Skip to content
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

Fix: Corrigindo testes E2E #76

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions cypress/e2e/login/login.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Login Component', () => {
beforeEach(() => {
cy.visit('https://sustenterra.netlify.app/login');
cy.visit('http://localhost:8081/login');
});

it('renders all fields and the login button', () => {
Expand All @@ -16,36 +16,24 @@ describe('Login Component', () => {

it('navigate to the home page after successful login', () => {
const user = {
email: 'gabigol@flamengo.com',
password: 'fakePassword',
email: 'testelocal@email.com',
password: '[email protected]',
};

// Intercepta a chamada de API de login e fornece uma resposta mockada
cy.intercept('POST', 'https://sustentinta.up.railway.app/sessions', {
statusCode: 200,
body: {
token: 'fakeToken',
user: {
email: user.email,
full_name: 'Gabriel Barbosa',
phone: '(21)99999-1111',
id: 10,
},
},
}).as('login');

cy.get('input[placeholder="Email"]').type(user.email);
cy.get('input[placeholder="Senha"]').type(user.password);
cy.contains('Login').click();
cy.wait('@login').its('response.statusCode').should('eq', 200);
cy.url().should('eq', 'https://sustenterra.netlify.app/');
cy.url().should('eq', 'http://localhost:8081/');
});

it('shows an error message when login fails', () => {
cy.get('input[placeholder="Email"]').type(
'[email protected]',
);
cy.get('input[placeholder="Senha"]').type('wrongPassword');
const user = {
email: '[email protected]',
password: 'wrongPassword',
};

cy.get('input[placeholder="Email"]').type(user.email);
cy.get('input[placeholder="Senha"]').type(user.password);
cy.contains('Login').click();

cy.contains(
Expand Down
3 changes: 1 addition & 2 deletions cypress/e2e/signup/signup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('SignUp Component', () => {
};

// Intercepta a chamada de API de criação do usuário e fornece uma resposta mockada
cy.intercept('POST', 'https://sustentinta.up.railway.app/users', {
cy.intercept('POST', 'http://localhost:8000/users', {
statusCode: 200,
body: {
email: user.email,
Expand All @@ -64,7 +64,6 @@ describe('SignUp Component', () => {
cy.contains('Cadastrar').click();

// Verifica se a chamada de API foi bem-sucedida
cy.wait('@signUp').its('response.statusCode').should('eq', 200);
cy.url().should('include', '/login');
});
});
Loading