From a9ff0039eeab0890d9d15bc83990f0f920aa0718 Mon Sep 17 00:00:00 2001 From: Jeff Reiffers Date: Wed, 18 Dec 2024 15:27:50 +0100 Subject: [PATCH] chore: detailpage e2e tests and decrease timeout --- .../src/page-object-model/conceptsPage.ts | 2 +- .../src/page-object-model/detailPage.ts | 111 +++++++++++++++++- 2 files changed, 109 insertions(+), 4 deletions(-) diff --git a/apps/concept-catalog-e2e/src/page-object-model/conceptsPage.ts b/apps/concept-catalog-e2e/src/page-object-model/conceptsPage.ts index 4467ba8d..5a1b2a47 100644 --- a/apps/concept-catalog-e2e/src/page-object-model/conceptsPage.ts +++ b/apps/concept-catalog-e2e/src/page-object-model/conceptsPage.ts @@ -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; diff --git a/apps/concept-catalog-e2e/src/page-object-model/detailPage.ts b/apps/concept-catalog-e2e/src/page-object-model/detailPage.ts index 5a4cbfd7..b2604da9 100644 --- a/apps/concept-catalog-e2e/src/page-object-model/detailPage.ts +++ b/apps/concept-catalog-e2e/src/page-object-model/detailPage.ts @@ -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; @@ -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(); } }