Skip to content

Commit c05d79f

Browse files
author
caneppelevitor
committed
fix: simplified test coverage and fix tests checks
1 parent 43e8290 commit c05d79f

File tree

5 files changed

+46
-29
lines changed

5 files changed

+46
-29
lines changed

cypress/e2e/tests/auth/signup.cy.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ describe("Sign Up tests", () => {
2929
cy.get(locators.signup.REPEATED_PASSWORD).type(testUser.password);
3030
cy.checkRecaptcha();
3131
cy.get(locators.signup.BTN_SUBMIT).click();
32-
cy.contains("Campo obrigatório").should("be.visible");
32+
cy.get(locators.signup.ERROR_NAME).should("be.visible");
33+
cy.get(locators.signup.ERROR_NAME).should(
34+
"contain",
35+
"Please, insert your name"
36+
);
3337
});
3438

3539
it("Should show validation error when email is invalid", () => {
@@ -39,7 +43,8 @@ describe("Sign Up tests", () => {
3943
cy.get(locators.signup.REPEATED_PASSWORD).type(testUser.password);
4044
cy.checkRecaptcha();
4145
cy.get(locators.signup.BTN_SUBMIT).click();
42-
cy.contains("E-mail inválido").should("be.visible");
46+
cy.get(locators.signup.ERROR_EMAIL).should("be.visible");
47+
cy.get(locators.signup.ERROR_EMAIL).should("contain", "Invalid e-mail");
4348
});
4449

4550
it("Should show validation error when passwords don't match", () => {
@@ -49,7 +54,11 @@ describe("Sign Up tests", () => {
4954
cy.get(locators.signup.REPEATED_PASSWORD).type("DifferentPassword123!");
5055
cy.checkRecaptcha();
5156
cy.get(locators.signup.BTN_SUBMIT).click();
52-
cy.contains("senhas não são iguais").should("be.visible");
57+
cy.get(locators.signup.ERROR_REPEATED_PASSWORD).should("be.visible");
58+
cy.get(locators.signup.ERROR_REPEATED_PASSWORD).should(
59+
"contain",
60+
"The two passwords that you entered do not match"
61+
);
5362
});
5463

5564
it("Should show error when CAPTCHA is not completed", () => {
@@ -58,7 +67,7 @@ describe("Sign Up tests", () => {
5867
cy.get(locators.signup.PASSWORD).type(testUser.password);
5968
cy.get(locators.signup.REPEATED_PASSWORD).type(testUser.password);
6069
cy.get(locators.signup.BTN_SUBMIT).click();
61-
cy.contains("Campo obrigatório").should("be.visible");
70+
cy.contains("Field is required").should("be.visible");
6271
});
6372

6473
it("Should successfully create account with valid data and CAPTCHA", () => {
@@ -67,21 +76,19 @@ describe("Sign Up tests", () => {
6776
cy.get(locators.signup.PASSWORD).type(testUser.password);
6877
cy.get(locators.signup.REPEATED_PASSWORD).type(testUser.password);
6978
cy.checkRecaptcha();
70-
cy.get(locators.signup.BTN_SUBMIT).click();
7179

72-
// After successful registration, user should be redirected to home
73-
cy.url().should("eq", "http://localhost:3000/");
74-
cy.contains("Cadastro realizado com sucesso").should("be.visible");
75-
});
80+
// Intercept the registration API call
81+
cy.intercept("POST", "/api/user/register").as("registerUser");
82+
cy.intercept("/api/.ory/sessions/whoami").as("confirmLogin");
7683

77-
it("Should show error when email already exists", () => {
78-
cy.get(locators.signup.NAME).type("Duplicate User");
79-
cy.get(locators.signup.EMAIL).type("existing@aletheiafact.org");
80-
cy.get(locators.signup.PASSWORD).type(testUser.password);
81-
cy.get(locators.signup.REPEATED_PASSWORD).type(testUser.password);
82-
cy.checkRecaptcha();
8384
cy.get(locators.signup.BTN_SUBMIT).click();
8485

85-
cy.contains(/usuário já existe|já cadastrado/i).should("be.visible");
86+
// Wait for registration to complete
87+
cy.wait("@registerUser", { timeout: 30000 });
88+
cy.wait("@confirmLogin", { timeout: 30000 });
89+
90+
// After successful registration, user should be redirected to home
91+
cy.url({ timeout: 30000 }).should("eq", "http://localhost:3000/");
92+
cy.contains("Sign-up successful").should("be.visible");
8693
});
8794
});

cypress/support/locators.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const locators = {
1313
PASSWORD: "[data-cy=passwordInputCreateAccount]",
1414
REPEATED_PASSWORD: "[data-cy=repeatedPasswordInputCreateAccount]",
1515
BTN_SUBMIT: "[data-cy=loginButton]",
16+
ERROR_NAME: "[data-cy=nameError]",
17+
ERROR_EMAIL: "[data-cy=emailError]",
18+
ERROR_PASSWORD: "[data-cy=passwordError]",
19+
ERROR_REPEATED_PASSWORD: "[data-cy=repeatedPasswordError]",
1620
},
1721

1822
personality: {

public/locales/en/login.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"nameLabel": "Name",
88
"submitButton": "Submit",
99
"emailErrorMessage": "Please, insert your e-mail",
10+
"invalidEmailErrorMessage": "Invalid e-mail",
1011
"nameErrorMessage": "Please, insert your name",
1112
"passwordErrorMessage": "Please, insert your password",
1213
"loginFailedMessage": "Error while logging in",

src/components/Login/SignUpForm.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const SignUpForm = ({ onFinish, onFinishFailed, isLoading }) => {
6464
})}
6565
/>
6666
<TextError
67+
data-cy="nameError"
6768
stateError={errors.name}
6869
children={t("login:nameErrorMessage")}
6970
/>
@@ -84,6 +85,7 @@ const SignUpForm = ({ onFinish, onFinishFailed, isLoading }) => {
8485
})}
8586
/>
8687
<TextError
88+
data-cy="emailError"
8789
stateError={errors.email}
8890
children={
8991
errors.email?.type === "pattern"
@@ -106,6 +108,7 @@ const SignUpForm = ({ onFinish, onFinishFailed, isLoading }) => {
106108
})}
107109
/>
108110
<TextError
111+
data-cy="passwordError"
109112
stateError={errors.password}
110113
children={t("login:passwordErrorMessage")}
111114
/>
@@ -125,6 +128,7 @@ const SignUpForm = ({ onFinish, onFinishFailed, isLoading }) => {
125128
})}
126129
/>
127130
<TextError
131+
data-cy="repeatedPasswordError"
128132
stateError={errors.repeatedPassword}
129133
children={
130134
errors.repeatedPassword?.type === "required"

src/components/TextErrorForm.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import React from "react";
22
import colors from "../styles/colors";
33

4-
const TextError = ({ children, stateError }) => {
5-
return (
6-
<p
7-
style={{
8-
fontSize: 14,
9-
color: colors.error,
10-
visibility: stateError ? "visible" : "hidden",
11-
marginBottom: 4,
12-
}}
13-
>
14-
{children}
15-
</p>
16-
);
4+
const TextError = ({ children, stateError, "data-cy": dataCy }) => {
5+
return (
6+
<p
7+
data-cy={dataCy}
8+
style={{
9+
fontSize: 14,
10+
color: colors.error,
11+
visibility: stateError ? "visible" : "hidden",
12+
marginBottom: 4,
13+
}}
14+
>
15+
{children}
16+
</p>
17+
);
1718
};
1819

1920
export default TextError;

0 commit comments

Comments
 (0)