Skip to content

Commit

Permalink
test: card items
Browse files Browse the repository at this point in the history
  • Loading branch information
admy7 committed Oct 8, 2024
1 parent 42f9b56 commit abef59e
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/app/datasets/__tests__/datasetCardItems.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
Original file line number Diff line number Diff line change
@@ -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("");
});
});
Original file line number Diff line number Diff line change
@@ -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");
});
});

0 comments on commit abef59e

Please sign in to comment.