employeeService/tests/login.spec.ts
Jan Klattenhoff 769c775be4
All checks were successful
Playwright Tests / test (pull_request) Successful in 1m51s
test: Add login redirection test for employees page
2025-01-16 17:42:00 +01:00

46 lines
1.5 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { async } from 'rxjs';
test('LoginPageShouldRender', async ({ page }) => {
await page.goto('http://localhost:4200');
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/EmployeeService/);
});
test('LoginPageShouldHaveCorrectHeading', async ({ page }) => {
await page.goto('http://localhost:4200');
const heading = page.getByRole('heading');
await expect(heading).toHaveText('Hi-Tec GmbH');
});
test('LoginPageShouldHaveLoginButton', async ({ page }) => {
await page.goto('http://localhost:4200');
const button = page.getByRole('button');
await expect(button).toHaveText('Login with Keycloak');
});
test('LoginPageButtonShouldRedirectToKeycloak', async ({ page }) => {
await page.goto('http://localhost:4200');
const button = page.getByText("Login with Keycloak");
await button.click();
await page.waitForFunction(() => window.location.href.includes('keycloak'));
expect(page.url()).toContain("keycloak.szut.dev");
});
test('AfterLoginUserShouldBeRedirectedToEmployees', 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');
expect(page.url()).toContain('localhost');
expect(page.url()).toContain('mitarbeiter');
});