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

Entrega do desafio técnico #6

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules

### CypressIO ###
# gitignore template for the CypressIO, browser test framework
# website: https://www.cypress.io/

cypress/results/*
cypress/reports/*
cypress/screenshots/*
cypress/videos/*
10 changes: 10 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
baseUrl: "https://qastage.buildbox.one/18",
},
});
165 changes: 165 additions & 0 deletions cypress/e2e/register.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
const { faker, fakerTH } = require("@faker-js/faker");
const { generate } = require("gerador-validador-cpf");
const staticData = require("../fixtures/staticData.json");

const generateUser = () => {
let birthday = faker.date.between({ from: "1950-01-01", to: "2005-12-31" });
const formattedBirthday = `${birthday
.getDate()
.toString()
.padStart(2, "0")}/${(birthday.getMonth() + 1)
.toString()
.padStart(2, "0")}/${birthday.getFullYear()}`;
return {
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
birthDate: formattedBirthday,
cpf: generate(),
email: faker.internet.exampleEmail(),
password: faker.internet.password(),
};
};
let newUser = generateUser();

describe("Feature: Registering", () => {
beforeEach(() => {
newUser = generateUser();
cy.visit("/cadastro");
});
it("should correctly open the register website", () => {
expect(cy.get('[data-cy="button-btn-enroll"]')).to.exist;
});
it("should successfully register a new user", () => {
cy.get('[data-cy="button-btn-enroll"]').click();
cy.personalData(
newUser.firstName,
newUser.lastName,
newUser.birthDate,
newUser.cpf,
newUser.email,
newUser.password,
"Advanced"
);
expect(cy.get("span").contains("STEP 02/02").scrollIntoView()).to.exist;
cy.addressData();
expect(cy.get('[data-cy="button-wide_window_button"]')).to.exist;
});

it("should validate previously registered emails", () => {
cy.get('[data-cy="button-btn-enroll"]').click();
cy.personalData(
newUser.firstName,
newUser.lastName,
newUser.birthDate,
newUser.cpf,
staticData.email,
newUser.password,
"Advanced"
);
expect(cy.get("span.input-error").contains("Este email já está em uso.")).to
.exist;
});

it("should validate the field: CPF already registered", () => {
cy.get('[data-cy="button-btn-enroll"]').click();
cy.personalData(
newUser.firstName,
newUser.lastName,
newUser.birthDate,
staticData.cpf,
newUser.email,
newUser.password,
"Advanced"
);
expect(cy.get("span.input-error").contains("Este CPF já está em uso.")).to
.exist;
});
it("should validate the field: invalid email format", () => {
cy.get('[data-cy="button-btn-enroll"]').click();
cy.personalData(
newUser.firstName,
newUser.lastName,
newUser.birthDate,
newUser.cpf,
"john@doe@@mailcom",
newUser.password,
"Advanced"
);
expect(cy.get("span.input-error").contains("Email inválido.")).to.exist;
});
it("should validate the field: mismatching emails", () => {
cy.get('[data-cy="button-btn-enroll"]').click();
cy.get('[data-cy="input-signup-personal-data-firstName"]').type(
newUser.firstName
);
cy.get('[data-cy="input-signup-personal-data-lastName"]').type(
newUser.lastName
);
cy.get('[data-cy="input-signup-personal-data-birthDate"]').type(
newUser.birthDate
);
cy.get('[data-cy="input-signup-personal-data-cpf"]').type(newUser.cpf);
cy.get('[data-cy="input-signup-personal-data-email"]').type(newUser.email);
cy.get('[data-cy="input-signup-personal-data-email-confirm"]').type(
staticData.email
);
cy.get('[data-cy="input-signup-personal-data-password"]').type(
newUser.password
);
cy.get('[data-cy="input-signup-personal-data-password-confirm"]').type(
newUser.password
);
cy.get('[aria-controls="dropdown-button-1"]').scrollIntoView().click();
cy.get("span").contains("Beginner").click();
cy.get('[data-cy="input-signup-personal-data-lgpd"]').click();
cy.get('[data-cy="button-signup_submit_button_1"]').click();
cy.get('[data-cy="input-signup-personal-data-email-confirm"]').then(
($input) => {
expect($input[0].validationMessage).to.eq("Os e-mails não são iguais.");
}
);
});
it("should validate the field: invalid CPF", () => {
cy.get('[data-cy="button-btn-enroll"]').click();
cy.personalData(
newUser.firstName,
newUser.lastName,
newUser.birthDate,
"1232",
newUser.email,
newUser.password,
"Advanced"
);
expect(cy.get("span.input-error").contains("CPF inválido.")).to.exist;
});

it("should validate the field: invalid birthdate", () => {
cy.get('[data-cy="button-btn-enroll"]').click();
cy.personalData(
newUser.firstName,
newUser.lastName,
"32133012",
newUser.cpf,
newUser.email,
newUser.password,
"Intermediate"
);
expect(cy.get("span.input-error").contains("Data de nascimento inválida."))
.to.exist;
});
});

describe("Feature: Login", () => {
it("should login with the registered email", () => {
cy.visit("/sign-in");
cy.wait(200);
cy.get("#user_login").type(staticData.email);
cy.get("#user_pass").type(staticData.password);
cy.get("#wp-submit").click();
cy.wait(10000);
cy.get(".hidden > .flex > .text-sm").should(
"contain.text",
`${staticData.firstName} ${staticData.lastName}}`
);
});
});
8 changes: 8 additions & 0 deletions cypress/fixtures/staticData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"firstName": "Bruce",
"lastName": "Wayne",
"email": "[email protected]",
"password": "#Na1Na2Na3Na4Na5Na6Na7Na8Na9Batman#",
"birthDate": "19/02/1970",
"cpf": "35506468016"
}
29 changes: 29 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Cypress.Commands.add(
"personalData",
(firstName, lastName, birthDate, cpf, email, password, proficiencyLevel) => {
cy.get('[data-cy="input-signup-personal-data-firstName"]').type(firstName);
cy.get('[data-cy="input-signup-personal-data-lastName"]').type(lastName);
cy.get('[data-cy="input-signup-personal-data-birthDate"]').type(birthDate);
cy.get('[data-cy="input-signup-personal-data-cpf"]').type(cpf);
cy.get('[data-cy="input-signup-personal-data-email"]').type(email);
cy.get('[data-cy="input-signup-personal-data-email-confirm"]').type(email);
cy.get('[data-cy="input-signup-personal-data-password"]').type(password);
cy.get('[data-cy="input-signup-personal-data-password-confirm"]').type(
password
);
cy.get('[aria-controls="dropdown-button-1"]').scrollIntoView().click();
cy.get("span").contains(`${proficiencyLevel}`).click();
cy.get('[data-cy="input-signup-personal-data-lgpd"]').click();
cy.get('[data-cy="button-signup_submit_button_1"]').click();
}
);

Cypress.Commands.add("addressData", () => {
cy.get('[data-cy="input-signup-address-cep"]').type("01310930");
cy.get('[data-cy="input-signup-address-neighborhood"]').type(
"Jardim Paulista"
);
cy.get('[data-cy="input-signup-address-street"]').type("Avenida Paulista");
cy.get('[data-cy="input-signup-address-number"]').type("1578");
cy.get('[data-cy="button-signup_submit_button_3"]').click();
});
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// 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 './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading