Skip to content

Commit

Permalink
Merge branch 'main' into 12180-default-section-for-component-config
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamThorenfeldt authored Feb 6, 2024
2 parents 2f3f0a5 + 74b8835 commit 9b378db
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -305,7 +306,7 @@ public bool TryGetFrontendVersion(AltinnRepoEditingContext altinnRepoEditingCont

try
{
indexFilePath = altinnAppGitRepository.FindFiles(new[] { "App/Views/Home/Index.cshtml" }).FirstOrDefault();
indexFilePath = altinnAppGitRepository.FindFiles(new[] { "App/views/Home/Index.cshtml" }).FirstOrDefault();
}
catch (DirectoryNotFoundException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task GetAppVersion_GivenCsProjFile_ShouldReturnOK(string org, strin
{ "[[appLibVersion]]", backendVersion }, { "[[frontendVersion]]", frontendVersion }
};
await AddCsProjToRepo("App/App.csproj", csprojTemplate, replacements);
await AddFrontendIndexToRepo("App/Views/Home/Index.cshtml", indesCshtmlTemplate, replacements);
await AddFrontendIndexToRepo("App/views/Home/Index.cshtml", indesCshtmlTemplate, replacements);

string url = VersionPrefix(org, targetRepository);

Expand Down Expand Up @@ -101,7 +101,7 @@ public async Task GetAppVersion_GivenIndexFileWithoutFrontendVersion_ShouldRetur
await CopyRepositoryForTest(org, app, developer, targetRepository);
await AddCsProjToRepo("App/App.csproj", csprojTemplate,
new Dictionary<string, string>() { { "[[appLibVersion]]", backendVersion } });
await AddFrontendIndexToRepo("App/Views/Home/Index.cshtml", indesCshtmlTemplate);
await AddFrontendIndexToRepo("App/views/Home/Index.cshtml", indesCshtmlTemplate);
string url = VersionPrefix(org, targetRepository);

using var response = await HttpClient.GetAsync(url);
Expand Down
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',
}
8 changes: 8 additions & 0 deletions frontend/testing/playwright/helpers/BasePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ export class BasePage extends RouterRoute {

return text;
}

public async waitForXAmountOfMilliseconds(milliseconds: number): Promise<void> {
await new Promise((resolve) =>
setTimeout(() => {
return resolve('');
}, milliseconds),
);
}
}
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
3 changes: 1 addition & 2 deletions frontend/testing/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export default defineConfig<ExtendedTestOptions>({
trace: 'on-first-retry',
baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL,
},
fullyParallel: true,
timeout: 3 * 60 * 1000,
fullyParallel: false,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: 1, // Github actions always use only 1, so we set to 1 locally as well
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,21 @@ 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();

// Changing langauge happens too fast in the browser, so we need to add some waiting
await loginPage.waitForXAmountOfMilliseconds(2000);

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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { DeployPage } from '../../pages/DeployPage';
import { Header } from '../../components/Header';
import { Gitea } from '../../helpers/Gitea';

const getTtdApp = (appName: string) => `ttd-app-${appName}`;

// Before the tests starts, we need to create the dashboard app
test.beforeAll(async ({ testAppName, request, storageState }) => {
// Create a new app
Expand All @@ -28,7 +30,7 @@ test.afterAll(async ({ request, testAppName }) => {
expect(response.ok()).toBeTruthy();

const responseTTD = await request.delete(
gitea.getDeleteAppEndpoint({ org: 'ttd', app: testAppName }),
gitea.getDeleteAppEndpoint({ org: 'ttd', app: getTtdApp(testAppName) }),
);
expect(responseTTD.ok()).toBeTruthy();
});
Expand Down Expand Up @@ -138,19 +140,20 @@ test('That it is possible to navigate from overview to the deploy page and back
storageState,
}) => {
const testDepartmentOrg: string = 'ttd';
const appName: string = getTtdApp(testAppName); // Need a different app name than the one generated by the user in beforeAll()

const designerApi = new DesignerApi({ app: testAppName });
const designerApi = new DesignerApi({ app: appName });
const response = await designerApi.createApp(
request,
storageState as StorageState,
testDepartmentOrg,
);
expect(response.ok()).toBeTruthy();

const dashboardPage = new DashboardPage(page, { app: testAppName });
const overviewPage = new OverviewPage(page, { app: testAppName });
const deployPage = new DeployPage(page, { app: testAppName });
const header = new Header(page, { app: testAppName });
const dashboardPage = new DashboardPage(page, { app: appName });
const overviewPage = new OverviewPage(page, { app: appName });
const deployPage = new DeployPage(page, { app: appName });
const header = new Header(page, { app: appName });

await dashboardPage.loadDashboardPage();
await dashboardPage.verifyDashboardPage();
Expand All @@ -161,13 +164,18 @@ test('That it is possible to navigate from overview to the deploy page and back
await dashboardPage.checkThatTTDApplicationsHeaderIsVisible();

expect(dashboardPage.org).toEqual('ttd');
await dashboardPage.clickOnTestAppEditButton(testAppName);

await dashboardPage.typeInSearchField(appName);
await dashboardPage.checkThatAppIsVisible(appName);
await dashboardPage.clickOnTestAppEditButton(appName);

// As we have changed env.org to 'ttd', we need to update the org of the new classes to make sure it works.
overviewPage.updateOrgNameEnv(testDepartmentOrg);
deployPage.updateOrgNameEnv(testDepartmentOrg);
header.updateOrgNameEnv(testDepartmentOrg);

// overviewPage.waitForXAmountOfMilliseconds(3000);

await overviewPage.verifyOverviewPage();

// Check Navigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ test('That it is possible to edit security level on "Policy editor" tab, and tha
const securityValueAfterChange = await policyEditor.getSelectedSecurityLevel();
expect(securityValueAfterChange).toBe(securityLevel3Text);

// In dev, the API call to save the policy takes some time, and therefore we add functionality to wait for a while to wait for the save to happen
await settingsModal.waitForXAmountOfMilliseconds(4000);

await settingsModal.navigateToTab('about');
await settingsModal.verifyThatTabIsVisible('about');
await settingsModal.verifyThatTabIsHidden('policy');
Expand Down

0 comments on commit 9b378db

Please sign in to comment.