Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmadp committed Nov 20, 2024
1 parent 1e9bf76 commit 5b088ca
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 59 deletions.
9 changes: 7 additions & 2 deletions base/api/testHelperPerson.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HeaderPage } from '../../pages/Header.page';
import { LoginPage } from '../../pages/LoginView.page';
import { faker } from '@faker-js/faker';
import { lehrkraftOeffentlichRolle } from '../roles';
import { generateLehrerNachname, generateLehrerVorname } from "../testHelperGenerateTestdataNames";

const FRONTEND_URL: string | undefined = process.env.FRONTEND_URL || "";

Expand Down Expand Up @@ -43,6 +44,8 @@ export async function createPersonWithUserContext(page: Page, organisationName:
// API-Calls machen und Benutzer mit Kontext anlegen
const organisationId: string = await getOrganisationId(page, organisationName);
const rolleId: string = await getRolleId(page, rolleName);
console.log('rolleName: ' + rolleName);
console.log('rolleId: ' + rolleId);
const userInfo: UserInfo = await createPerson(page, familienname, vorname, organisationId, rolleId, koPersNr);
return userInfo;
}
Expand Down Expand Up @@ -95,8 +98,8 @@ export async function getPersonId(page: Page, Benutzername: string): Promise<str
export async function createTeacherAndLogin(page) {
const header = new HeaderPage(page);
const login: LoginPage = new LoginPage(page);
const vorname = "TAuto-PW-V-" + faker.person.firstName();
const nachname = "TAuto-PW-N-" + faker.person.lastName();
const vorname = await generateLehrerVorname();
const nachname = await generateLehrerNachname();
const organisation = 'Testschule Schulportal';
const kopersNr = '0815' + faker.string.numeric({ length: 3 });

Expand All @@ -105,6 +108,8 @@ export async function createTeacherAndLogin(page) {
await header.button_login.click();
await login.login(userInfo.username, userInfo.password);
await login.UpdatePW();
await expect(header.icon_myProfil).toBeVisible();
await expect(header.icon_logout).toBeVisible();
}

export async function lockPerson(page: Page, personId: string, organisationId: string): Promise<void> {
Expand Down
6 changes: 5 additions & 1 deletion base/api/testHelperServiceprovider.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { Page, expect } from '@playwright/test';
const FRONTEND_URL: string | undefined = process.env.FRONTEND_URL || "";

export async function getSPId(page: Page, nameSP: string): Promise<string> {
const response = await page.request.get(FRONTEND_URL + `api/provider/all`, {});
let response = await page.request.get(FRONTEND_URL + `api/provider/all`, {});
if(response.status() != 200) {
console.log(response);
response = await page.request.get(FRONTEND_URL + `api/provider/all`, {});
}
expect(response.status()).toBe(200);
const json = await response.json();
expect(response.status()).toBe(200);
Expand Down
11 changes: 5 additions & 6 deletions base/testHelperGenerateTestdataNames.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { faker } from "@faker-js/faker/locale/de";
import { generateRandomString, CharacterSetType } from "ts-randomstring/lib/index.js"

export async function generateLehrerVorname(){
return "TAuto-PW-V-" + faker.person.firstName();
return "TAuto-PW-V-" + faker.person.firstName() + generateRandomString({length: 3,charSetType: CharacterSetType.Alphabetic})
}

export async function generateLehrerNachname(){
return "TAuto-PW-N-" + faker.person.lastName();
return "TAuto-PW-N-" + faker.person.lastName() + generateRandomString({length: 3,charSetType: CharacterSetType.Alphabetic})
}

export async function generateRolleName(){
return "TAuto-PW-R-" + faker.lorem.word({ length: { min: 8, max: 12 }});
}


return "TAuto-PW-R-" + faker.lorem.word({ length: { min: 7, max: 7 }}) + generateRandomString({length: 3,charSetType: CharacterSetType.Alphabetic})
}
36 changes: 35 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 3 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,7 @@
"@fast-csv/parse": "^4.3.6",
"fast-csv": "^4.3.6",
"generate-password-ts": "^1.6.5",
"moment": "^2.30.1"
},
"name": "schulportal-testautomatisierung",
"description": "",
"version": "0.6.0",
"main": "index.js",
"directories": {
"test": "tests"
},
"keywords": [],
"author": "Dataport AöR",
"license": "EUPL-1.2"
"moment": "^2.30.1",
"ts-randomstring": "^1.0.8"
}
}
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default defineConfig({
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
maxFailures: 9,
workers: process.env.CI ? 1 : undefined,
workers: process.env.CI ? 2 : undefined,
reporter: [["html"]],
use: {
trace: "on-first-retry",
Expand Down
3 changes: 2 additions & 1 deletion tests/Person.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,10 @@ test.describe(`Testfälle für die Administration von Personen": Umgebung: ${pro
await personCreationView.combobox_Rolle.click();
await expect(personCreationView.listbox_Rolle).toContainText(rolleLehr);
await expect(personCreationView.listbox_Rolle).toContainText(rolleLiV);
await expect(personCreationView.listbox_Rolle).toContainText(schuladminOeffentlichRolle);
await expect(personCreationView.listbox_Rolle).toContainText(schuelerRolle);
await expect(personCreationView.listbox_Rolle).not.toContainText(landesadminRolle);
await page.keyboard.type(schuladminOeffentlichRolle);
await expect(personCreationView.listbox_Rolle).toContainText(schuladminOeffentlichRolle);
});
});

Expand Down
91 changes: 61 additions & 30 deletions tests/Profile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { UserInfo } from "../base/api/testHelper.page";
import { addSystemrechtToRolle } from "../base/api/testHelperRolle.page";
import { LONG, SHORT, STAGE, BROWSER } from "../base/tags";
import { deleteRolleById, deletePersonByUsername} from "../base/testHelperDeleteTestdata";
import {generateLehrerNachname, generateLehrerVorname, generateRolleName} from "../base/testHelperGenerateTestdataNames.ts";

const PW: string | undefined = process.env.PW;
const ADMIN: string | undefined = process.env.USER;
Expand Down Expand Up @@ -310,13 +311,13 @@ test.describe(`Testfälle für das eigene Profil anzeigen: Umgebung: ${process.e
const login: LoginPage = new LoginPage(page);

let personId = '';
const vorname = "TAuto-PW-V-" + faker.person.firstName();
const nachname = "TAuto-PW-N-" + faker.person.lastName();
const vorname = await generateLehrerVorname();
const nachname = await generateLehrerNachname();
const organisation1 = 'Testschule Schulportal';
const organisation2 = 'Carl-Orff-Schule';
const dienststellenNr1 = '1111111';
const dienststellenNr2 = '0702948';
const rollenname = 'TAuto-PW-R-RolleLehrer';
const rollenname = await generateRolleName();
const rollenart = 'LEHR';

await test.step(`Lehrer via api anlegen und mit diesem anmelden`, async () => {
Expand Down Expand Up @@ -349,29 +350,62 @@ test.describe(`Testfälle für das eigene Profil anzeigen: Umgebung: ${process.e
await expect(profileView.label_KopersNr).toBeHidden();
await expect(profileView.data_KopersNr).toBeHidden();
await expect(profileView.icon_InfoPersoenlicheDaten).toBeVisible();
// Schulzuordnung 1
await expect(profileView.cardHeadline_Schulzuordnung1).toHaveText('Schulzuordnung 1');
await expect(profileView.label_Schule1).toHaveText('Schule:');
await expect(profileView.data_Schule1).toHaveText(organisation1);
await expect(profileView.label_Rolle1).toHaveText('Rolle:');
await expect(profileView.data_Rolle1).toHaveText(rollenname);
await expect(profileView.label_Dienststellennummer1).toHaveText('DStNr.:');
await expect(profileView.data_Dienststellennummer1).toHaveText(dienststellenNr1);
// Schulzuordnung 2
await expect(profileView.cardHeadline_Schulzuordnung2).toHaveText('Schulzuordnung 2');
await expect(profileView.label_Schule2).toHaveText('Schule:');
await expect(profileView.data_Schule2).toHaveText(organisation2);
await expect(profileView.label_Rolle2).toHaveText('Rolle:');
await expect(profileView.data_Rolle2).toHaveText(rollenname);
await expect(profileView.label_Dienststellennummer2).toHaveText('DStNr.:');
await expect(profileView.data_Dienststellennummer2).toHaveText(dienststellenNr2);
// Passwort
await expect(profileView.cardHeadline_Passwort).toHaveText('Passwort');
await expect(profileView.button_NeuesPasswortSetzen).toBeEnabled();
// 2FA
// Aktuell wird der Abschnitt 2FA generell nicht angezeigt
// await expect(profileView.cardHeadline_2FA).toHaveText('Zwei-Faktor-Authentifizierung');
// await expect(profileView.button_2FAEinrichten).toBeEnabled();

// prüfen, welche von den beiden Schulen zuerst angezeigt wird in der Tabelle
if(await profileView.data_Schule1.innerText() == organisation1) {
// Schulzuordnung 1
await expect(profileView.cardHeadline_Schulzuordnung1).toHaveText('Schulzuordnung 1');
await expect(profileView.label_Schule1).toHaveText('Schule:');
await expect(profileView.data_Schule1).toHaveText(organisation1);
await expect(profileView.label_Rolle1).toHaveText('Rolle:');
await expect(profileView.data_Rolle1).toHaveText(rollenname);
await expect(profileView.label_Dienststellennummer1).toHaveText('DStNr.:');
await expect(profileView.data_Dienststellennummer1).toHaveText(dienststellenNr1);

// Schulzuordnung 2
await expect(profileView.cardHeadline_Schulzuordnung2).toHaveText('Schulzuordnung 2');
await expect(profileView.label_Schule2).toHaveText('Schule:');
await expect(profileView.data_Schule2).toHaveText(organisation2);
await expect(profileView.label_Rolle2).toHaveText('Rolle:');
await expect(profileView.data_Rolle2).toHaveText(rollenname);
await expect(profileView.label_Dienststellennummer2).toHaveText('DStNr.:');
await expect(profileView.data_Dienststellennummer2).toHaveText(dienststellenNr2);
// Passwort
await expect(profileView.cardHeadline_Passwort).toHaveText('Passwort');
await expect(profileView.button_NeuesPasswortSetzen).toBeEnabled();
// 2FA
// Aktuell wird der Abschnitt 2FA generell nicht angezeigt
// await expect(profileView.cardHeadline_2FA).toHaveText('Zwei-Faktor-Authentifizierung');
// await expect(profileView.button_2FAEinrichten).toBeEnabled();
}
else {
// Schulzuordnung 1
await expect(profileView.cardHeadline_Schulzuordnung2).toHaveText('Schulzuordnung 2');
await expect(profileView.label_Schule2).toHaveText('Schule:');
await expect(profileView.data_Schule2).toHaveText(organisation1);
await expect(profileView.label_Rolle2).toHaveText('Rolle:');
await expect(profileView.data_Rolle2).toHaveText(rollenname);
await expect(profileView.label_Dienststellennummer2).toHaveText('DStNr.:');
await expect(profileView.data_Dienststellennummer2).toHaveText(dienststellenNr2);

// Schulzuordnung 2
await expect(profileView.cardHeadline_Schulzuordnung1).toHaveText('Schulzuordnung 1');
await expect(profileView.label_Schule1).toHaveText('Schule:');
await expect(profileView.data_Schule1).toHaveText(organisation2);
await expect(profileView.label_Rolle1).toHaveText('Rolle:');
await expect(profileView.data_Rolle1).toHaveText(rollenname);
await expect(profileView.label_Dienststellennummer1).toHaveText('DStNr.:');
await expect(profileView.data_Dienststellennummer1).toHaveText(dienststellenNr1);

// Passwort
await expect(profileView.cardHeadline_Passwort).toHaveText('Passwort');
await expect(profileView.button_NeuesPasswortSetzen).toBeEnabled();
// 2FA
// Aktuell wird der Abschnitt 2FA generell nicht angezeigt
// await expect(profileView.cardHeadline_2FA).toHaveText('Zwei-Faktor-Authentifizierung');
// await expect(profileView.button_2FAEinrichten).toBeEnabled();

}
});
});

Expand All @@ -380,15 +414,12 @@ test.describe(`Testfälle für das eigene Profil anzeigen: Umgebung: ${process.e
const header = new HeaderPage(page);
const login = new LoginPage(page);

const vorname = "TAuto-PW-V-" + faker.person.firstName();
const nachname = "TAuto-PW-N-" + faker.person.lastName();
const organisation = 'Testschule Schulportal';
const rollenname = 'TAuto-PW-R-RolleSchüler';
const rollenart = 'LERN';

await test.step(`Lehrer via api anlegen und mit diesem anmelden`, async () => {
const idSP = await getSPId(page, 'itslearning');
const userInfo: UserInfo = await createRolleAndPersonWithUserContext(page, organisation, rollenart, nachname, vorname, idSP, rollenname);
const userInfo: UserInfo = await createRolleAndPersonWithUserContext(page, organisation, rollenart, await generateLehrerNachname(), await generateLehrerVorname(), idSP, await generateRolleName());
roleId.push(userInfo.rolleId);
username.push(userInfo.username);

Expand Down
8 changes: 3 additions & 5 deletions tests/Rolle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test.describe(`Testfälle für die Administration von Rollen: Umgebung: ${proces
faker.lorem.word({ length: { min: 8, max: 12 } }) +
zufallsnummer;
const schulstrukturknoten1 = "Land Schleswig-Holstein";
const schulstrukturknoten2 = "0703754 (Amalie-Sieveking-Schule)";
const schulstrukturknoten2 = "Ersatzschulen Land Schleswig-Holstein";;
const rollenart1 = "Lern";
const rollenart2 = "Lehr";
const merkmal2 = "KoPers.-Nr. ist Pflichtangabe";
Expand Down Expand Up @@ -92,10 +92,8 @@ test.describe(`Testfälle für die Administration von Rollen: Umgebung: ${proces

await test.step(`Zweite Rolle anlegen`, async () => {
await rolleCreationView.button_WeitereRolleAnlegen.click();

await rolleCreationView.schulstrukturknoten.selectByTitle(
schulstrukturknoten2,
);
await rolleCreationView.schulstrukturknoten.selectByTitle(schulstrukturknoten2);
await page.pause();
await rolleCreationView.rollenarten.selectByTitle(rollenart2);
await rolleCreationView.enterRollenname(rollenname2);
await rolleCreationView.merkmale.selectByTitle(merkmal2);
Expand Down
3 changes: 3 additions & 0 deletions tests/workflow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test.describe(`Testfälle für den Test von workflows: Umgebung: ${process.env.E

test("Angebote per Link öffnen als Lehrer", {tag: [LONG, SHORT, STAGE]}, async ({ page }) => {
const startseite: StartPage = new StartPage(page);
const header: HeaderPage = new HeaderPage(page);

await test.step(`Lehrer via api anlegen und mit diesem anmelden`, async () => {
await createTeacherAndLogin(page);
Expand All @@ -43,6 +44,8 @@ test.describe(`Testfälle für den Test von workflows: Umgebung: ${process.env.E
// Die Schnittstelle email für Lehrkräfte(ox) gibt es nur auf stage
// Auf dev wird nur getestet, dass die url für ox aufgerufen wird wenn man die Kachel email anklickt
// Wenn SPSH-1043 auf stage deployed ist, muss der Test erweitert werden. Hier muss dann das erwartete Verhalten getestet werden, wenn man auf stage auf die Kachel(email, Adressbuch, Kalender) klickt
await expect(startseite.card_item_email).toBeVisible(); // warten bis die Seite geladen ist

const page_Email4Teacher_Promise = page.waitForEvent("popup");
await startseite.card_item_email.click();
const page_Email4Teacher = await page_Email4Teacher_Promise;
Expand Down

0 comments on commit 5b088ca

Please sign in to comment.