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

TEST: Testes na tela de tabela de usuários #74

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
5 changes: 5 additions & 0 deletions .changeset/breezy-moose-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"playwright-ui-tests": minor
---

test: adiciona testes na tela de listagem de usuários com o projeto Playwright
2 changes: 1 addition & 1 deletion test/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
workers: 1,
reporter: 'html',
use: {
baseURL: 'http://localhost:8181',
Expand Down
Empty file.
37 changes: 37 additions & 0 deletions test/playwright/tests/shared/mocks/generateUsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { faker } from '@faker-js/faker';
import { request } from '@playwright/test';
import { generateValidCPF } from '../commands/generateValidCPF';

/**
* Realiza o mock de criação de um usuário através de requisições HTTP.
*/
async function mockGenerateUsers(): Promise<void> {
const apiContext = await request.newContext({
baseURL: 'http://localhost:3001/register',
});

const response = await apiContext.post('/register', {
data: {
fullName: faker.person.fullName(),
socialName: faker.person.lastName(),
document: generateValidCPF(),
docType: 'cpf',
phone: faker.phone.number({ style: 'national' }),
email: faker.internet.email({ provider: 'example.qa.solar' }),
password: '123456',
},
});

if (!response.ok()) {
throw new Error(`Erro ao criar usuário: ${response.status()}`);
}
}

/**
* Gera múltiplos usuários simulados.
*/
export async function generateUsers(): Promise<void> {
for (let i = 0; i < 10; i++) {
await mockGenerateUsers();
}
}
40 changes: 40 additions & 0 deletions test/playwright/tests/specs/listUsers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expect, test } from '@playwright/test';
import { login } from '../shared/commands/login';
import { generateUsers } from '../shared/mocks/generateUsers';

test.describe('Tela de listagem de Usuários', () => {

test.beforeAll(async () => {
await generateUsers();
});

test.beforeEach(async ({ page }) => {
login(page, '[email protected]', '123456');
await page.goto('/listusers')
await page.waitForURL('/listusers');
});

test('Deveria ser possível visualizar os elementos da tela de listagem de Usuários', async ({ page }) => {
await expect(page.locator('[data-testid="table-users"]')).toBeVisible();
await expect(page.locator('[data-testid="checkbox-select-all"]')).toBeVisible();
await page.locator('[data-testid="btn-delete-user"]').scrollIntoViewIfNeeded();
await expect(page.locator('[data-testid="btn-delete-user"]')).toBeVisible();
});

test('Deveria ser possível selecionar todos os usuários', async ({ page }) => {
const selectAllCheckbox = page.locator('[data-testid="checkbox-select-all"]');
await selectAllCheckbox.check();
await expect(selectAllCheckbox).toBeChecked();
});

test('Deveria ser possível selecionar um usuário e excluí-lo', async ({ page }) => {
const userCheckbox = page.locator('[data-testid="checkbox-select-users"]').nth(2);
await userCheckbox.check();
const deleteButton = page.locator('[data-testid="btn-delete-user"]');
await deleteButton.scrollIntoViewIfNeeded();
await deleteButton.click();
const toastContent = page.locator('[data-testid="toast-content"]').first();
await expect(toastContent).toBeVisible();
await expect(toastContent).toHaveText('1 usuário(s) excluído(s) com sucesso!');
});
});
10 changes: 6 additions & 4 deletions test/playwright/tests/specs/registerUser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ test.describe('Tela de Cadastro de Usuários', () => {
await expect(page.locator('[data-testid="link-go-to-login"]')).toBeVisible();
});

test('Deveria ser possivel visualizar o toast ao clicar no botão sem adicionar algum valor nos campos', async ({ page }) => {
test('Deveria ser possível visualizar o toast ao clicar no botão sem adicionar algum valor nos campos', async ({ page }) => {
await page.locator('[data-testid="btn-register"]').click();
await expect(page.locator('[data-testid="toast-content"]')).toHaveText('Por favor, corrija os erros no formulário.');

const inputName = ['fullname', 'cpfcnpj', 'email', 'password'];
const inputError = ['O Nome Completo é obrigatório.', 'O CPF/CNPJ é obrigatório.', 'O Email é obrigatório.', 'A Senha é obrigatória.'];

inputName.forEach((name, index) => {
expect(page.locator(`[data-testid="input-error-${name}"]`)).toHaveText(inputError[index]);
})
for (let i = 0; i < inputName.length; i++) {
const name = inputName[i];
const error = inputError[i];
await expect(page.locator(`[data-testid="input-error-${name}"]`)).toHaveText(error);
}
});

test('Não deveria ser possivel criar o usuário com o Nome Completo errado', async ({ page }) => {
Expand Down