Skip to content

Commit

Permalink
Merge branch 'main' of github.com:dBildungsplattform/schulportal-test…
Browse files Browse the repository at this point in the history
…automatisierung into SPSH-1131
  • Loading branch information
jaggarnaut committed Nov 27, 2024
2 parents daa7267 + 6de486d commit bbf57ac
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
10 changes: 6 additions & 4 deletions base/api/testHelperPerson.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { HeaderPage } from '../../pages/Header.page';
import { LoginPage } from '../../pages/LoginView.page';
import { faker } from '@faker-js/faker';
import { lehrkraftOeffentlichRolle } from '../rollen';
import { generateNachname, generateVorname } from "../testHelperGenerateTestdataNames";
import { generateNachname, generateVorname, generateKopersNr } from "../testHelperGenerateTestdataNames";
import { testschule } from "../organisation";

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

Expand Down Expand Up @@ -95,21 +96,22 @@ export async function getPersonId(page: Page, searchString: string): Promise<str
return json.items[0].person.id;
}

export async function createTeacherAndLogin(page) {
export async function createTeacherAndLogin(page: Page) {
const header = new HeaderPage(page);
const login: LoginPage = new LoginPage(page);
const vorname = await generateVorname();
const nachname = await generateNachname();
const organisation = 'Testschule Schulportal';
const organisation = testschule;
const kopersNr = '0815' + faker.string.numeric({ length: 3 });

const userInfo: UserInfo = await createPersonWithUserContext(page, organisation, nachname, vorname, lehrkraftOeffentlichRolle, kopersNr);
const userInfo: UserInfo = await createPersonWithUserContext(page, organisation, await generateNachname(), await generateVorname(), lehrkraftOeffentlichRolle, await generateKopersNr());
await header.logout();
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();
return userInfo;
}

export async function lockPerson(page: Page, personId: string, organisationId: string): Promise<void> {
Expand Down
6 changes: 5 additions & 1 deletion base/testHelperGenerateTestdataNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ export async function generateNachname(){
}

export async function generateRolleName(){
return "TAuto-PW-R-" + faker.lorem.word({ length: { min: 7, max: 7 }}) + generateRandomString({length: 3,charSetType: CharacterSetType.Alphabetic})
return "TAuto-PW-R-" + faker.lorem.word({ length: { min: 7, max: 7 }}) + generateRandomString({length: 3,charSetType: CharacterSetType.Alphabetic});
}

export async function generateKopersNr(){
return '0815' + faker.string.numeric({ length: 3 });
}
13 changes: 7 additions & 6 deletions tests/Person.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { LONG, SHORT, STAGE, BROWSER } from "../base/tags";
import { deletePersonenBySearchStrings, deleteRolleById, deleteRolleByName } from "../base/testHelperDeleteTestdata.ts";
import { landesadminRolle, schuelerRolle, schuladminOeffentlichRolle } from "../base/rollen.ts";
import { generateNachname, generateVorname, generateRolleName } from "../base/testHelperGenerateTestdataNames.ts";
import { testschule665 } from "../base/organisation.ts";
import { gotoTargetURL } from "../base/testHelperUtils.ts";

const PW: string | undefined = process.env.PW;
const ADMIN: string | undefined = process.env.USER;
Expand Down Expand Up @@ -464,23 +466,22 @@ test.describe(`Testfälle für die Administration von Personen": Umgebung: ${pro

test("In der Ergebnisliste die Filterfunktion der Schulen benutzen als Landesadmin", {tag: [LONG, SHORT, STAGE]}, async ({ page }) => {
const personManagementView = new PersonManagementViewPage(page);
const schulstrukturknoten = "Testschule-PW665";

await test.step(`Filter öffnen und Schule selektieren`, async () => {
await page.goto(FRONTEND_URL + "admin/personen");
await gotoTargetURL(page, "admin/personen");
await expect(personManagementView.text_h2_Benutzerverwaltung).toHaveText("Benutzerverwaltung");

// Fill the input with the name of the Schule and let the autocomplete find it
await personManagementView.comboboxMenuIcon_Schule_input.fill(schulstrukturknoten);
await personManagementView.comboboxMenuIcon_Schule_input.fill(testschule665);

// Click on the found Schule
await page.getByText(schulstrukturknoten).click();

await page.getByRole('option', { name: testschule665 }).click();
// Close the dropdown
await personManagementView.comboboxMenuIcon_Schule.click();

// Click elsewhere on the page to fully confirm the selected Schule
await page.locator('body').click();
await personManagementView.button_Suchen.click();

await expect(page.getByTestId('schule-select')).toHaveText('1111165 (Testschule-PW665)');
});
Expand Down
33 changes: 32 additions & 1 deletion tests/workflow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ import { LONG, SHORT, STAGE, BROWSER } from "../base/tags";
import { CalendarPage } from "../pages/Cards/Calendar.page";
import { DirectoryPage } from "../pages/Cards/Directory.page";
import { createTeacherAndLogin } from "../base/api/testHelperPerson.page";
import { UserInfo} from "../base/api/testHelper.page.ts";
import { deletePersonenBySearchStrings } from "../base/testHelperDeleteTestdata.ts";

const PW: string | undefined = process.env.PW;
const ADMIN: string | undefined = process.env.USER;
const FRONTEND_URL: string | undefined = process.env.FRONTEND_URL || "";
const ENV: string | undefined = process.env.ENV;

let usernames: string[] = []; // Im afterEach Block werden alle Testdaten gelöscht

test.describe(`Testfälle für den Test von workflows: Umgebung: ${process.env.ENV}: URL: ${process.env.FRONTEND_URL}:`, () => {
test.beforeEach(async ({ page }) => {
await test.step(`Login`, async () => {
Expand All @@ -31,12 +35,39 @@ test.describe(`Testfälle für den Test von workflows: Umgebung: ${process.env.E
});
});

test.afterEach(async ({page}) => {
const header = new HeaderPage(page);
const landing = new LandingPage(page);
const login = new LoginPage(page);
const startseite = new StartPage(page);

await test.step(`Testdaten(Benutzer) löschen via API`, async () => {
if (usernames) { // nur wenn der Testfall auch mind. einen Benutzer angelegt hat
await header.logout();
await landing.button_Anmelden.click();
await login.login(ADMIN, PW);
await expect(startseite.text_h2_Ueberschrift).toBeVisible();

await deletePersonenBySearchStrings(page, usernames);
usernames = [];
}
});

await test.step(`Abmelden`, async () => {
const header = new HeaderPage(page);
await header.logout();
});
});

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);

let userInfoAdmin: UserInfo;

await test.step(`Lehrer via api anlegen und mit diesem anmelden`, async () => {
await createTeacherAndLogin(page);
userInfoAdmin = await createTeacherAndLogin(page);
usernames.push(userInfoAdmin.username);
});

await test.step(`Kacheln Email für Lehrkräfte und Itslearning öffnen, danach beide Kacheln wieder schließen`, async () => {
Expand Down

0 comments on commit bbf57ac

Please sign in to comment.