Skip to content

Commit

Permalink
chore: detailpage e2e tests and decrease timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreiffers committed Dec 18, 2024
1 parent 2ab25a3 commit a9ff003
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class ConceptsPage {

async deletedAllConcepts() {
try {
await this.noResultsLocator().waitFor({ state: 'visible', timeout: 10000 });
await this.noResultsLocator().waitFor({ state: 'visible', timeout: 5000 });
return await this.noResultsLocator().isVisible();
} catch {
return false;
Expand Down
111 changes: 108 additions & 3 deletions apps/concept-catalog-e2e/src/page-object-model/detailPage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, Page, BrowserContext } from '@playwright/test';
import type AxeBuilder from '@axe-core/playwright';
import EditPage from './editPage';
import { Concept } from '@catalog-frontend/types';
import { Concept, Definisjon } from '@catalog-frontend/types';

export default class DetailPage {
url: string;
Expand Down Expand Up @@ -54,8 +54,113 @@ export default class DetailPage {

expect(items.length).toBe(0);
}


getStatusText(uri) {
if (uri.includes('DRAFT')) {
return 'utkast';
} else if (uri.includes('CURRENT')) {
return 'gjeldende';
} else if (uri.includes('REJECTED')) {
return 'avvist';
}
return 'ukjent';
}

getStatusColor(uri) {
if (uri.includes('DRAFT')) {
return 'rgb(250, 238, 194)';
} else if (uri.includes('CURRENT')) {
return 'rgb(209, 244, 225)';
} else if (uri.includes('REJECTED')) {
return 'rgb(244, 245, 246)';
}
return 'ukjent';
}

getDefinitionSourceText(def: Definisjon) {
if(def.kildebeskrivelse.forholdTilKilde === 'egendefinert') {
return "Egendefinert";
}
return "";
}

getVersionText(concept: Concept) {
return `${concept.versjonsnr.major}.${concept.versjonsnr.minor}.${concept.versjonsnr.patch}`
}

async expectHeading(concept: Concept) {
await expect(this.page.getByRole('heading', { name: concept.anbefaltTerm.navn.nb as string })).toBeVisible();

const statusTag = this.page.getByText(this.getStatusText(concept.statusURI), { exact: true });
await expect(statusTag).toBeVisible();

const backgroundColor = await statusTag.evaluate((el) =>
window.getComputedStyle(el).backgroundColor
);
expect(backgroundColor).toBe(this.getStatusColor(concept.statusURI));
}

async expectActionButtons() {
await expect(this.page.getByRole('button', { name: 'Rediger' })).toBeVisible();
await expect(this.page.getByRole('button', { name: 'Slett' })).toBeVisible();
await expect(this.page.getByRole('link', { name: 'Foreslå endring' })).toBeVisible();
}

async expectLanguageCombobox() {
const languageCombobox = this.page.getByRole('combobox');
const languageValue = await languageCombobox.inputValue();
await expect(languageCombobox).toBeVisible();
await expect(languageValue).toBe('nb');
}

async expectLeftColumnContent(concept: Concept) {
await expect(
this.page
.locator('div')
.filter({
hasText: new RegExp(`Definisjon:${concept.definisjon.tekst.nb as string}Kilde:${this.getDefinitionSourceText(concept.definisjon)}`),
}).nth(1)
).toBeVisible();
}

async expectTabs() {
await expect(this.page.getByRole('button', { name: 'Kommentarer' })).toBeVisible();
await expect(this.page.getByRole('button', { name: 'Endringshistorikk' })).toBeVisible();
await expect(this.page.getByRole('button', { name: 'Versjoner' })).toBeVisible();
}

async expectRightColumnContent(concept: Concept) {
await expect(this.page.getByRole('heading', { name: 'Begreps-ID'})).toBeVisible();
await expect(this.page.getByText(/^[a-z0-9]+-[a-z0-9]+-[a-z0-9]+-[a-z0-9]+-[a-z0-9]+$/)).toBeVisible();

await expect(this.page.getByRole('heading', { name: 'Publiseringstilstand'})).toBeVisible();
await expect(this.page.getByText(concept.erPublisert ? 'Publisert i felles datakatalog' : 'Ikke publisert')).toBeVisible();

await expect(this.page.getByRole('heading', { name: 'Versjon'})).toBeVisible();
await expect(this.page.getByText(this.getVersionText(concept))).toBeVisible();

await expect(this.page.getByRole('heading', { name: 'Dato sist oppdatert'})).toBeVisible();
await expect(this.page.getByText(this.getVersionText(concept))).toBeVisible();

await expect(this.page.getByRole('heading', { name: 'Opprettet', exact: true })).toBeVisible();
await expect(this.page.getByText(this.getVersionText(concept))).toBeVisible();

await expect(this.page.getByRole('heading', { name: 'Opprettet av', exact: true })).toBeVisible();
await expect(this.page.getByText(this.getVersionText(concept))).toBeVisible();

if(concept.kontaktpunkt?.harEpost || concept.kontaktpunkt?.harTelefon) {
await expect(this.page.getByRole('heading', { name: 'Kontaktinformasjon for eksterne'})).toBeVisible();
await expect(this.page.getByText(concept.kontaktpunkt.harEpost)).toBeVisible({ visible: Boolean(concept.kontaktpunkt.harEpost) });
await expect(this.page.getByText(concept.kontaktpunkt.harTelefon)).toBeVisible({ visible: Boolean(concept.kontaktpunkt.harTelefon) });
}
}

public async expectDetails(concept: Concept) {
return true;
await this.expectActionButtons();
await this.expectLanguageCombobox();
await this.expectHeading(concept);
await this.expectLeftColumnContent(concept);
await this.expectRightColumnContent(concept);
await this.expectTabs();
}
}

0 comments on commit a9ff003

Please sign in to comment.