diff --git a/client/src/components/History/Content/Collection/CollectionDescription.test.js b/client/src/components/History/Content/Collection/CollectionDescription.test.js deleted file mode 100644 index 4e2712ac6f22..000000000000 --- a/client/src/components/History/Content/Collection/CollectionDescription.test.js +++ /dev/null @@ -1,64 +0,0 @@ -import { mount } from "@vue/test-utils"; -import { getLocalVue } from "tests/jest/helpers"; - -import CollectionDescription from "./CollectionDescription"; -import { JobStateSummary } from "./JobStateSummary"; - -const localVue = getLocalVue(); - -describe("CollectionDescription", () => { - let wrapper; - - beforeEach(() => { - const jss = new JobStateSummary(); - wrapper = mount(CollectionDescription, { - propsData: { - collectionType: "list", - jobStateSummary: jss, - }, - localVue, - }); - }); - - it("should display expected heterogeneous descriptions", async () => { - const HETEROGENEOUS_DATATYPES = ["txt", "csv", "tabular"]; - await wrapper.setProps({ elementCount: 1, elementsDatatypes: HETEROGENEOUS_DATATYPES }); - expect(wrapper.text()).toBe("a list with 1 dataset"); - - await wrapper.setProps({ elementCount: 2, collectionType: "paired" }); - expect(wrapper.text()).toBe("a pair with 2 datasets"); - - await wrapper.setProps({ elementCount: 10, collectionType: "list" }); - expect(wrapper.text()).toBe("a list with 10 datasets"); - - await wrapper.setProps({ collectionType: "list:paired" }); - expect(wrapper.text()).toBe("a list with 10 pairs"); - - await wrapper.setProps({ collectionType: "list:list" }); - expect(wrapper.text()).toBe("a list with 10 lists"); - - await wrapper.setProps({ collectionType: "other" }); - expect(wrapper.text()).toBe("a nested list with 10 dataset collections"); - }); - - it("should display expected homogeneous descriptions", async () => { - const EXPECTED_HOMOGENEOUS_DATATYPE = "tabular"; - await wrapper.setProps({ elementCount: 1, elementsDatatypes: [EXPECTED_HOMOGENEOUS_DATATYPE] }); - expect(wrapper.text()).toBe(`a list with 1 ${EXPECTED_HOMOGENEOUS_DATATYPE} dataset`); - - await wrapper.setProps({ elementCount: 2, collectionType: "paired" }); - expect(wrapper.text()).toBe(`a pair with 2 ${EXPECTED_HOMOGENEOUS_DATATYPE} datasets`); - - await wrapper.setProps({ elementCount: 10, collectionType: "list" }); - expect(wrapper.text()).toBe(`a list with 10 ${EXPECTED_HOMOGENEOUS_DATATYPE} datasets`); - - await wrapper.setProps({ collectionType: "list:paired" }); - expect(wrapper.text()).toBe(`a list with 10 ${EXPECTED_HOMOGENEOUS_DATATYPE} pairs`); - - await wrapper.setProps({ collectionType: "list:list" }); - expect(wrapper.text()).toBe(`a list with 10 ${EXPECTED_HOMOGENEOUS_DATATYPE} lists`); - - await wrapper.setProps({ collectionType: "other" }); - expect(wrapper.text()).toBe(`a nested list with 10 ${EXPECTED_HOMOGENEOUS_DATATYPE} dataset collections`); - }); -}); diff --git a/client/src/components/History/Content/Collection/CollectionDescription.test.ts b/client/src/components/History/Content/Collection/CollectionDescription.test.ts new file mode 100644 index 000000000000..2dcacedd1c4a --- /dev/null +++ b/client/src/components/History/Content/Collection/CollectionDescription.test.ts @@ -0,0 +1,164 @@ +import { mount, type Wrapper } from "@vue/test-utils"; +import { getLocalVue } from "tests/jest/helpers"; +import type Vue from "vue"; + +import type { HDCASummary } from "@/api"; + +import CollectionDescription from "./CollectionDescription.vue"; + +const localVue = getLocalVue(); + +const defaultTestHDCA: HDCASummary = { + id: "test_id", + name: "Test Collection", + hid: 1, + collection_id: "test_collection_id", + type: "collection", + collection_type: "list", + history_content_type: "dataset_collection", + element_count: null, + create_time: null, + update_time: null, + deleted: false, + visible: true, + elements_datatypes: [], + history_id: "fake_history_id", + model_class: "HistoryDatasetCollectionAssociation", + populated_state: "ok", + tags: [], + url: "fake/url", + contents_url: "fake/contents/url", +}; + +describe("CollectionDescription", () => { + let wrapper: Wrapper; + + beforeEach(() => { + wrapper = mount(CollectionDescription as object, { + propsData: { + hdca: defaultTestHDCA, + }, + localVue, + }); + }); + + it("should display expected heterogeneous descriptions", async () => { + const HETEROGENEOUS_DATATYPES = ["txt", "csv", "tabular"]; + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + collection_type: "list", + element_count: 1, + elements_datatypes: HETEROGENEOUS_DATATYPES, + }, + }); + expect(wrapper.text()).toBe("a list with 1 dataset"); + + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + element_count: 2, + collection_type: "paired", + }, + }); + expect(wrapper.text()).toBe("a pair with 2 datasets"); + + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + element_count: 10, + collection_type: "list", + }, + }); + expect(wrapper.text()).toBe("a list with 10 datasets"); + + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + element_count: 10, + collection_type: "list:paired", + }, + }); + expect(wrapper.text()).toBe("a list with 10 pairs"); + + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + element_count: 10, + collection_type: "list:list", + }, + }); + expect(wrapper.text()).toBe("a list with 10 lists"); + + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + element_count: 10, + collection_type: "other", + }, + }); + expect(wrapper.text()).toBe("a nested list with 10 dataset collections"); + }); + + it("should display expected homogeneous descriptions", async () => { + const EXPECTED_HOMOGENEOUS_DATATYPE = "tabular"; + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + element_count: 1, + elements_datatypes: [EXPECTED_HOMOGENEOUS_DATATYPE], + }, + }); + expect(wrapper.text()).toBe(`a list with 1 ${EXPECTED_HOMOGENEOUS_DATATYPE} dataset`); + + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + element_count: 2, + collection_type: "paired", + elements_datatypes: [EXPECTED_HOMOGENEOUS_DATATYPE], + }, + }); + expect(wrapper.text()).toBe(`a pair with 2 ${EXPECTED_HOMOGENEOUS_DATATYPE} datasets`); + + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + element_count: 10, + collection_type: "list", + elements_datatypes: [EXPECTED_HOMOGENEOUS_DATATYPE], + }, + }); + expect(wrapper.text()).toBe(`a list with 10 ${EXPECTED_HOMOGENEOUS_DATATYPE} datasets`); + + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + element_count: 10, + collection_type: "list:paired", + elements_datatypes: [EXPECTED_HOMOGENEOUS_DATATYPE], + }, + }); + expect(wrapper.text()).toBe(`a list with 10 ${EXPECTED_HOMOGENEOUS_DATATYPE} pairs`); + + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + element_count: 10, + collection_type: "list:list", + elements_datatypes: [EXPECTED_HOMOGENEOUS_DATATYPE], + }, + }); + expect(wrapper.text()).toBe(`a list with 10 ${EXPECTED_HOMOGENEOUS_DATATYPE} lists`); + + await wrapper.setProps({ + hdca: { + ...defaultTestHDCA, + element_count: 10, + collection_type: "other", + elements_datatypes: [EXPECTED_HOMOGENEOUS_DATATYPE], + }, + }); + expect(wrapper.text()).toBe(`a nested list with 10 ${EXPECTED_HOMOGENEOUS_DATATYPE} dataset collections`); + }); +}); diff --git a/client/src/components/History/Content/Collection/CollectionDescription.vue b/client/src/components/History/Content/Collection/CollectionDescription.vue index 42096e4fe940..7cc6e0a40b00 100644 --- a/client/src/components/History/Content/Collection/CollectionDescription.vue +++ b/client/src/components/History/Content/Collection/CollectionDescription.vue @@ -1,21 +1,17 @@