From 5f4724c517ac56a556f0e48a99a28463bddfd29f Mon Sep 17 00:00:00 2001 From: anne-ds Date: Fri, 17 Jan 2025 12:44:56 +0100 Subject: [PATCH] Add handover tests RISDEV-5883 --- .../HandoverDocumentationUnitView.vue | 7 +- .../components/HandoverDuplicateCheckView.vue | 19 ++- .../test/components/handoverDocument.spec.ts | 111 ++++++++++++++--- .../handoverDocumentDuplicateCheck.spec.ts | 117 ++++++++++++++++++ frontend/test/test-helper/routes.ts | 3 +- 5 files changed, 225 insertions(+), 32 deletions(-) create mode 100644 frontend/test/components/handoverDocumentDuplicateCheck.spec.ts diff --git a/frontend/src/components/HandoverDocumentationUnitView.vue b/frontend/src/components/HandoverDocumentationUnitView.vue index 3ec393cd91..0e001a600b 100644 --- a/frontend/src/components/HandoverDocumentationUnitView.vue +++ b/frontend/src/components/HandoverDocumentationUnitView.vue @@ -313,10 +313,6 @@ const isDecisionReasonsInvalid = computed( !!store.documentUnit?.longTexts.decisionReasons, ) -const hasPendingDuplicateWarning = computed( - () => pendingDuplicates.value.length > 0, -) - const isScheduled = computed( () => !!store.documentUnit!.managementData.scheduledPublicationDateTime, ) @@ -593,8 +589,7 @@ const isPublishable = computed(
diff --git a/frontend/src/components/HandoverDuplicateCheckView.vue b/frontend/src/components/HandoverDuplicateCheckView.vue index b512be0cd2..67e2db8b5b 100644 --- a/frontend/src/components/HandoverDuplicateCheckView.vue +++ b/frontend/src/components/HandoverDuplicateCheckView.vue @@ -1,17 +1,20 @@ diff --git a/frontend/test/components/handoverDocument.spec.ts b/frontend/test/components/handoverDocument.spec.ts index df7fd54756..84a501f47d 100644 --- a/frontend/test/components/handoverDocument.spec.ts +++ b/frontend/test/components/handoverDocument.spec.ts @@ -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( @@ -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 () => { @@ -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 () => { @@ -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") diff --git a/frontend/test/components/handoverDocumentDuplicateCheck.spec.ts b/frontend/test/components/handoverDocumentDuplicateCheck.spec.ts new file mode 100644 index 0000000000..d9ad445a4d --- /dev/null +++ b/frontend/test/components/handoverDocumentDuplicateCheck.spec.ts @@ -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() + }) +}) diff --git a/frontend/test/test-helper/routes.ts b/frontend/test/test-helper/routes.ts index 5ddf3e3da6..5c80b3cdfd 100644 --- a/frontend/test/test-helper/routes.ts +++ b/frontend/test/test-helper/routes.ts @@ -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",