From 41b249a3335eb5f44156cc9738ae040f6a50c656 Mon Sep 17 00:00:00 2001 From: Mountler Date: Tue, 2 Sep 2025 13:34:25 +0200 Subject: [PATCH 1/5] added tests for welcome screen --- game/tests/libs/viewPorts.ts | 10 +++++ game/tests/libs/welcomeScreen_helper.ts | 30 +++++++++++++++ game/tests/welcomeScreen.spec.ts | 49 +++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 game/tests/libs/viewPorts.ts create mode 100644 game/tests/libs/welcomeScreen_helper.ts create mode 100644 game/tests/welcomeScreen.spec.ts diff --git a/game/tests/libs/viewPorts.ts b/game/tests/libs/viewPorts.ts new file mode 100644 index 0000000..facb593 --- /dev/null +++ b/game/tests/libs/viewPorts.ts @@ -0,0 +1,10 @@ +export const viewPorts: {width: number, height: number}[] = [ + {width: 844, height: 331}, + {width: 390, height: 695}, + {width: 1080, height: 688}, + {width: 810, height: 918}, + {width: 1280, height: 612}, + {width: 1920, height: 918}, + {width: 2560, height: 1224}, + {width: 3840, height: 1836}, +] \ No newline at end of file diff --git a/game/tests/libs/welcomeScreen_helper.ts b/game/tests/libs/welcomeScreen_helper.ts new file mode 100644 index 0000000..86fb2e6 --- /dev/null +++ b/game/tests/libs/welcomeScreen_helper.ts @@ -0,0 +1,30 @@ +import {Page} from "@playwright/test"; + +export async function userLogin( + page: Page, + username: string = process.env._PLAYWRIGHT_USER_STUDENT_USERNAME!, + password: string = process.env._USER_STUDENT_PW!, +) { + await page.goto('/'); + await page.getByTestId('userName').click(); + await page.getByTestId('userName').fill(username); + await page.getByTestId('userName').press('Tab'); + await page.getByTestId('password').fill(password); + await page.getByTestId('loginButton').click(); +} + +export async function userLogout( + page: Page +) { + await page.getByTestId("logout").click(); +} + +export async function navigateToLearningWorldMenu(page: Page) { + //TODO: Replace with getByTestId-Query when button has testid + await page.getByRole('button').filter({ hasText: /^$/ }).nth(1).click(); +} + +export async function navigateToAvatarEditor(page: Page) { + //TODO: Replace with getByTestId-Query when button has testid + await page.getByRole('button').filter({ hasText: /^$/ }).nth(2).click(); +} \ No newline at end of file diff --git a/game/tests/welcomeScreen.spec.ts b/game/tests/welcomeScreen.spec.ts new file mode 100644 index 0000000..161a73d --- /dev/null +++ b/game/tests/welcomeScreen.spec.ts @@ -0,0 +1,49 @@ +import {test} from "./libs/enhanced_test"; +import {userLogin, userLogout, navigateToAvatarEditor, navigateToLearningWorldMenu} from "./libs/welcomeScreen_helper" +import {expect} from "@playwright/test"; +import {enrollInMoodleCourse} from "./libs/moodle_helpers"; +import {viewPorts} from "./libs/viewPorts"; + +test.beforeAll(async ({ request, resetEnvironment, uploadWorld }) => { + await resetEnvironment(); + const uploadedWorld = await uploadWorld('testwelt'); + await enrollInMoodleCourse( + request, + process.env._PLAYWRIGHT_USER_STUDENT_USERNAME!, + process.env._USER_STUDENT_PW!, + uploadedWorld.worldNameInLms + ); +}); + +viewPorts.forEach(({width, height}) => { + + test(`user logs in (${width}x${height})`, async ({page}) => { + await page.setViewportSize({width: width, height: height}); + await userLogin(page); + await expect(page.getByTestId("login-button")).toBeVisible(); + }) + + test(`user logs out (${width}x${height})`, async ({page}) => { + await page.setViewportSize({width: width, height: height}); + await userLogin(page); + await userLogout(page); + await expect(page.getByTestId("userName")).toBeVisible() + await expect(page.getByTestId("password")).toBeVisible() + }) + + test(`user navigates to learning world menu (${width}x${height})`, async ({page}) => { + await page.setViewportSize({width: width, height: height}); + await userLogin(page); + await navigateToLearningWorldMenu(page); + await expect(page.url()).toContain("worldmenu"); + await expect(page.getByRole('button', { name: 'testwelt' })).toBeVisible(); + }) + + test(`user navigates to avatar-editor (${width}x${height})`, async ({page}) => { + await page.setViewportSize({width: width, height: height}); + await userLogin(page); + await navigateToAvatarEditor(page); + await expect(page.url()).toContain("avatarEditor"); + await expect(page.locator("canvas")).toBeVisible(); + }) +}) From 6038656db6f2acd94de04b8aefb02b9db500bbde Mon Sep 17 00:00:00 2001 From: Mountler Date: Mon, 8 Sep 2025 12:12:32 +0200 Subject: [PATCH 2/5] serialized welcome screen tests --- game/tests/welcomeScreen.spec.ts | 75 +++++++++++++++++--------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/game/tests/welcomeScreen.spec.ts b/game/tests/welcomeScreen.spec.ts index 161a73d..23726ec 100644 --- a/game/tests/welcomeScreen.spec.ts +++ b/game/tests/welcomeScreen.spec.ts @@ -4,46 +4,49 @@ import {expect} from "@playwright/test"; import {enrollInMoodleCourse} from "./libs/moodle_helpers"; import {viewPorts} from "./libs/viewPorts"; -test.beforeAll(async ({ request, resetEnvironment, uploadWorld }) => { - await resetEnvironment(); - const uploadedWorld = await uploadWorld('testwelt'); - await enrollInMoodleCourse( - request, - process.env._PLAYWRIGHT_USER_STUDENT_USERNAME!, - process.env._USER_STUDENT_PW!, - uploadedWorld.worldNameInLms - ); -}); +test.describe.serial(`welcome screen`, () => { -viewPorts.forEach(({width, height}) => { + test.beforeAll(async ({ request, resetEnvironment, uploadWorld }) => { + await resetEnvironment(); + const uploadedWorld = await uploadWorld('testwelt'); + await enrollInMoodleCourse( + request, + process.env._PLAYWRIGHT_USER_STUDENT_USERNAME!, + process.env._USER_STUDENT_PW!, + uploadedWorld.worldNameInLms + ); + }); - test(`user logs in (${width}x${height})`, async ({page}) => { - await page.setViewportSize({width: width, height: height}); - await userLogin(page); - await expect(page.getByTestId("login-button")).toBeVisible(); - }) + viewPorts.forEach(({width, height}) => { - test(`user logs out (${width}x${height})`, async ({page}) => { - await page.setViewportSize({width: width, height: height}); - await userLogin(page); - await userLogout(page); - await expect(page.getByTestId("userName")).toBeVisible() - await expect(page.getByTestId("password")).toBeVisible() - }) + test(`user logs in (${width}x${height})`, async ({page}) => { + await page.setViewportSize({width: width, height: height}); + await userLogin(page); + await expect(page.getByTestId("login-button")).toBeVisible(); + }) - test(`user navigates to learning world menu (${width}x${height})`, async ({page}) => { - await page.setViewportSize({width: width, height: height}); - await userLogin(page); - await navigateToLearningWorldMenu(page); - await expect(page.url()).toContain("worldmenu"); - await expect(page.getByRole('button', { name: 'testwelt' })).toBeVisible(); - }) + test(`user logs out (${width}x${height})`, async ({page}) => { + await page.setViewportSize({width: width, height: height}); + await userLogin(page); + await userLogout(page); + await expect(page.getByTestId("userName")).toBeVisible() + await expect(page.getByTestId("password")).toBeVisible() + }) + + test(`user navigates from welcome screen to learning world menu (${width}x${height})`, async ({page}) => { + await page.setViewportSize({width: width, height: height}); + await userLogin(page); + await navigateToLearningWorldMenu(page); + await expect(page.url()).toContain("worldmenu"); + await expect(page.getByRole('button', { name: 'testwelt' })).toBeVisible(); + }) - test(`user navigates to avatar-editor (${width}x${height})`, async ({page}) => { - await page.setViewportSize({width: width, height: height}); - await userLogin(page); - await navigateToAvatarEditor(page); - await expect(page.url()).toContain("avatarEditor"); - await expect(page.locator("canvas")).toBeVisible(); + test(`user navigates from welcome screen to avatar-editor (${width}x${height})`, async ({page}) => { + await page.setViewportSize({width: width, height: height}); + await userLogin(page); + await navigateToAvatarEditor(page); + await expect(page.url()).toContain("avatarEditor"); + await expect(page.locator("canvas")).toBeVisible(); + }) }) }) From c31d841807addac7f986141da5b6558f10528c03 Mon Sep 17 00:00:00 2001 From: Mountler Date: Mon, 8 Sep 2025 12:12:59 +0200 Subject: [PATCH 3/5] removed redundant login test --- game/tests/login.spec.ts | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 game/tests/login.spec.ts diff --git a/game/tests/login.spec.ts b/game/tests/login.spec.ts deleted file mode 100644 index 3347440..0000000 --- a/game/tests/login.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -import {expect} from '@playwright/test'; -import {test} from './libs/enhanced_test'; - -test.beforeAll(async ({ resetEnvironment }) => { - await resetEnvironment(); -}); - -test('test', async ({page}) => { - await page.goto('/'); - await page.getByTestId('userName').click(); - await page.getByTestId('userName').fill(process.env._PLAYWRIGHT_USER_STUDENT_USERNAME!); - await page.getByTestId('userName').press('Tab'); - await page.getByTestId('password').fill(process.env._USER_STUDENT_PW!); - await page.getByTestId('loginButton').click(); - await expect(page.getByTestId('login-button')).toBeVisible(); -}); - From 7a465fe45b740bc50b238b0bee6288a182b8d566 Mon Sep 17 00:00:00 2001 From: Mountler Date: Mon, 8 Sep 2025 12:13:25 +0200 Subject: [PATCH 4/5] added tests for avatar editor --- game/tests/avatarEditor.spec.ts | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 game/tests/avatarEditor.spec.ts diff --git a/game/tests/avatarEditor.spec.ts b/game/tests/avatarEditor.spec.ts new file mode 100644 index 0000000..747eba2 --- /dev/null +++ b/game/tests/avatarEditor.spec.ts @@ -0,0 +1,47 @@ +import {test} from "./libs/enhanced_test"; +import {userLogin, navigateToAvatarEditor, userLogout} from "./libs/welcomeScreen_helper" +import {expect} from "@playwright/test"; +import {enrollInMoodleCourse} from "./libs/moodle_helpers"; +import {viewPorts} from "./libs/viewPorts"; + +test.describe.serial(`avatar editor`, () => { + + test.beforeAll(async ({ request, resetEnvironment, uploadWorld }) => { + await resetEnvironment(); + const uploadedWorld = await uploadWorld('testwelt'); + await enrollInMoodleCourse( + request, + process.env._PLAYWRIGHT_USER_STUDENT_USERNAME!, + process.env._USER_STUDENT_PW!, + uploadedWorld.worldNameInLms + ); + }); + + viewPorts.forEach(({width, height}) => { + + test(`user navigates from avatar editor to welcome screen (${width}x${height})`, async ({page}) => { + await page.setViewportSize({width: width, height: height}); + await userLogin(page); + await navigateToAvatarEditor(page); + await page.getByRole('button', { name: 'Home Icon' }).click(); + await expect(page.url()).toEqual(`http://localhost:${process.env._PORT_3D}/`); + }) + + test(`user selects avatar editor categories (${width}x${height})`, async ({page}) =>{ + //TODO: Replace getByRole-Query with getByTestId-Query when button has testid + await page.setViewportSize({width: width, height: height}); + await userLogin(page); + await navigateToAvatarEditor(page); + await page.getByTestId('avatar-editor-category-tab-0').click(); + await expect(await page.getByRole('button', { name: /Frisur/i })).toBeVisible(); + await page.getByTestId('avatar-editor-category-tab-1').click(); + await expect(await page.getByRole('button', { name: /Augenbrauen/i })).toBeVisible(); + await page.getByTestId('avatar-editor-category-tab-2').click(); + await expect(await page.getByRole('button', { name: /Kopfbedeckung/i })).toBeVisible(); + await page.getByTestId('avatar-editor-category-tab-3').click(); + await expect(await page.getByRole('button', { name: /Oberteil/i })).toBeVisible(); + await page.getByTestId('avatar-editor-category-tab-4').click(); + await expect(await page.getByRole('heading', { name: /Hautfarbe/i })).toBeVisible(); + }) + }) +}) From 677804dadf9c0e37d40fa6696d21e973d19c8ed1 Mon Sep 17 00:00:00 2001 From: Mountler Date: Mon, 8 Sep 2025 12:49:37 +0200 Subject: [PATCH 5/5] fixed avatar editor navigation test --- game/tests/avatarEditor.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/game/tests/avatarEditor.spec.ts b/game/tests/avatarEditor.spec.ts index 747eba2..c3873e9 100644 --- a/game/tests/avatarEditor.spec.ts +++ b/game/tests/avatarEditor.spec.ts @@ -22,9 +22,10 @@ test.describe.serial(`avatar editor`, () => { test(`user navigates from avatar editor to welcome screen (${width}x${height})`, async ({page}) => { await page.setViewportSize({width: width, height: height}); await userLogin(page); + const welcomScreenURL = page.url(); await navigateToAvatarEditor(page); await page.getByRole('button', { name: 'Home Icon' }).click(); - await expect(page.url()).toEqual(`http://localhost:${process.env._PORT_3D}/`); + await expect(page.url()).toEqual(welcomScreenURL); }) test(`user selects avatar editor categories (${width}x${height})`, async ({page}) =>{