-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invite to pull request Alegria #14
base: main
Are you sure you want to change the base?
Changes from all commits
20a4510
6146fe9
71aad6d
50e11cb
ee3d9bf
5ba15d3
dcb3205
834720b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ | |
|
||
# misc | ||
.DS_Store | ||
**.env | ||
guilhermealegria marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const { defineConfig } = require("cypress"); | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
env:{ | ||
grepFilterSpecs: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vejo que usou o No entanto, uma maneira mais simples seria informar ao Cypress quais arquivos (ou pastas) seriam executados, usando a opção Exemplo: cypress run --spec 'cypress/e2e/gui/*.cy.js' |
||
baseUrl: 'http://localhost:3001/' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A propriedade Para a URL da API, você pode definir uma Exemplo: env: {
API_URL: 'http://localhost:3001'
} E a |
||
}, | ||
fixturesFolder: false, | ||
setupNodeEvents(on, config) { | ||
require('@cypress/grep/src/plugin')(config); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ao fazer o que sugeri acima, tal lib nem mesmo seria necessária, tornando o projeto mais simples, que é o que procuramos quando se fala de um bom design: simplicidade. |
||
return config; | ||
}, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,108 @@ | ||||||
/// <reference types="cypress" /> | ||||||
|
||||||
wlsf82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
describe('All test intermediary API', {tags: 'api', env: {baseUrl: 'http://localhost:3001/customers'}}, () => { | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Essa linha tbm pode ser removida pela mesma razão anterior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Visto que você não implementou a sugestão, essa conversa não deveria ter sido resolvida. |
||||||
context('Request all customers', () => { | ||||||
beforeEach('Get request', () => { | ||||||
cy.request(Cypress.env('baseUrl')).as('customers') | ||||||
guilhermealegria marked this conversation as resolved.
Show resolved
Hide resolved
guilhermealegria marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Veja o comentário anterior. |
||||||
}) | ||||||
guilhermealegria marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
it('Check status code return for all customers', () => { | ||||||
cy.get('@customers').then(({ status }) =>{ | ||||||
expect(status).to.eq(200) | ||||||
}) | ||||||
}) | ||||||
guilhermealegria marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
it('Check length for return with all customers', () => { | ||||||
cy.get('@customers').then(({ body }) =>{ | ||||||
expect(body.customers).to.length(10) | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
|
||||||
context('Request all customers with pagination', () => { | ||||||
const pagination = [1,2,3,4,5,6,7] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. De onde saíram estes números? E se só tiverem 20 clientes no banco de dados? A partir da página 3 já não viria nada. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Faltou responder minha pergunta. |
||||||
it.each(pagination)('Check pagination with all customers', (page) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pra que tal complexidade? Veja abaixo uma solução simples e direta-ao-ponto. it('paginates the customer list correctly', () => {
cy.request('GET', `${CUSTOMERS_API_URL}?page=2`).as('getCustomersPageTwo')
cy.get('@getCustomersPageTwo')
.its('body.pageInfo.currentPage')
.should('eq', 2) // Supposing there are at least 2 pages
}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Não gostou da minha sugestão? |
||||||
cy.request(`${Cypress.env('baseUrl')}?page=${page}`).should(({status, body}) => { | ||||||
expect(status).to.eq(200) | ||||||
expect(body.pageInfo.currentPage).to.eq(page) | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
|
||||||
context('Request with get limit customer', () =>{ | ||||||
const limit = [1,2,3,4,5,6,7,8,9,10] | ||||||
it.each(limit)('Filter to customers with inside limit', (limit) => { | ||||||
cy.request(`${Cypress.env('baseUrl')}?page=1&limit=${limit}`).then(({status, body}) => { | ||||||
expect(status).to.eq(200) | ||||||
expect(body.customers).to.length(limit) | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
|
||||||
context('Request with get industry customers', () => { | ||||||
const industry = ['Logistics', 'Retail', 'HR', 'Logistics'] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E a indústria |
||||||
it.each(industry)('Filter to customers with industry', (industry) => { | ||||||
cy.request(`${Cypress.env('baseUrl')}?page=1&industry=${industry}`).then(({status, body}) => { | ||||||
expect(status).to.eq(200) | ||||||
expect(body.customers[0].industry).to.eq(industry) | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
context('Request with get size customers', () => { | ||||||
const sizes = ['Small','Medium','Enterprise','Large Enterprise','Very Large Enterprise'] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Ao deixar um espaço em branco entre cada item do array, a legibilidade melhora. |
||||||
it.each(sizes)('Filter to customer with size', (sizes) => { | ||||||
cy.request(`${Cypress.env('baseUrl')}?page=1&size=${sizes}&industry=All`).then(({status, body}) => { | ||||||
expect(status).to.eq(200) | ||||||
expect(body.customers[0].size).to.eq(sizes) | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
|
||||||
context('Bad Requests', () => { | ||||||
it('Check message for invalid page', () => { | ||||||
cy.request({url: `${Cypress.env('baseUrl')}?page=0`, failOnStatusCode: false}).then(({status, body}) => { | ||||||
expect(status).to.eq(400) | ||||||
expect(body.error).to.contain('Invalid page or limit. Both must be positive numbers.') | ||||||
}) | ||||||
}) | ||||||
|
||||||
it('Check message for invalid limit', () => { | ||||||
cy.request({url: `${Cypress.env('baseUrl')}?page=1&limit=0`, failOnStatusCode: false}).then(({status, body}) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Se o teste é de invalid limit, pra que passar |
||||||
expect(status).to.eq(400) | ||||||
expect(body.error).to.contain('Invalid page or limit. Both must be positive numbers.') | ||||||
}) | ||||||
}) | ||||||
|
||||||
it('Check message for invalid page with insert string', () => { | ||||||
cy.request({url: `${Cypress.env('baseUrl')}?page=teste&limit=0`, failOnStatusCode: false}).then(({status, body}) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Se o teste de de invalid page, pra que passar |
||||||
expect(status).to.eq(400) | ||||||
expect(body.error).to.contain('Invalid page or limit. Both must be positive numbers.') | ||||||
}) | ||||||
}) | ||||||
|
||||||
it('Check message for invalid limit with insert boolean', () => { | ||||||
cy.request({url: `${Cypress.env('baseUrl')}?page=teste&limit=true`, failOnStatusCode: false}).then(({status, body}) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Se o teste é de invalid limit, pra que passar There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Além disso, que tal quebrar a linha para evitar scroll horizontal? |
||||||
expect(status).to.eq(400) | ||||||
expect(body.error).to.contain('Invalid page or limit. Both must be positive numbers.') | ||||||
}) | ||||||
}) | ||||||
|
||||||
it('Check message for invalid size', () => { | ||||||
const message = 'Unsupported size value. Supported values are All, Small, Medium, Enterprise, Large Enterprise, and Very Large Enterprise.' | ||||||
cy.request({ url: `${Cypress.env('baseUrl')}?page=1&limit=10&size=0`, failOnStatusCode: false}).then(({status, body}) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Se o teste é de invalid size, pra que passar |
||||||
expect(status).to.eq(400) | ||||||
expect(body.error).to.contain(message) | ||||||
}) | ||||||
}) | ||||||
|
||||||
it('Check message for invalid industry', () => { | ||||||
const message = 'Unsupported industry value. Supported values are All, Logistics, Retail, Technology, HR, and Finance.' | ||||||
cy.request({ url: `${Cypress.env('baseUrl')}?page=1&limit=10&size=All&industry=0`, failOnStatusCode: false}).then(({status, body}) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Se o teste é de invalid industry, pra que passar |
||||||
expect(status).to.eq(400) | ||||||
expect(body.error).to.contain(message) | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,50 @@ | ||||||
/// <reference types="cypress" /> | ||||||
|
||||||
describe('Tests customers gui', {tags: 'gui', env:{baseUrl: 'http://localhost:3000/'}},() => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conforme já comentado, a |
||||||
context('Home customers', () => { | ||||||
beforeEach(() => { | ||||||
cy.setCookieSession('accepted') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vale mesmo a pena abstrair isso para um comando customizado? Além disso, o comando não diz o que ele realmente faz, pois além de definir o cookie, ele visita a página da aplicação em teste, mas isso não é claro ao ler o nome do comando. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A propósito, por qual motivo o comando visita a página, se logo abaixo há um |
||||||
cy.visit(Cypress.env('baseUrl')) | ||||||
}) | ||||||
|
||||||
const industries = ['Logistic', 'Retail', 'Technology', 'HR', 'Finance'] | ||||||
it.each(industries)('Filter with industries', (industries) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Veja abaixo um teste meu para filtragem por indústria. it('filters by Logistics industry', () => {
cy.intercept(
'GET',
`${CUSTOMERS_API_URL}?page=1&limit=10&size=All&industry=Logistics`,
{ fixture: 'logisticsCustomers' }
).as('getLogisticsCustomers')
cy.get('[data-testid="industry-filter"]').select('Logistics')
cy.wait('@getLogisticsCustomers')
cy.get('tbody tr').should('have.length', 1)
}) Você percebe como este teste é mais simples e direto ao ponto? Além disso, perceba que só estou testando que o frontend está fazendo a chamada corretao ao backend. Pra verificar que o backend filtra corretamente, testo no nível da API. |
||||||
cy.intercept('GET', '**&industry=*').as('wait') | ||||||
cy.get('[data-testid="industry-filter"]').select(industries) | ||||||
cy.wait('@wait') | ||||||
|
||||||
cy.get('[data-testid="table"] > table > tbody > tr').then((elements) => { | ||||||
cy.wrap(elements).each(() => { | ||||||
cy.contains('tr', industries) | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
|
||||||
const sizes = ['Small', 'Medium', 'Enterprise', 'Large Enterprise', 'Very Large Enterprise'] | ||||||
it.each(sizes)('Filter with sizes', (sizes) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mesmo que o comentário acima. |
||||||
cy.intercept('GET', '**&size=*').as('wait') | ||||||
cy.get('[data-testid="size-filter"]').select(sizes) | ||||||
cy.wait('@wait') | ||||||
|
||||||
cy.get('[data-testid="table"] > table > tbody > tr').then((elements) => { | ||||||
cy.wrap(elements).each(() => { | ||||||
cy.contains('tr', sizes) | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
|
||||||
it('Check maintain filter when returning from view details customers ', () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Que tal a seguinte descrição?
Suggested change
|
||||||
cy.get('[data-testid="size-filter"]').as('select') | ||||||
cy.get('@select').select('Small') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Em vez de fazer isso, a linha acima podia ser: cy.get('[data-testid="size-filter"]')
.as('select')
.select('Small') |
||||||
cy.get('[data-testid="table"] > table > tbody > tr').as('list') | ||||||
cy.get('@list').first().last().find('button').should('be.visible').click() | ||||||
cy.contains('h2', 'Customer Details').should('be.visible') | ||||||
|
||||||
cy.contains('button', 'Back').should('be.visible').click() | ||||||
|
||||||
cy.get('@select').should('be.visible').invoke('val').should('eq', 'Small') | ||||||
}) | ||||||
}) | ||||||
}) | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Uma linha em branco ao final do arquivo já é o suficiente. |
||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||||
// *********************************************** | ||||||||
// This example commands.js shows you how to | ||||||||
// create various custom commands and overwrite | ||||||||
// existing commands. | ||||||||
// | ||||||||
// For more comprehensive examples of custom | ||||||||
// commands please read more here: | ||||||||
// https://on.cypress.io/custom-commands | ||||||||
// *********************************************** | ||||||||
// | ||||||||
// | ||||||||
// -- This is a parent command -- | ||||||||
// Cypress.Commands.add('login', (email, password) => { ... }) | ||||||||
// | ||||||||
// | ||||||||
// -- This is a child command -- | ||||||||
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) | ||||||||
// | ||||||||
// | ||||||||
// -- This is a dual command -- | ||||||||
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) | ||||||||
// | ||||||||
// | ||||||||
// -- This will overwrite an existing command -- | ||||||||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) | ||||||||
|
||||||||
Cypress.Commands.add('setCookieSession', (value) => { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Já falei anteriormente sobre a não-necessidade deste comando, visto que sua implementação é tão simples. A propósito, o Por fim, você percebeu que abstraiu isso para um comando e tal comando só é usado uma vez? Isso é o que chamo de uma abstração prematura. |
||||||||
cy.session(value ,() => { | ||||||||
cy.visit(Cypress.env('baseUrl')) | ||||||||
cy.setCookie('cookieConsent', value) | ||||||||
}) | ||||||||
}) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Recomenda-se deixar uma linha em branco ao final de cada arquivo, para evitar que ferramentas como o GitHub exibam o ícone de Isso é uma boa prática e convenção a ser seguida. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tem algum motivo pelo qual optaste por criar esse arquivo, ao invés de utilizar o There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Este arquivo faz parte da estrutura padrão do Cypress @ldasilvaNZ11. Ele é o arquivo principal dos comandos customizados, onde plugins externos são importados e também comandos customizados ( Ou seja, tudo certo! Eu só removeria esse monte de comentários, pra dar uma limpada no arquivo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Algum motivo por não ter removido os comentários? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// *********************************************************** | ||
// This example support/e2e.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import 'cypress-each' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Se tivesse implementado solução mais simples para os testes, tal lib não seria necessária. |
||
import './commands' | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ldasilvaNZ11, o
.env.example
deve sim ser versionado, visto que não contém dados sensíveis, é só um exemplo, como o nome indica, de qual estrutura deve ser usada no.env
, esse sim não versionado.