-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileUploader.nuxt.test.js
More file actions
70 lines (58 loc) · 2.16 KB
/
FileUploader.nuxt.test.js
File metadata and controls
70 lines (58 loc) · 2.16 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
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 FileUploader from "@ogw_front/components/FileUploader"
import { useGeodeStore } from "@ogw_front/stores/geode"
import { vuetify } from "../../utils"
const upload_file_schema = schemas.opengeodeweb_back.upload_file
describe("FileUploader", async () => {
const pinia = createTestingPinia({
stubActions: false,
createSpy: vi.fn,
})
setActivePinia(pinia)
const geodeStore = useGeodeStore()
geodeStore.base_url = ""
registerEndpoint(upload_file_schema.$id, {
method: upload_file_schema.methods[0],
handler: () => ({}),
})
registerEndpoint(upload_file_schema.$id, {
method: upload_file_schema.methods[1],
handler: () => ({}),
})
const files = [new File(["fake_file"], "fake_file.txt")]
describe(`Upload file`, async () => {
test(`prop auto_upload false`, async () => {
const wrapper = await mountSuspended(FileUploader, {
global: {
plugins: [vuetify, pinia],
},
props: { multiple: false, accept: "*.txt" },
})
const v_file_input = wrapper.findComponent(components.VFileInput)
await v_file_input.trigger("click")
await v_file_input.setValue(files)
await v_file_input.trigger("change")
const v_btn = wrapper.findComponent(components.VBtn)
await v_btn.trigger("click")
await flushPromises()
await flushPromises()
expect(wrapper.emitted().files_uploaded[0][0]).toEqual(files)
})
test(`prop auto_upload true`, async () => {
const wrapper = await mountSuspended(FileUploader, {
global: {
plugins: [vuetify, pinia],
},
props: { multiple: false, accept: "*.txt", files, auto_upload: true },
})
await flushPromises()
expect(wrapper.emitted().files_uploaded[0][0]).toEqual(files)
})
})
})