2025-01-17 13:32:11 +01:00
|
|
|
import { test, expect } from "@playwright/test";
|
|
|
|
|
|
|
|
test.describe('mitarbeiter', () => {
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
await page.goto('http://localhost:4200');
|
|
|
|
|
|
|
|
await page.getByRole('button').click();
|
|
|
|
await page.waitForFunction(() => window.location.href.includes('keycloak'));
|
|
|
|
await page.getByLabel('Username or email').fill('user');
|
|
|
|
await page.getByLabel('Password').fill('test');
|
|
|
|
await page.click('#kc-login');
|
|
|
|
|
|
|
|
await page.goto('http://localhost:4200/mitarbeitererstellen');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('pageShouldLoad', async ({ page }) => {
|
|
|
|
await expect(page.getByText('Save')).toHaveCount(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('backButtonShouldGoBack', async ({ page }) => {
|
|
|
|
await page.getByText('Back').click();
|
|
|
|
|
|
|
|
expect(page.url().includes('erstellen')).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('EveryFieldShouldValidateEmptiness', async ({ page }) => {
|
|
|
|
await page.getByText('Save').click();
|
|
|
|
|
|
|
|
const errors = page.getByText('This field is required');
|
|
|
|
|
|
|
|
await expect(errors).toHaveCount(6);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('PhoneNumberShouldBeValidated', async ({ page }) => {
|
|
|
|
await page.getByLabel('Phone').fill("asd");
|
|
|
|
await page.getByText('Save').click();
|
|
|
|
|
|
|
|
const error = page.getByText('This field must be a valid phone number');
|
|
|
|
|
|
|
|
await expect(error).toHaveCount(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('PostCodeShouldValidateTooShort', async ({ page }) => {
|
|
|
|
await page.getByLabel('Postcode').fill("1");
|
|
|
|
await page.getByText('Save').click();
|
|
|
|
|
|
|
|
const error = page.getByText('The value is too short');
|
|
|
|
|
|
|
|
await expect(error).toHaveCount(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('PostCodeShouldValidateTooLong', async ({ page }) => {
|
|
|
|
await page.getByLabel('Postcode').fill("123456");
|
|
|
|
await page.getByText('Save').click();
|
|
|
|
|
|
|
|
const error = page.getByText('The value is too long');
|
|
|
|
|
|
|
|
await expect(error).toHaveCount(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('CreationAndDeletion', async ({ page }) => {
|
|
|
|
await page.getByLabel('Last Name').fill('a');
|
|
|
|
await page.getByLabel('Street').fill('a');
|
|
|
|
await page.getByLabel('Postcode').fill('12345');
|
|
|
|
await page.getByLabel('City').fill('a');
|
|
|
|
await page.getByLabel('Phone Number').fill('1234');
|
|
|
|
|
2025-01-17 14:05:30 +01:00
|
|
|
await page.getByText('Save').click();
|
2025-01-17 13:32:11 +01:00
|
|
|
|
|
|
|
expect(page.url().includes('erstellen')).toBeFalsy();
|
|
|
|
|
|
|
|
const deleteButton = page.getByText('Delete').nth(2);
|
2025-01-17 14:05:30 +01:00
|
|
|
await deleteButton.waitFor({ state: 'visible', timeout: 5000 }); // Add a timeout for safety
|
2025-01-17 13:59:47 +01:00
|
|
|
|
2025-01-17 13:32:11 +01:00
|
|
|
await deleteButton.click();
|
|
|
|
|
|
|
|
const deletedEmployee = page.getByText('12345');
|
2025-01-17 14:05:30 +01:00
|
|
|
await expect(deletedEmployee).toHaveCount(0, { timeout: 5000 });
|
2025-01-17 13:32:11 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|