Skip to content

Commit

Permalink
Adding e2e tests for footnotes
Browse files Browse the repository at this point in the history
RISDEV-1464
  • Loading branch information
hmones committed Jun 23, 2023
1 parent 8ab9234 commit fe6208c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 53 deletions.
62 changes: 21 additions & 41 deletions frontend/test/e2e/norms/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 9 additions & 6 deletions frontend/test/e2e/norms/testdata/norm_edited_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions frontend/test/e2e/norms/utilities/inputs/editing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (page: Page, id: string, value: T) => Promise<void>

Expand All @@ -24,6 +27,23 @@ const fillTextArea: FieldFiller<string> = async (page, id, value) => {
await input.fill(value)
}

const fillTextEditor: FieldFiller<FootnoteInputType[]> = 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<boolean> = async (page, id, value) => {
const input = page.locator(`input#${id}`)
await expect(input).toBeEditable()
Expand Down Expand Up @@ -81,6 +101,7 @@ const FIELD_FILLERS: FieldFillerMapping = {
[FieldType.CHIPS]: fillChipsInput,
[FieldType.DROPDOWN]: fillDropdown,
[FieldType.TEXTAREA]: fillTextArea,
[FieldType.EDITOR]: fillTextEditor,
}

export function fillInputField<
Expand Down
33 changes: 28 additions & 5 deletions frontend/test/e2e/norms/utilities/inputs/reading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = (page: Page, id: string, value: T) => Promise<void>

Expand Down Expand Up @@ -32,6 +35,21 @@ const expectRadioButton: FieldExpecter<boolean> = async (page, id, value) => {
expect(checked).toBe(value)
}

const expectTextEditor: FieldExpecter<FootnoteInputType[]> = 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<string[]> = async (page, _, value) => {
for (const subValue of (value ?? []) as string[]) {
const chip = page.locator(`div.label-wrapper:text-is("${subValue}")`)
Expand All @@ -51,6 +69,7 @@ const FIELD_EXPECTER: FieldExpectMapping = {
[FieldType.RADIO]: expectRadioButton,
[FieldType.CHIPS]: expectChipsInput,
[FieldType.DROPDOWN]: expectDropdown,
[FieldType.EDITOR]: expectTextEditor,
}

export async function expectInputFieldHasCorrectValue<
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion frontend/test/e2e/norms/utilities/inputs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit fe6208c

Please sign in to comment.