Skip to content

Commit 2e8bca6

Browse files
committed
adding test cases for Registry/UtilComponents
1 parent 2caafb9 commit 2e8bca6

File tree

8 files changed

+204
-2
lines changed

8 files changed

+204
-2
lines changed

src/components/Registry/UtilComponents/AutoCompleteComponent.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
clearable
4141
closable-chips
4242
color="primary"
43+
data-testid="autocompleteComponent"
4344
density="compact"
4445
flat
4546
hide-details="auto"

src/components/Registry/UtilComponents/SelectComponent.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
clearable
3939
closable-chips
4040
color="primary"
41+
data-testid="comboboxComponent"
4142
density="compact"
4243
flat
4344
hide-details="auto"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { describe, expect, it } from "vitest";
2+
import { createVuetify } from "vuetify";
3+
4+
import { mount } from "@vue/test-utils";
5+
import AutoCompleteComponent from "../AutoCompleteComponent.vue";
6+
import { createPinia, setActivePinia } from "pinia";
7+
8+
const vuetify = createVuetify();
9+
10+
describe("AutoCompleteComponent.vue", function () {
11+
let wrapper;
12+
13+
beforeEach(() => {
14+
setActivePinia(createPinia());
15+
wrapper = mount(AutoCompleteComponent, {
16+
global: {
17+
plugins: [vuetify],
18+
data: () => {
19+
return {
20+
search: null,
21+
model: ["foo"],
22+
};
23+
},
24+
props: {
25+
itemList: ["foo"],
26+
itemValue: ["foo"],
27+
loading: false,
28+
toolTipText: "dummy",
29+
label: "label",
30+
disabled: false,
31+
},
32+
stubs: { vAutocomplete: true },
33+
},
34+
});
35+
});
36+
37+
it("can be instantiated", () => {
38+
//When search text is more than 3 words
39+
wrapper.vm.$options.watch.search.call(wrapper.vm, "test");
40+
//When search text is less than 3 words
41+
wrapper.vm.$options.watch.search.call(wrapper.vm, "te");
42+
wrapper.vm.$options.watch.model.call(wrapper.vm, ["xyz"]);
43+
expect(wrapper.vm.$options.name).toMatch("AutoCompleteComponent");
44+
});
45+
it("can check v-model", async () => {
46+
let itemListArr = ["foo"];
47+
const component = wrapper.findComponent(
48+
"[data-testid='autocompleteComponent']",
49+
);
50+
component.componentVM.search = "abc";
51+
await component.setValue(itemListArr);
52+
expect(wrapper.vm.model).toStrictEqual(itemListArr);
53+
});
54+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { describe, expect, it } from "vitest";
2+
import { createVuetify } from "vuetify";
3+
4+
import { mount } from "@vue/test-utils";
5+
import SelectComponent from "../SelectComponent.vue";
6+
import { createPinia, setActivePinia } from "pinia";
7+
8+
const vuetify = createVuetify();
9+
10+
describe("SelectComponent.vue", function () {
11+
let wrapper;
12+
13+
beforeEach(() => {
14+
setActivePinia(createPinia());
15+
wrapper = mount(SelectComponent, {
16+
global: {
17+
plugins: [vuetify],
18+
data: () => {
19+
return {
20+
model: ["foo"],
21+
};
22+
},
23+
props: {
24+
itemList: ["foo"],
25+
itemValue: ["foo"],
26+
loading: false,
27+
toolTipText: "dummy",
28+
label: "label",
29+
disabled: false,
30+
},
31+
stubs: { vCombobox: true },
32+
},
33+
});
34+
});
35+
36+
it("can be instantiated", () => {
37+
wrapper.vm.$options.watch.disabled.call(wrapper.vm, true);
38+
wrapper.vm.$options.watch.model.call(wrapper.vm, ["xyz"]);
39+
expect(wrapper.vm.$options.name).toMatch("SelectComponent");
40+
});
41+
it("can check v-model", async () => {
42+
let itemListArr = ["foo"];
43+
const component = wrapper.findComponent(
44+
"[data-testid='comboboxComponent']",
45+
);
46+
component.componentVM.search = "abc";
47+
await component.setValue(itemListArr);
48+
expect(wrapper.vm.model).toStrictEqual(itemListArr);
49+
});
50+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { describe, expect, it } from "vitest";
2+
import { createVuetify } from "vuetify";
3+
4+
import { mount } from "@vue/test-utils";
5+
import TableComponent from "../TableComponent.vue";
6+
import { createPinia, setActivePinia } from "pinia";
7+
8+
const vuetify = createVuetify();
9+
10+
describe("TableComponent.vue", function () {
11+
let wrapper;
12+
13+
beforeEach(() => {
14+
setActivePinia(createPinia());
15+
wrapper = mount(TableComponent, {
16+
global: {
17+
plugins: [vuetify],
18+
data() {
19+
return {
20+
fairsharingURL: import.meta.env.VITE_FAIRSHARING_URL,
21+
headers: [
22+
{
23+
title: "Name",
24+
value: "name",
25+
align: "center",
26+
key: "name",
27+
sortable: false,
28+
},
29+
{
30+
title: "Type",
31+
value: "type",
32+
align: "center",
33+
key: "type",
34+
sortable: false,
35+
},
36+
{
37+
title: "Status",
38+
value: "status",
39+
align: "center",
40+
key: "status",
41+
sortable: false,
42+
},
43+
],
44+
loading: false,
45+
};
46+
},
47+
props: {
48+
itemList: ["foo"],
49+
hideType: false,
50+
},
51+
stubs: { vDataTable: true },
52+
},
53+
});
54+
});
55+
56+
it("can be instantiated", () => {
57+
expect(wrapper.vm.$options.name).toMatch("TableComponent");
58+
});
59+
60+
it("can check headersList computed property", async () => {
61+
wrapper.setProps({ hideType: true });
62+
expect(wrapper.vm.headersList).toStrictEqual(wrapper.vm.headers);
63+
});
64+
});

src/components/Registry/__tests__/CollapseTreeGraph.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("CollapseTreeGraph.vue", function () {
2929
expect(wrapper.vm.$options.name).toMatch("CollapseTreeGraph");
3030
});
3131

32-
it("getGraphData method is called on v-select", async () => {
32+
it("getGraphData method is called on v-select when mounted", async () => {
3333
let itemList = [
3434
{
3535
id: 1,

src/lib/GraphClient/GraphClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class GraphQLClient {
7777
const regExp = /\(|\)|\{|\}/g;
7878

7979
const hasBrackets = regExp.test(query.queryParam[key]);
80-
80+
/* v8 ignore next */
8181
if (hasBrackets) queryString += `${key}:${query.queryParam[key]}`;
8282
else queryString += `${key}:"${query.queryParam[key]}" `;
8383
// queryString += `${key}:"${query.queryParam[key]}" `;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { describe, expect, it } from "vitest";
2+
import { createVuetify } from "vuetify";
3+
4+
import { shallowMount } from "@vue/test-utils";
5+
import ResultTableView from "../ResultTableView.vue";
6+
import { createPinia, setActivePinia } from "pinia";
7+
import { useAdvancedSearchStore } from "@/stores/advancedSearch.js";
8+
9+
const vuetify = createVuetify();
10+
11+
describe("RegistryView.vue", function () {
12+
let wrapper;
13+
14+
beforeEach(() => {
15+
setActivePinia(createPinia());
16+
wrapper = shallowMount(ResultTableView, {
17+
global: {
18+
plugins: [vuetify],
19+
},
20+
});
21+
});
22+
23+
it("can be instantiated", () => {
24+
expect(wrapper.vm.$options.name).toMatch("ResultTableView");
25+
});
26+
27+
it("can check noData computed property", () => {
28+
let store = useAdvancedSearchStore();
29+
store.noData = true;
30+
expect(wrapper.vm.noData).toBe("No data available");
31+
});
32+
});

0 commit comments

Comments
 (0)