-
-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Documentação e testes com Cypress #41
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
Open
spencerarq
wants to merge
1
commit into
ServeRest:main
Choose a base branch
from
spencerarq:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,30 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # contract testing | ||
| logs/ | ||
| pacts/ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # contract testing | ||
| logs/ | ||
| pacts/ | ||
|
|
||
| # log video cypress | ||
| cypress-ui.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| serverest.netlify.app | ||
| serverest.netlify.app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { defineConfig } from "cypress"; | ||
|
|
||
| export default defineConfig({ | ||
| e2e: { | ||
| setupNodeEvents(on, config) { | ||
| // implement node event listeners here | ||
| }, | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||
| describe('login spec', () => { | ||||||
| const baseUrl = 'https://front.serverest.dev/login' | ||||||
|
|
||||||
| // Cenário 1: Login válido | ||||||
| it('Deve logar com sucesso', () => { | ||||||
| cy.visit(baseUrl) // Navegar para a página de login | ||||||
| cy.get('input[name=email]').type('[email protected]') // Digitar email válido | ||||||
| cy.get('input[name=password]').type('1234') // Digitar senha válida | ||||||
| cy.get('button[type=submit]').click() // Clicar no botão de login | ||||||
|
|
||||||
| // Validar redirecionamento para a URL esperada | ||||||
| cy.url().should('include', '/admin/home') // Verifica se a URL contém '/admin/home' | ||||||
| }) | ||||||
|
|
||||||
| // Cenário 2: Login com e-mail não registrado | ||||||
| it('Exibe erro para email não registrado', () => { | ||||||
| cy.visit(baseUrl) | ||||||
| cy.get('input[name=email]').type('[email protected]') | ||||||
| cy.get('input[name=password]').type('teste') | ||||||
| cy.get('button[type=submit]').click() | ||||||
| cy.contains('Email e/ou senha inválidos').should('be.visible') // Validação | ||||||
| }) | ||||||
|
|
||||||
| // Cenário 3: Login com e-mail válido e senha inválida | ||||||
| it('Exibe erro para senha inválida', () => { | ||||||
| cy.visit(baseUrl) | ||||||
| cy.get('input[name=email]').type('[email protected]') | ||||||
| cy.get('input[name=password]').type('senhaerrada') | ||||||
| cy.get('button[type=submit]').click() | ||||||
| cy.contains('Email e/ou senha inválidos').should('be.visible') // Validação | ||||||
| }) | ||||||
|
|
||||||
| // Cenário 4: Login com todos os campos em branco | ||||||
| it('Exibe erro para campos em branco', () => { | ||||||
| cy.visit(baseUrl) // Navegar para a página de login | ||||||
| cy.get('button[type=submit]').click() // Clicar no botão de login sem preencher os campos | ||||||
|
|
||||||
| // Validar mensagens de erro exibidas | ||||||
| cy.get('.form > :nth-child(3)').should('contain', 'Email é obrigatório') // Mensagem correta para o email | ||||||
| cy.get(':nth-child(4) > :nth-child(2)').should('contain', 'Password é obrigatório') // Mensagem correta para a senha | ||||||
|
||||||
| cy.get(':nth-child(4) > :nth-child(2)').should('contain', 'Password é obrigatório') // Mensagem correta para a senha | |
| cy.get('[data-testid="password-error"]').should('contain', 'Password é obrigatório') // Mensagem correta para a senha |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "name": "Using fixtures to represent data", | ||
| "email": "[email protected]", | ||
| "body": "Fixtures are a great way to mock data for responses to routes" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /// <reference types="cypress" /> | ||
| // *********************************************** | ||
| // This example commands.ts 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) => { ... }) | ||
| // | ||
| // declare global { | ||
| // namespace Cypress { | ||
| // interface Chainable { | ||
| // login(email: string, password: string): Chainable<void> | ||
| // drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element> | ||
| // dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element> | ||
| // visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element> | ||
| // } | ||
| // } | ||
| // } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // *********************************************************** | ||
| // This example support/e2e.ts 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 './commands' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider using a more robust data-testid selector instead of a nth-child selector to reduce brittleness and improve test reliability.