From abef59e5dd1d5d1776155dd4471c41ccdaab57e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Youn=C3=A8s=20Adem?= Date: Tue, 8 Oct 2024 15:07:00 +0200 Subject: [PATCH] test: card items --- .../__tests__/datasetCardItems.test.ts | 69 +++++++++++++++ .../__tests__/applicationCardItems.test.ts | 49 +++++++++++ .../__tests__/entitlementCardItems.test.ts | 84 +++++++++++++++++++ 3 files changed, 202 insertions(+) create mode 100644 src/app/datasets/__tests__/datasetCardItems.test.ts create mode 100644 src/app/requests/applications/__tests__/applicationCardItems.test.ts create mode 100644 src/app/requests/entitlements/__tests__/entitlementCardItems.test.ts diff --git a/src/app/datasets/__tests__/datasetCardItems.test.ts b/src/app/datasets/__tests__/datasetCardItems.test.ts new file mode 100644 index 00000000..d561aa5c --- /dev/null +++ b/src/app/datasets/__tests__/datasetCardItems.test.ts @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2024 PNED G.I.E. +// +// SPDX-License-Identifier: Apache-2.0 + +import { SearchedDataset } from "@/services/discovery/types/dataset.types"; +import { createDatasetCardItems } from "../datasetCardItems"; + +describe("datasetCardItems", () => { + beforeEach(() => { + global.window = {} as unknown as Window & typeof globalThis; + }); + + afterEach(() => { + global.window = undefined as unknown as Window & typeof globalThis; + }); + + it("should return dataset card items", () => { + const dataset: SearchedDataset = { + id: "1", + title: "", + description: "dataset1 description", + themes: [{ value: "theme1", label: "theme1" }], + keywords: [ + { + label: "keyword1", + value: "keyword1", + }, + { + label: "keyword2", + value: "keyword2", + }, + ], + distributions: [ + { + id: "r", + title: "distribution1", + description: "distribution1 description", + format: { + label: "format1", + value: "format1", + }, + licenses: [], + createdAt: "2022-01-01T00:00:00.000Z", + modifiedAt: "2022-01-01T00:00:00.000Z", + uri: "distribution1", + }, + ], + organization: { + id: "1", + title: "organization1", + imageUrl: "", + numberOfDatasets: 0, + name: "organization1", + description: "organization1 description", + }, + createdAt: "2024-03-01T00:00:00.000Z", + modifiedAt: "", + recordsCount: 21, + }; + + const items = createDatasetCardItems(dataset); + expect(items.length).toBe(5); + expect(items[0].text).toBe("Created on 1 March 2024"); + expect(items[1].text).toBe(""); + expect(items[2].text).toBe("Published by organization1"); + expect(items[3].text).toBe("1 Distribution"); + expect(items[4].text).toBe("21 Records"); + }); +}); diff --git a/src/app/requests/applications/__tests__/applicationCardItems.test.ts b/src/app/requests/applications/__tests__/applicationCardItems.test.ts new file mode 100644 index 00000000..2478611e --- /dev/null +++ b/src/app/requests/applications/__tests__/applicationCardItems.test.ts @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: 2024 PNED G.I.E. +// +// SPDX-License-Identifier: Apache-2.0 + +import { createApplicationCardItems } from "../applicationCardItems"; +import { ListedApplication } from "@/types/application.types"; + +describe("applicationCardItems", () => { + beforeEach(() => { + global.window = {} as unknown as Window & typeof globalThis; + }); + + afterEach(() => { + global.window = undefined as unknown as Window & typeof globalThis; + }); + + it("should return application card items", () => { + const application: ListedApplication = { + id: 1, + title: "application1", + description: "app 1 description", + datasets: [], + currentState: "submitted", + createdAt: "2024-07-12", + stateChangedAt: "2024-08-03", + }; + + const items = createApplicationCardItems(application); + expect(items.length).toBe(2); + expect(items[0].text).toBe("Created on 12 July 2024"); + expect(items[1].text).toBe("Modified on 3 August 2024"); + }); + it("should return applicationCardItems with empty strings when dates are not empty", () => { + const application: ListedApplication = { + id: 1, + title: "application1", + description: "app 1 description", + datasets: [], + currentState: "submitted", + createdAt: "", + stateChangedAt: "", + }; + + const items = createApplicationCardItems(application); + expect(items.length).toBe(2); + expect(items[0].text).toBe(""); + expect(items[1].text).toBe(""); + }); +}); diff --git a/src/app/requests/entitlements/__tests__/entitlementCardItems.test.ts b/src/app/requests/entitlements/__tests__/entitlementCardItems.test.ts new file mode 100644 index 00000000..78a4aa6b --- /dev/null +++ b/src/app/requests/entitlements/__tests__/entitlementCardItems.test.ts @@ -0,0 +1,84 @@ +// SPDX-FileCopyrightText: 2024 PNED G.I.E. +// +// SPDX-License-Identifier: Apache-2.0 + +import { SearchedDataset } from "@/services/discovery/types/dataset.types"; +import { createEntitlementCardItems } from "../entitlementCardItems"; + +describe("entitlementCardItems", () => { + beforeEach(() => { + global.window = {} as unknown as Window & typeof globalThis; + }); + + afterEach(() => { + global.window = undefined as unknown as Window & typeof globalThis; + }); + + it("should return entitlement Card items", () => { + const dataset: SearchedDataset = { + id: "1", + title: "", + description: "dataset1 description", + themes: [{ value: "theme1", label: "theme1" }], + keywords: [ + { + label: "keyword1", + value: "keyword1", + }, + { + label: "keyword2", + value: "keyword2", + }, + ], + distributions: [ + { + id: "1", + title: "distribution1", + description: "distribution1 description", + format: { + label: "format1", + value: "format1", + }, + licenses: [], + createdAt: "2022-01-01T00:00:00.000Z", + modifiedAt: "2022-01-01T00:00:00.000Z", + uri: "distribution1", + }, + { + id: "2", + title: "distribution2", + description: "distribution2 description", + format: { + label: "format1", + value: "format1", + }, + licenses: [], + createdAt: "2022-01-01T00:00:00.000Z", + modifiedAt: "2022-01-01T00:00:00.000Z", + uri: "distribution1", + }, + ], + organization: { + id: "1", + title: "organization1", + imageUrl: "", + numberOfDatasets: 0, + name: "organization1", + description: "organization1 description", + }, + createdAt: "2024-03-01T00:00:00.000Z", + modifiedAt: "", + }; + + const items = createEntitlementCardItems(dataset, "2024-06-23", ""); + + expect(items.length).toBe(7); + expect(items[0].text).toBe("Created on 1 March 2024"); + expect(items[1].text).toBe(""); + expect(items[2].text).toBe("Published by organization1"); + expect(items[3].text).toBe("2 Distributions"); + expect(items[4].text).toBe(""); + expect(items[5].text).toBe("Start: 23 June 2024"); + expect(items[6].text).toBe("End: N/A"); + }); +});