-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
src/app/requests/applications/__tests__/applicationCardItems.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(""); | ||
}); | ||
}); |
84 changes: 84 additions & 0 deletions
84
src/app/requests/entitlements/__tests__/entitlementCardItems.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
}); |