Loading client/src/components/Visualizations/VisualizationCreate.test.js +25 −12 Original line number Diff line number Diff line Loading @@ -4,11 +4,20 @@ import { createPinia, defineStore, setActivePinia } from "pinia"; import { getLocalVue } from "tests/jest/helpers"; import { ref } from "vue"; import { fetchPluginHistoryItems } from "@/api/plugins"; import { fetchPlugin, fetchPluginHistoryItems } from "@/api/plugins"; import VisualizationCreate from "./VisualizationCreate.vue"; import FormCardSticky from "@/components/Form/FormCardSticky.vue"; const PLUGIN = { name: "scatterplot", description: "A great scatterplot plugin.", html: "Scatterplot Plugin", logo: "/logo.png", help: "Some help text", tags: ["tag1", "tag2"], }; jest.mock("vue-router/composables", () => ({ useRouter: () => ({ push: jest.fn(), Loading @@ -18,22 +27,13 @@ jest.mock("vue-router/composables", () => ({ jest.mock("@/api/plugins", () => ({ fetchPlugin: jest.fn(() => Promise.resolve({ name: "scatterplot", description: "A great scatterplot plugin.", html: "Scatterplot Plugin", logo: "/logo.png", help: "Some help text", tags: ["tag1", "tag2"], params: { dataset_id: { required: true } }, ...PLUGIN, }), ), fetchPluginHistoryItems: jest.fn(() => Promise.resolve({ hdas: [] })), })); jest.mock("./utilities", () => ({ getTestExtensions: jest.fn(() => ["txt"]), getTestUrls: jest.fn(() => [{ name: "Example", url: "https://example.com/data.txt" }]), })); let mockedStore; jest.mock("@/stores/historyStore", () => ({ useHistoryStore: () => mockedStore, Loading Loading @@ -95,3 +95,16 @@ it("adds hid to dataset names when fetching history items", async () => { { id: "dataset2", name: "102: Second Dataset" }, ]); }); it("displays create new visualization option if dataset is not required", async () => { fetchPlugin.mockResolvedValueOnce(PLUGIN); const wrapper = mount(VisualizationCreate, { localVue, propsData: { visualization: "scatterplot", }, }); await wrapper.vm.$nextTick(); const results = await wrapper.vm.doQuery(); expect(results).toEqual([{ id: "", name: "Create a new visualization..." }]); }); client/src/components/Visualizations/VisualizationCreate.vue +1 −1 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ defineExpose({ doQuery }); </template> <div class="my-3"> <SelectionField object-name="Select a dataset..." object-name="Make a selection..." object-title="Select to Visualize" object-type="history_dataset_id" :object-query="doQuery" Loading client/src/components/Visualizations/utilities.test.js +10 −2 Original line number Diff line number Diff line import { getFilename, getTestUrls } from "./utilities"; import { getFilename, getRequiresDataset, getTestUrls } from "./utilities"; describe("Utility Functions", () => { describe("getTestUrls", () => { describe("getRequiresDataset and getTestUrls", () => { it("return wether the visualization requires a dataset or not", () => { expect(getRequiresDataset({})).toEqual(false); const plugin = { params: { dataset_id: { required: true } }, }; expect(getRequiresDataset(plugin)).toEqual(true); }); it("returns empty array when plugin is undefined", () => { expect(getTestUrls()).toEqual([]); }); Loading Loading
client/src/components/Visualizations/VisualizationCreate.test.js +25 −12 Original line number Diff line number Diff line Loading @@ -4,11 +4,20 @@ import { createPinia, defineStore, setActivePinia } from "pinia"; import { getLocalVue } from "tests/jest/helpers"; import { ref } from "vue"; import { fetchPluginHistoryItems } from "@/api/plugins"; import { fetchPlugin, fetchPluginHistoryItems } from "@/api/plugins"; import VisualizationCreate from "./VisualizationCreate.vue"; import FormCardSticky from "@/components/Form/FormCardSticky.vue"; const PLUGIN = { name: "scatterplot", description: "A great scatterplot plugin.", html: "Scatterplot Plugin", logo: "/logo.png", help: "Some help text", tags: ["tag1", "tag2"], }; jest.mock("vue-router/composables", () => ({ useRouter: () => ({ push: jest.fn(), Loading @@ -18,22 +27,13 @@ jest.mock("vue-router/composables", () => ({ jest.mock("@/api/plugins", () => ({ fetchPlugin: jest.fn(() => Promise.resolve({ name: "scatterplot", description: "A great scatterplot plugin.", html: "Scatterplot Plugin", logo: "/logo.png", help: "Some help text", tags: ["tag1", "tag2"], params: { dataset_id: { required: true } }, ...PLUGIN, }), ), fetchPluginHistoryItems: jest.fn(() => Promise.resolve({ hdas: [] })), })); jest.mock("./utilities", () => ({ getTestExtensions: jest.fn(() => ["txt"]), getTestUrls: jest.fn(() => [{ name: "Example", url: "https://example.com/data.txt" }]), })); let mockedStore; jest.mock("@/stores/historyStore", () => ({ useHistoryStore: () => mockedStore, Loading Loading @@ -95,3 +95,16 @@ it("adds hid to dataset names when fetching history items", async () => { { id: "dataset2", name: "102: Second Dataset" }, ]); }); it("displays create new visualization option if dataset is not required", async () => { fetchPlugin.mockResolvedValueOnce(PLUGIN); const wrapper = mount(VisualizationCreate, { localVue, propsData: { visualization: "scatterplot", }, }); await wrapper.vm.$nextTick(); const results = await wrapper.vm.doQuery(); expect(results).toEqual([{ id: "", name: "Create a new visualization..." }]); });
client/src/components/Visualizations/VisualizationCreate.vue +1 −1 Original line number Diff line number Diff line Loading @@ -82,7 +82,7 @@ defineExpose({ doQuery }); </template> <div class="my-3"> <SelectionField object-name="Select a dataset..." object-name="Make a selection..." object-title="Select to Visualize" object-type="history_dataset_id" :object-query="doQuery" Loading
client/src/components/Visualizations/utilities.test.js +10 −2 Original line number Diff line number Diff line import { getFilename, getTestUrls } from "./utilities"; import { getFilename, getRequiresDataset, getTestUrls } from "./utilities"; describe("Utility Functions", () => { describe("getTestUrls", () => { describe("getRequiresDataset and getTestUrls", () => { it("return wether the visualization requires a dataset or not", () => { expect(getRequiresDataset({})).toEqual(false); const plugin = { params: { dataset_id: { required: true } }, }; expect(getRequiresDataset(plugin)).toEqual(true); }); it("returns empty array when plugin is undefined", () => { expect(getTestUrls()).toEqual([]); }); Loading