Skip to content

Commit

Permalink
Add core component basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Nov 8, 2024
1 parent 78ad05c commit 57ee1ab
Showing 3 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/App.test.js
Original file line number Diff line number Diff line change
@@ -19,6 +19,6 @@ describe("build user interface", () => {
const wrapper = mount(App, { props: { incoming: incoming } });
expect(wrapper.html()).toContain("Please wait...");
await wrapper.vm.$nextTick();
expect(wrapper.html()).toContain('fill="#E30A17"');
expect(wrapper.html()).not.toContain('fill="#E30A17"');
});
});
62 changes: 62 additions & 0 deletions src/components/GalaxyCharts.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { describe, test, expect, mount } from "vitest";
import { mount } from "@vue/test-utils";

import Target from "./GalaxyCharts.vue";

function mountTarget(incoming) {
return mount(Target, {
props: { incoming: incoming },
slots: {
default: `<template #default="{ datasetId, datasetUrl, root, settings, specs, tracks }">
<pre>{{ datasetId }}</pre>
<pre>{{ datasetUrl }}</pre>
<pre>{{ root }}</pre>
<pre>{{ settings }}</pre>
<pre>{{ specs }}</pre>
<pre>{{ tracks }}</pre>
</template>`,
},
});
}

describe("build user interface", () => {
test("Show error if dataset id and url are missing", async () => {
const wrapper = mount(Target);
expect(wrapper.html()).toContain("Visualization requires `dataset_id` or `dataset_url`.");
});

test("Load user interface only dataset id", async () => {
const incoming = {
visualization_config: { dataset_id: "MY_DATASET_ID" },
};
const wrapper = mountTarget(incoming);
expect(wrapper.html()).toContain("Please wait...");
await wrapper.vm.$nextTick();
const elements = wrapper.findAll("pre");
const values = ["MY_DATASET_ID", "/api/datasets/MY_DATASET_ID/display", "/", "{}", "{}", "[]"];
values.forEach((x, index) => expect(elements[index].text()).toEqual(x));
expect(wrapper.html()).not.toContain('fill="#E30A17"');
});

test("Load user interface", async () => {
const incoming = {
root: "ROOT",
visualization_config: {
dataset_id: "MY_DATASET_ID",
dataset_url: "MY_DATASET_URL",
settings: "SETTINGS",
tracks: "TRACKS",
},
visualization_plugin: {
specs: "SPECS",
},
};
const wrapper = mountTarget(incoming);
expect(wrapper.html()).toContain("Please wait...");
await wrapper.vm.$nextTick();
const elements = wrapper.findAll("pre");
const values = ["MY_DATASET_ID", "MY_DATASET_URL", "ROOT", "SETTINGS", "SPECS", "TRACKS"];
values.forEach((x, index) => expect(elements[index].text()).toEqual(x));
expect(wrapper.html()).not.toContain('fill="#E30A17"');
});
});
2 changes: 1 addition & 1 deletion src/components/GalaxyCharts.vue
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ function updateTracks(newTracks: Array<InputValuesType>): void {
</n-float-button>
</div>
<SidePanel
v-else
v-else-if="!hidePanel"
:dataset-id="datasetId"
:description="description"
:html="html"

0 comments on commit 57ee1ab

Please sign in to comment.