diff --git a/frontend/test/e2e/norms/fixtures.ts b/frontend/test/e2e/norms/fixtures.ts index c16f2b0469..713ea226e5 100644 --- a/frontend/test/e2e/norms/fixtures.ts +++ b/frontend/test/e2e/norms/fixtures.ts @@ -8,6 +8,7 @@ import { import { importNormViaApi, loadJurisTestFile } from "./e2e-utils" import { normData } from "./testdata/norm_basic" import { FieldType, MetadataInputSection } from "./utilities" +import { FOOTNOTE_LABELS } from "@/components/footnotes/types" type MyFixtures = { normData: NormData @@ -1335,47 +1336,26 @@ export function getNormBySections(norm: NormData): MetadataInputSection[] { }, ], }, - // { - // heading: "Fußnoten", - // fields: [ - // { - // type: FieldType.TEXT, - // id: "otherFootnote", - // label: "Sonstige Fußnote", - // value: norm.otherFootnote, - // }, - // { - // type: FieldType.TEXT, - // id: "footnoteChange", - // label: "Änderungsfußnote", - // value: norm.footnoteChange, - // }, - // { - // type: FieldType.TEXT, - // id: "footnoteComment", - // label: "Kommentierende Fußnote", - // value: norm.footnoteComment, - // }, - // { - // type: FieldType.TEXT, - // id: "footnoteDecision", - // label: "BVerfG-Entscheidung", - // value: norm.footnoteDecision, - // }, - // { - // type: FieldType.TEXT, - // id: "footnoteStateLaw", - // label: "Landesrecht", - // value: norm.footnoteStateLaw, - // }, - // { - // type: FieldType.TEXT, - // id: "footnoteEuLaw", - // label: "EU/EG-Recht", - // value: norm.footnoteEuLaw, - // }, - // ], - // }, + { + heading: "Fußnoten", + isRepeatedSection: true, + isNotImported: true, + id: "footnotes", + fields: [ + { + type: FieldType.EDITOR, + id: "footnotes", + label: "Fußnoten", + values: norm.metadataSections?.FOOTNOTES?.map( + (section) => + section.FOOTNOTE?.map((note) => ({ + label: FOOTNOTE_LABELS[Object.keys(note)[0]], + content: Object.values(note)[0][0] as string, + }))?.flat() ?? [] + ), + }, + ], + }, { heading: "Gültigkeitsregelung", isSingleFieldSection: true, diff --git a/frontend/test/e2e/norms/testdata/norm_edited_fields.ts b/frontend/test/e2e/norms/testdata/norm_edited_fields.ts index 055ca802ac..facee37eca 100644 --- a/frontend/test/e2e/norms/testdata/norm_edited_fields.ts +++ b/frontend/test/e2e/norms/testdata/norm_edited_fields.ts @@ -225,6 +225,15 @@ export const newNorm: NormData = { APPENDIX: ["appendix"], }, ], + FOOTNOTES: [ + { + FOOTNOTE: [ + { FOOTNOTE_REFERENCE: ["§ 7 Abs. 1a Satz 1 u. 2"] }, + { FOOTNOTE_CHANGE: ["eine ganze Menge Text"] }, + { FOOTNOTE_EU_LAW: ["irgendwas halt"] }, + ], + }, + ], }, officialLongTitle: "Verordnung zur Anpassung von Rechtsverordnungen an das Tierarzneimittelrecht", @@ -245,12 +254,6 @@ export const newNorm: NormData = { documentTextProof: "documentTextProof", eli: "europeanLegalIdentifier", otherDocumentNote: "otherDocumentNote", - // otherFootnote: "otherFootnote", - // footnoteChange: "footnoteChange", - // footnoteComment: "footnoteComment", - // footnoteDecision: "footnoteDecision", - // footnoteStateLaw: "footnoteStateLaw", - // footnoteEuLaw: "footnoteEuLaw", otherStatusNote: "otherStatusNote", reissueArticle: "reissueArticle", reissueDate: "01.11.2022", diff --git a/frontend/test/e2e/norms/utilities/inputs/editing.ts b/frontend/test/e2e/norms/utilities/inputs/editing.ts index f3176321c1..37df0b5c3d 100644 --- a/frontend/test/e2e/norms/utilities/inputs/editing.ts +++ b/frontend/test/e2e/norms/utilities/inputs/editing.ts @@ -3,8 +3,11 @@ import { AnyField, FieldType, FieldValueTypeMapping, + FootnoteInputType, MetadataInputSection, } from "./types" +import { FOOTNOTE_LABELS } from "@/components/footnotes/types" +import { MetadatumType } from "@/domain/Norm" type FieldFiller = (page: Page, id: string, value: T) => Promise @@ -24,6 +27,23 @@ const fillTextArea: FieldFiller = async (page, id, value) => { await input.fill(value) } +const fillTextEditor: FieldFiller = async ( + page, + id, + value +) => { + const input = page.locator(`[data-testid='${id}']`) + await expect(input).toBeEditable() + await input.click() + for (const footnote of value) { + if (footnote.label != FOOTNOTE_LABELS[MetadatumType.FOOTNOTE_REFERENCE]) { + await input.type(` #${footnote.label}`) + await input.press("Enter") + } + await input.type(footnote.content) + } +} + const fillCheckbox: FieldFiller = async (page, id, value) => { const input = page.locator(`input#${id}`) await expect(input).toBeEditable() @@ -81,6 +101,7 @@ const FIELD_FILLERS: FieldFillerMapping = { [FieldType.CHIPS]: fillChipsInput, [FieldType.DROPDOWN]: fillDropdown, [FieldType.TEXTAREA]: fillTextArea, + [FieldType.EDITOR]: fillTextEditor, } export function fillInputField< diff --git a/frontend/test/e2e/norms/utilities/inputs/reading.ts b/frontend/test/e2e/norms/utilities/inputs/reading.ts index 1442da5f56..694f43e4d1 100644 --- a/frontend/test/e2e/norms/utilities/inputs/reading.ts +++ b/frontend/test/e2e/norms/utilities/inputs/reading.ts @@ -3,8 +3,11 @@ import { AnyField, FieldType, FieldValueTypeMapping, + FootnoteInputType, MetadataInputSection, } from "./types" +import { FOOTNOTE_LABELS } from "@/components/footnotes/types" +import { MetadatumType } from "@/domain/Norm" type FieldExpecter = (page: Page, id: string, value: T) => Promise @@ -32,6 +35,21 @@ const expectRadioButton: FieldExpecter = async (page, id, value) => { expect(checked).toBe(value) } +const expectTextEditor: FieldExpecter = async ( + page, + id, + value +) => { + const input = page.locator(`[data-testid='${id}']`) + await expect(input).toBeVisible() + for (const footnote of value) { + if (footnote.label != FOOTNOTE_LABELS[MetadatumType.FOOTNOTE_REFERENCE]) { + expect(await input.innerText()).toContain(footnote.label) + } + expect(await input.innerText()).toContain(footnote.content) + } +} + const expectChipsInput: FieldExpecter = async (page, _, value) => { for (const subValue of (value ?? []) as string[]) { const chip = page.locator(`div.label-wrapper:text-is("${subValue}")`) @@ -51,6 +69,7 @@ const FIELD_EXPECTER: FieldExpectMapping = { [FieldType.RADIO]: expectRadioButton, [FieldType.CHIPS]: expectChipsInput, [FieldType.DROPDOWN]: expectDropdown, + [FieldType.EDITOR]: expectTextEditor, } export async function expectInputFieldHasCorrectValue< @@ -71,8 +90,10 @@ export async function expectInputFieldGroupHasCorrectValues( valueIndex !== undefined ? field.values?.[valueIndex] : field.value if (value !== undefined) { - const label = page.locator(`label:has-text("${field.label}")`).first() - await expect(label).toBeVisible() + if (field.type !== FieldType.EDITOR) { + const label = page.locator(`label:has-text("${field.label}")`).first() + await expect(label).toBeVisible() + } await expectInputFieldHasCorrectValue(page, field.type, field.id, value) } @@ -89,9 +110,11 @@ export async function expectRepeatedSectionListHasCorrectEntries( await expandable.click() - const numberOfSectionRepetition = Math.max( - ...(section.fields ?? []).map((field) => field.values?.length ?? 0) - ) + const numberOfSectionRepetition = section.isNotImported + ? 1 + : Math.max( + ...(section.fields ?? []).map((field) => field.values?.length ?? 0) + ) const listEntries = expandable.getByLabel("Listen Eintrag") const entryCount = await listEntries.count() expect(entryCount).toBe(numberOfSectionRepetition) diff --git a/frontend/test/e2e/norms/utilities/inputs/types.ts b/frontend/test/e2e/norms/utilities/inputs/types.ts index 2fde5a1519..0e5302ac71 100644 --- a/frontend/test/e2e/norms/utilities/inputs/types.ts +++ b/frontend/test/e2e/norms/utilities/inputs/types.ts @@ -5,9 +5,12 @@ export enum FieldType { CHIPS, DROPDOWN, TEXTAREA, + EDITOR, } -export type FieldValue = string | boolean | string[] +export type FootnoteInputType = { label: string; content: string } + +export type FieldValue = string | boolean | string[] | FootnoteInputType[] // FIXME: How to relate these two types to each other? export type FieldValueTypeMapping = { [FieldType.TEXT]: string @@ -16,6 +19,7 @@ export type FieldValueTypeMapping = { [FieldType.CHIPS]: string[] [FieldType.DROPDOWN]: string [FieldType.TEXTAREA]: string + [FieldType.EDITOR]: FootnoteInputType[] } // FIXME: resolve awkward mixture with value and values.