-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEST: Testes na tela de tabela de usuários (#74)
* test: altera a configuracao dos workers * test: ajusta um teste flacky * test: cria mock para gerar usuarios fakers * test: adiciona testes na tela de lista de usuarios * test: adiciona o changesets
- Loading branch information
1 parent
8b293f3
commit c647a81
Showing
6 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
--- | ||
"playwright-ui-tests": minor | ||
--- | ||
|
||
test: adiciona testes na tela de listagem de usuários com o projeto Playwright |
This file contains 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
Empty file.
This file contains 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 @@ | ||
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(); | ||
} | ||
} |
This file contains 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,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!'); | ||
}); | ||
}); |
This file contains 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