-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathObjectSelector.nuxt.test.js
More file actions
118 lines (111 loc) · 3.92 KB
/
ObjectSelector.nuxt.test.js
File metadata and controls
118 lines (111 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { describe, expect, test, vi } from "vitest"
import { registerEndpoint, mountSuspended } from "@nuxt/test-utils/runtime"
import { flushPromises } from "@vue/test-utils"
import * as components from "vuetify/components"
import { setActivePinia } from "pinia"
import { createTestingPinia } from "@pinia/testing"
import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json"
import ObjectSelector from "@ogw_front/components/ObjectSelector"
import { useGeodeStore } from "@ogw_front/stores/geode"
import { vuetify } from "../../utils"
const allowed_objects = schemas.opengeodeweb_back.allowed_objects
describe("ObjectSelector", async () => {
const pinia = createTestingPinia({
stubActions: false,
createSpy: vi.fn,
})
setActivePinia(pinia)
const geodeStore = useGeodeStore()
geodeStore.base_url = ""
test(`test loadable with one class`, async () => {
var response = {
allowed_objects: {},
}
const geode_object_1 = "BRep"
response["allowed_objects"][geode_object_1] = { is_loadable: true }
registerEndpoint(allowed_objects.$id, {
method: allowed_objects.methods[0],
handler: () => response,
})
const wrapper = await mountSuspended(ObjectSelector, {
global: {
plugins: [vuetify, pinia],
},
props: { filenames: ["test.toto"] },
})
const v_card = wrapper.findComponent(components.VCard)
const v_img = v_card.findComponent(components.VImg)
expect(v_img.vm.src).toContain(`${geode_object_1}.svg`)
expect(wrapper.emitted()).toHaveProperty("update_values")
expect(wrapper.emitted().update_values).toHaveLength(1)
expect(wrapper.emitted().update_values[0][0]).toEqual({
geode_object_type: geode_object_1,
})
wrapper.unmount()
})
test(`test loabable with multiple classes`, async () => {
var response = {
allowed_objects: {},
}
const geode_object_1 = "BRep"
const geode_object_2 = "EdgedCurve3D"
response["allowed_objects"][geode_object_1] = { is_loadable: true }
response["allowed_objects"][geode_object_2] = { is_loadable: true }
registerEndpoint(allowed_objects.$id, {
method: allowed_objects.methods[0],
handler: () => response,
})
const wrapper = await mountSuspended(ObjectSelector, {
global: {
plugins: [vuetify, pinia],
},
props: { filenames: ["test.toto"] },
})
const v_card = wrapper.findComponent(components.VCard)
const v_img = v_card.findComponent(components.VImg)
expect(v_img.vm.src).toContain(`${geode_object_1}.svg`)
await flushPromises()
await v_card.trigger("click")
await flushPromises()
expect(wrapper.emitted()).toHaveProperty("update_values")
console.log(
"wrapper.emitted().update_values",
wrapper.emitted().update_values,
)
expect(wrapper.emitted().update_values).toHaveLength(1)
expect(wrapper.emitted().update_values[0][0]).toEqual({
geode_object_type: geode_object_1,
})
wrapper.unmount()
})
test(`test object_priority when is_loadable scores equal`, async () => {
var response = { allowed_objects: {} }
const geode_object_1 = "BRep"
const geode_object_2 = "EdgedCurve3D"
response["allowed_objects"][geode_object_1] = {
is_loadable: 1.0,
object_priority: 2,
}
response["allowed_objects"][geode_object_2] = {
is_loadable: 1.0,
object_priority: 1,
}
registerEndpoint(allowed_objects.$id, {
method: allowed_objects.methods[0],
handler: () => response,
})
const wrapper = await mountSuspended(ObjectSelector, {
global: {
plugins: [vuetify, pinia],
},
props: { filenames: ["test.toto"] },
})
await flushPromises()
expect(wrapper.emitted()).toHaveProperty("update_values")
expect(wrapper.emitted().update_values).toHaveLength(1)
expect(wrapper.emitted().update_values[0][0]).toEqual({
geode_object_type: geode_object_1,
})
wrapper.unmount()
})
})