diff --git a/game/tests/avatarEditor.spec.ts b/game/tests/avatarEditor.spec.ts new file mode 100644 index 0000000..c3873e9 --- /dev/null +++ b/game/tests/avatarEditor.spec.ts @@ -0,0 +1,48 @@ +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); + const welcomScreenURL = page.url(); + await navigateToAvatarEditor(page); + await page.getByRole('button', { name: 'Home Icon' }).click(); + await expect(page.url()).toEqual(welcomScreenURL); + }) + + 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(); + }) + }) +}) 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/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(); -}); - diff --git a/game/tests/welcomeScreen.spec.ts b/game/tests/welcomeScreen.spec.ts new file mode 100644 index 0000000..23726ec --- /dev/null +++ b/game/tests/welcomeScreen.spec.ts @@ -0,0 +1,52 @@ +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.describe.serial(`welcome screen`, () => { + + 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 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 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(); + }) + }) +})