Skip to content

Commit

Permalink
Add handover tests
Browse files Browse the repository at this point in the history
RISDEV-5883
  • Loading branch information
anne-ds committed Jan 17, 2025
1 parent 7671f85 commit 5f4724c
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 32 deletions.
7 changes: 1 addition & 6 deletions frontend/src/components/HandoverDocumentationUnitView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,6 @@ const isDecisionReasonsInvalid = computed<boolean>(
!!store.documentUnit?.longTexts.decisionReasons,
)
const hasPendingDuplicateWarning = computed<boolean>(
() => pendingDuplicates.value.length > 0,
)
const isScheduled = computed<boolean>(
() => !!store.documentUnit!.managementData.scheduledPublicationDateTime,
)
Expand Down Expand Up @@ -593,8 +589,7 @@ const isPublishable = computed<boolean>(
</div>
</div>
<HandoverDuplicateCheckView
:has-active-duplicate-warning="hasPendingDuplicateWarning"
:is-duplicate-feature-active="isDuplicateFeatureActive"
v-if="isDuplicateFeatureActive"
:pending-duplicates="pendingDuplicates"
/>
<div class="border-b-1 border-b-gray-400"></div>
Expand Down
19 changes: 9 additions & 10 deletions frontend/src/components/HandoverDuplicateCheckView.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<script lang="ts" setup>
import dayjs from "dayjs"
import { computed } from "vue"
import DecisionSummary from "@/components/DecisionSummary.vue"
import TextButton from "@/components/input/TextButton.vue"
import { DuplicateRelation } from "@/domain/documentUnit"
import IconCheck from "~icons/ic/baseline-check"
import IconErrorOutline from "~icons/ic/baseline-error-outline"
defineProps<{
isDuplicateFeatureActive: boolean
hasActiveDuplicateWarning: boolean
const props = defineProps<{
pendingDuplicates: DuplicateRelation[]
}>()
const hasPendingDuplicateWarning = computed<boolean>(
() => props.pendingDuplicates.length > 0,
)
function renderSummary(duplicateRelation: DuplicateRelation) {
return [
...(duplicateRelation.courtLabel
Expand All @@ -26,14 +29,10 @@ function renderSummary(duplicateRelation: DuplicateRelation) {
}
</script>
<template>
<div
v-if="isDuplicateFeatureActive"
aria-label="Dublettenprüfung"
class="flex flex-col"
>
<div aria-label="Dublettenprüfung" class="flex flex-col">
<h2 class="ds-label-01-bold mb-16">Dublettenprüfung</h2>

<div v-if="hasActiveDuplicateWarning">
<div v-if="hasPendingDuplicateWarning">
<div class="flex flex-row gap-8">
<IconErrorOutline class="text-red-800" />
<div class="ds-body-01-reg flex flex-col gap-8">
Expand Down Expand Up @@ -75,7 +74,7 @@ function renderSummary(duplicateRelation: DuplicateRelation) {
</div>
<div v-else class="flex flex-row gap-8">
<IconCheck class="text-green-700" />
<p>Es besteht kein Dublettenverdacht.</p>
<p>Es besteht kein Dublettenverdacht</p>
</div>
</div>
</template>
111 changes: 96 additions & 15 deletions frontend/test/components/handoverDocument.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
import { createTestingPinia } from "@pinia/testing"
import { userEvent } from "@testing-library/user-event"
import { render, fireEvent, screen } from "@testing-library/vue"
import { fireEvent, render, screen } from "@testing-library/vue"
import { Stubs } from "@vue/test-utils/dist/types"
import { beforeEach } from "vitest"
import { nextTick } from "vue"
import { createRouter, createWebHistory } from "vue-router"
import HandoverDocumentationUnitView from "@/components/HandoverDocumentationUnitView.vue"
import DocumentUnit from "@/domain/documentUnit"
import DocumentUnit, { DuplicationRelationStatus } from "@/domain/documentUnit"
import { EventRecordType, HandoverMail, Preview } from "@/domain/eventRecord"
import LegalForce from "@/domain/legalForce"
import NormReference from "@/domain/normReference"
import SingleNorm from "@/domain/singleNorm"
import featureToggleService from "@/services/featureToggleService"
import handoverDocumentationUnitService from "@/services/handoverDocumentationUnitService"
import routes from "~/test-helper/routes"

const router = createRouter({
history: createWebHistory(),
routes: [
{
path: "/caselaw/documentUnit/:documentNumber/categories",
name: "caselaw-documentUnit-documentNumber-categories",
component: {},
},
{
path: "/",
name: "caselaw",
component: {},
},
],
routes: routes,
})

function renderComponent(
Expand Down Expand Up @@ -73,6 +65,10 @@ describe("HandoverDocumentationUnitView:", () => {
success: true,
}),
})
vi.spyOn(featureToggleService, "isEnabled").mockResolvedValue({
status: 200,
data: true,
})
})
describe("renders plausibility check", () => {
it("with all required fields filled", async () => {
Expand Down Expand Up @@ -380,6 +376,91 @@ describe("HandoverDocumentationUnitView:", () => {
"caselaw-documentUnit-documentNumber-categories",
)
})

it("should not allow to publish with pending duplicate", async () => {
renderComponent({
documentUnit: new DocumentUnit("123", {
documentNumber: "foo",
managementData: {
duplicateRelations: [
{
documentNumber: "documentNumber",
status: DuplicationRelationStatus.PENDING,
isJdvDuplicateCheckActive: true,
},
],
borderNumbers: [],
},
coreData: {
fileNumbers: ["foo"],
court: { type: "type", location: "location", label: "label" },
decisionDate: "2022-02-01",
documentType: {
jurisShortcut: "ca",
label: "category",
},
},
}),
})

// wait for feature flag to be loaded, can be removed when flag is removed.
await nextTick()

expect(
screen.getByText("Es besteht Dublettenverdacht."),
).toBeInTheDocument()
expect(
screen.getByRole("button", {
name: "Dokumentationseinheit an jDV übergeben",
}),
).toBeDisabled()
})

it("should allow to publish with ignored duplicate", async () => {
renderComponent({
documentUnit: new DocumentUnit("123", {
documentNumber: "foo",
coreData: {
fileNumbers: ["foo"],
court: {
type: "type",
location: "location",
label: "label",
},
decisionDate: "2022-02-01",
legalEffect: "legalEffect",
documentType: {
jurisShortcut: "ca",
label: "category",
},
},
longTexts: { decisionReasons: "decisionReasons" },
managementData: {
duplicateRelations: [
{
documentNumber: "documentNumber",
isJdvDuplicateCheckActive: true,
status: DuplicationRelationStatus.IGNORED,
},
],
borderNumbers: [],
},
}),
})

// wait for feature flag to be loaded, can be removed when flag is removed.
await nextTick()

expect(await screen.findByText("XML Vorschau")).toBeInTheDocument()
expect(
screen.getByText("Es besteht kein Dublettenverdacht"),
).toBeInTheDocument()
expect(
screen.getByRole("button", {
name: "Dokumentationseinheit an jDV übergeben",
}),
).toBeEnabled()
})
})

it("should show error message with invalid border numbers", async () => {
Expand Down Expand Up @@ -640,7 +721,7 @@ describe("HandoverDocumentationUnitView:", () => {
await new Promise((resolve) => setTimeout(resolve, 0))

expect(container).toHaveTextContent(
`Übergabe an jDVPlausibilitätsprüfungAlle Pflichtfelder sind korrekt ausgefülltRandnummernprüfungDie Reihenfolge der Randnummern ist korrektXML VorschauDokumentationseinheit an jDV übergebenOder für später terminieren:Datum * Uhrzeit * Termin setzenLetzte EreignisseXml Email Abgabe - 02.01.2000 um 00:00 UhrE-Mail an: receiver address Betreff: mail subject`,
`Übergabe an jDVPlausibilitätsprüfungAlle Pflichtfelder sind korrekt ausgefülltRandnummernprüfungDie Reihenfolge der Randnummern ist korrektDublettenprüfungEs besteht kein DublettenverdachtXML VorschauDokumentationseinheit an jDV übergebenOder für später terminieren:Datum * Uhrzeit * Termin setzenLetzte EreignisseXml Email Abgabe - 02.01.2000 um 00:00 UhrE-Mail an: receiver address Betreff: mail subject`,
)

const codeSnippet = screen.queryByTestId("code-snippet")
Expand Down
117 changes: 117 additions & 0 deletions frontend/test/components/handoverDocumentDuplicateCheck.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { createTestingPinia } from "@pinia/testing"
import { render, screen } from "@testing-library/vue"
import { describe } from "vitest"
import { createRouter, createWebHistory } from "vue-router"
import HandoverDuplicateCheckView from "@/components/HandoverDuplicateCheckView.vue"
import {
DuplicateRelation,
DuplicationRelationStatus,
} from "@/domain/documentUnit"
import { PublicationState } from "@/domain/publicationStatus"
import routes from "~/test-helper/routes"

const router = createRouter({
history: createWebHistory(),
routes: routes,
})

describe("HandoverDocumentDuplicateCheckView:", () => {
test("without duplicates", async () => {
render(HandoverDuplicateCheckView, {
props: { pendingDuplicates: [] },
global: {
plugins: [router],
},
})

expect(screen.getByText("Dublettenprüfung")).toBeInTheDocument()
expect(
screen.getByText("Es besteht kein Dublettenverdacht"),
).toBeInTheDocument()
expect(
screen.queryByText("Es besteht Dublettenverdacht."),
).not.toBeInTheDocument()
expect(screen.queryByText("Dokumentationseinheit")).not.toBeInTheDocument()
expect(
screen.queryByRole("button", {
name: "Dublettenwarnung prüfen",
}),
).not.toBeInTheDocument()
})

test("with pending unpublished duplicate", async () => {
const duplicate: DuplicateRelation = {
documentNumber: "documentNumber",
fileNumber: "AZ ABC",
courtLabel: "AG Aachen",
decisionDate: "2025-01-15",
documentType: "Beschluss",
status: DuplicationRelationStatus.PENDING,
isJdvDuplicateCheckActive: true,
publicationStatus: PublicationState.UNPUBLISHED,
}
render(HandoverDuplicateCheckView, {
props: { pendingDuplicates: [duplicate] },
global: {
plugins: [[createTestingPinia()], [router]],
},
})

expect(screen.getByText("Dublettenprüfung")).toBeInTheDocument()
expect(
screen.getByText("Es besteht Dublettenverdacht."),
).toBeInTheDocument()
expect(screen.getByText("Dokumentationseinheit")).toBeInTheDocument()
expect(
screen.getByText("AG Aachen, 15.01.2025, AZ ABC, Beschluss,", {
exact: false,
}),
).toBeInTheDocument()
expect(screen.getByText("Unveröffentlicht")).toBeInTheDocument()
expect(
screen.getByRole("button", {
name: "Dublettenwarnung prüfen",
}),
).toBeInTheDocument()
expect(
screen.queryByText("Es besteht kein Dublettenverdacht"),
).not.toBeInTheDocument()
})

test("with pending unpublished and published duplicates", async () => {
const unpublishedDuplicate: DuplicateRelation = {
documentNumber: "documentNumber",
status: DuplicationRelationStatus.PENDING,
isJdvDuplicateCheckActive: true,
publicationStatus: PublicationState.UNPUBLISHED,
}
const publishedDuplicate: DuplicateRelation = {
documentNumber: "documentNumber",
status: DuplicationRelationStatus.PENDING,
isJdvDuplicateCheckActive: true,
publicationStatus: PublicationState.PUBLISHED,
}
render(HandoverDuplicateCheckView, {
props: { pendingDuplicates: [publishedDuplicate, unpublishedDuplicate] },
global: {
plugins: [[createTestingPinia()], [router]],
},
})

expect(screen.getByText("Dublettenprüfung")).toBeInTheDocument()
expect(
screen.getByText("Es besteht Dublettenverdacht."),
).toBeInTheDocument()
expect(screen.getByText("Dokumentationseinheiten")).toBeInTheDocument()
expect(screen.getByText("Unveröffentlicht")).toBeInTheDocument()
expect(screen.getByText("Veröffentlicht")).toBeInTheDocument()
expect(
screen.getByRole("button", {
name: "Dublettenwarnung prüfen",
}),
).toBeInTheDocument()
expect(
screen.queryByText("Es besteht kein Dublettenverdacht"),
).not.toBeInTheDocument()
})
})
3 changes: 2 additions & 1 deletion frontend/test/test-helper/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ const routes = [
component: {},
},
{
path: "/caselaw/documentUnit/:documentNumber/managementdata",
path: "/caselaw/documentUnit/:documentNumber/managementData",
name: "caselaw-documentUnit-documentNumber-managementData",
component: {},
},
{ path: "/managementData", name: "managementData", component: {} },
{
path: "/caselaw/periodical-evaluation/:editionId",
name: "caselaw-periodical-evaluation-editionId",
Expand Down

0 comments on commit 5f4724c

Please sign in to comment.