Skip to content

Commit

Permalink
Change display of references in preview
Browse files Browse the repository at this point in the history
RISDEV-5902
  • Loading branch information
leonie-koch committed Dec 18, 2024
1 parent 30879b9 commit 4150409
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 53 deletions.
50 changes: 16 additions & 34 deletions frontend/src/components/preview/PreviewReferences.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,27 @@ const secondaryReferences = computed(() =>

<template>
<PreviewRow
v-if="
(primaryReferences && primaryReferences.length > 0) ||
(secondaryReferences && secondaryReferences.length > 0)
"
data-testid="references-preview"
v-if="primaryReferences && primaryReferences.length > 0"
data-testid="primary-references-preview"
>
<PreviewCategory>Fundstellen</PreviewCategory>
<PreviewCategory>Primäre Fundstellen</PreviewCategory>
<PreviewContent>
<div v-if="primaryReferences && primaryReferences.length > 0">
<span class="ds-body-01-bold">Primäre Fundstellen</span>

<div
v-for="item in primaryReferences"
:key="item.legalPeriodical?.uuid"
>
{{ item.renderDecision }}
</div>
</div>
<div
v-if="
primaryReferences &&
primaryReferences.length > 0 &&
secondaryReferences &&
secondaryReferences.length > 0
"
>
<br />
<div v-for="item in primaryReferences" :key="item.legalPeriodical?.uuid">
{{ item.renderDecision }}
</div>
</PreviewContent>
</PreviewRow>
<PreviewRow
v-if="secondaryReferences && secondaryReferences.length > 0"
data-testid="secondary-references-preview"
>
<PreviewCategory>Sekundäre Fundstellen</PreviewCategory>
<PreviewContent>
<div
v-if="secondaryReferences && secondaryReferences.length > 0"
class="pt-4"
v-for="item in secondaryReferences"
:key="item.legalPeriodical?.uuid"
>
<span class="ds-body-01-bold">Sekundäre Fundstellen</span>
<div
v-for="item in secondaryReferences"
:key="item.legalPeriodical?.uuid"
>
{{ item.renderDecision }}
</div>
{{ item.renderDecision }}
</div>
</PreviewContent>
</PreviewRow>
Expand Down
55 changes: 41 additions & 14 deletions frontend/test/components/preview/previewReferences.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ describe("preview references", () => {
"exclude references if null or empty",
async (references?: Reference[]) => {
renderComponent(references)
expect(screen.queryByTestId("references-preview")).not.toBeInTheDocument()
expect(
screen.queryByTestId("primary-references-preview"),
).not.toBeInTheDocument()
expect(
screen.queryByTestId("secondary-references-preview"),
).not.toBeInTheDocument()
},
)

it.each([
[
"FundstellenPrimäre FundstellenABC 2006, S.3",
"Primäre FundstellenABC 2006, S.3",
[
new Reference({
citation: "2006, S.3",
Expand All @@ -39,7 +44,7 @@ describe("preview references", () => {
],
],
[
"FundstellenPrimäre FundstellenABC 2006, S.3XYZ 2007, S.4",
"Primäre FundstellenABC 2006, S.3XYZ 2007, S.4",
[
new Reference({
citation: "2006, S.3",
Expand All @@ -57,8 +62,25 @@ describe("preview references", () => {
}),
],
],
])(
`renders primary references %s in preview`,
async (expected: string, references: Reference[]) => {
renderComponent(references)
expect(
screen.getByTestId("primary-references-preview"),
).toBeInTheDocument()
expect(
screen.queryByTestId("secondary-references-preview"),
).not.toBeInTheDocument()
expect(
screen.getByTestId("primary-references-preview"),
).toHaveTextContent(expected)
},
)

it.each([
[
"FundstellenSekundäre FundstellenDEF 2008, S.5",
"Sekundäre FundstellenDEF 2008, S.5",
[
new Reference({
citation: "2008, S.5",
Expand All @@ -70,17 +92,17 @@ describe("preview references", () => {
],
],
[
"FundstellenPrimäre FundstellenABC 2006, S.3Sekundäre FundstellenDEF 2008, S.5",
"Sekundäre FundstellenDEF 2009, S.5DEF 2009, S.8",
[
new Reference({
citation: "2006, S.3",
citation: "2009, S.5",
legalPeriodical: {
abbreviation: "ABC",
primaryReference: true,
abbreviation: "DEF",
primaryReference: false,
},
}),
new Reference({
citation: "2008, S.5",
citation: "2009, S.8",
legalPeriodical: {
abbreviation: "DEF",
primaryReference: false,
Expand All @@ -89,13 +111,18 @@ describe("preview references", () => {
],
],
])(
`renders references %s in preview`,
`renders secondary references %s in preview`,
async (expected: string, references: Reference[]) => {
renderComponent(references)
expect(screen.getByTestId("references-preview")).toBeInTheDocument()
expect(screen.getByTestId("references-preview")).toHaveTextContent(
expected,
)
expect(
screen.queryByTestId("primary-references-preview"),
).not.toBeInTheDocument()
expect(
screen.getByTestId("secondary-references-preview"),
).toBeInTheDocument()
expect(
screen.getByTestId("secondary-references-preview"),
).toHaveTextContent(expected)
},
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ test.describe(
await newTab.getByLabel("Fundstellen").click()
await expect(
newTab
.getByTestId("references-preview")
.getByText("Fundstellen", { exact: true }),
.getByTestId("secondary-references-preview")
.getByText("Sekundäre Fundstellen", { exact: true }),
).toBeVisible()
await expect(
newTab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,12 @@ test.describe("Literature references", () => {
)

const referencesPreview = page.locator(
'[data-testid="references-preview"]',
'[data-testid="secondary-references-preview"]',
)

// Make sure the caselaw citations are in the correct order
expect(await referencesPreview.textContent()).toContain(
"Fundstellen" +
"Sekundäre Fundstellen" +
"Sekundäre Fundstellen" +
"MMG 2024, 1-2, Heft 1 (L)" +
"MMG 2024, 300, Heft 1 (ST)",
)
Expand Down

0 comments on commit 4150409

Please sign in to comment.