Skip to content

Commit

Permalink
Merge branch 'main' into feat/podmanSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
framitdavid authored Feb 6, 2024
2 parents 547c3cf + 10340e5 commit bf2d787
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
3 changes: 3 additions & 0 deletions frontend/testing/playwright/enum/Language.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum Language {
Norwegian = 'Norsk',
}
20 changes: 19 additions & 1 deletion frontend/testing/playwright/pages/LoginPage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type { Page } from '@playwright/test';
import { BasePage } from '../helpers/BasePage';
import { Language } from '../enum/Language';

// Since this page is a Razor page, it's not using the nb/en.json files, which are used in the frontend.
const loginPageTexts: Record<string, string> = {
login: 'logg inn',
username: 'Brukernavn eller epost',
password: 'Passord',
error_message: 'Ugyldig brukernavn eller passord.',
links: 'Links',
};

export class LoginPage extends BasePage {
Expand Down Expand Up @@ -44,7 +47,22 @@ export class LoginPage extends BasePage {
}

public async checkThatErrorMessageIsVisible(): Promise<void> {
await this.page.getByText(/ugyldig brukernavn eller passord./i).isVisible();
await this.page.getByText(loginPageTexts['error_message']).isVisible();
}

public async getLanguage(): Promise<string> {
return await this.page
.getByRole('group', { name: loginPageTexts['links'] })
.getByRole('menu')
.innerText();
}

public async clickOnLanguageMenu(): Promise<void> {
await this.page.getByRole('group', { name: loginPageTexts['links'] }).getByRole('menu').click();
}

public async clickOnNorwegianLanguageOption(): Promise<void> {
await this.page.getByRole('menuitem', { name: Language.Norwegian }).click();
}

public async addSessionToSharableStorage() {
Expand Down
28 changes: 15 additions & 13 deletions frontend/testing/playwright/tests/dashboard/dashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@ const getExtraAppName = (appName: string): string => `extra-app-${appName}`;

// Before the tests starts, we need to create the dashboard app
test.beforeAll(async ({ testAppName, request, storageState }) => {
// Create 2 apps
const firstApp = await createApp(testAppName, request, storageState as StorageState);
const secondApp = await createApp(
getExtraAppName(testAppName),
request,
storageState as StorageState,
);

expect(firstApp.ok()).toBeTruthy();
expect(secondApp.ok()).toBeTruthy();
const response = await createApp(testAppName, request, storageState as StorageState);
expect(response.ok()).toBeTruthy();
});

test.afterAll(async ({ request, testAppName }) => {
Expand Down Expand Up @@ -84,14 +76,24 @@ test('It is possible to change context and view only Testdepartementet apps', as
await dashboardPage.checkThatTTDApplicationsHeaderIsVisible();
});

test('It is possible to search an app by name', async ({ page, testAppName }) => {
test('It is possible to search an app by name', async ({
page,
testAppName,
request,
storageState,
}) => {
const dashboardPage = await setupAndVerifyDashboardPage(page, testAppName);
const testAppName2 = `${testAppName}2`;
const testAppName2 = getExtraAppName(testAppName);

// Need to wait a bit to make sure that Gitea does not crash
dashboardPage.waitForXAmountOfMilliseconds(3000);
const response = await createApp(testAppName2, request, storageState as StorageState);
expect(response.ok()).toBeTruthy();

await dashboardPage.checkThatAppIsVisible(testAppName);
await dashboardPage.checkThatAppIsVisible(testAppName2);

await dashboardPage.typeInSearchField('2');
await dashboardPage.typeInSearchField('extra');
await dashboardPage.checkThatAppIsHidden(testAppName);
await dashboardPage.checkThatAppIsVisible(testAppName2);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { test } from '../../extenders/testExtend';
import { LoginPage } from '../../pages/LoginPage';
import { DashboardPage } from '../../pages/DashboardPage';
import { expect } from '@playwright/test';
import { Language } from '../../enum/Language';

// This line must be there to ensure that the tests do not run in parallell, and
// that the before all call is being executed before we start the tests
Expand Down Expand Up @@ -32,6 +34,18 @@ test('That it is not possible to login with invalid credentials', async ({
await loginPage.goToAltinnLoginPage();
await loginPage.goToGiteaLoginPage();

const lang = await loginPage.getLanguage();

if (lang !== Language.Norwegian) {
await loginPage.clickOnLanguageMenu();
await loginPage.clickOnNorwegianLanguageOption();

const langAfterchange = await loginPage.getLanguage();
expect(langAfterchange).toBe(Language.Norwegian);
} else {
expect(lang).toBe(Language.Norwegian);
}

await loginPage.writeUsername(process.env.PLAYWRIGHT_USER);
await loginPage.writePassword('123');

Expand Down

0 comments on commit bf2d787

Please sign in to comment.