Skip to content

Commit 9e7e66e

Browse files
Merge pull request #158 from Geode-solutions/next
Next
2 parents 7d15e81 + 5d456d5 commit 9e7e66e

File tree

4 files changed

+97
-44
lines changed

4 files changed

+97
-44
lines changed

components/FileSelector.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<FetchingData v-if="loading" />
33
<FileUploader
44
v-else
5-
v-bind="{ multiple, accept, files }"
5+
v-bind="{ multiple, accept, files, auto_upload }"
66
@files_uploaded="files_uploaded_event"
77
/>
88
</template>
@@ -21,18 +21,18 @@
2121
multiple: { type: Boolean, required: true },
2222
supported_feature: { type: String, required: false, default: null },
2323
files: { type: Array, required: false, default: [] },
24+
auto_upload: { type: Boolean, required: false, default: true },
2425
})
2526
26-
const { multiple, supported_feature } = props
27-
27+
const { auto_upload, multiple, supported_feature } = props
2828
const accept = ref("")
2929
const loading = ref(false)
3030
3131
const toggle_loading = useToggle(loading)
3232
3333
function files_uploaded_event(value) {
3434
if (value.length) {
35-
emit("update_values", { files: value })
35+
emit("update_values", { files: value, auto_upload: false })
3636
emit("increment_step")
3737
}
3838
}

components/FileUploader.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
multiple: { type: Boolean, required: true },
4141
accept: { type: String, required: true },
4242
files: { type: Array, required: false, default: [] },
43+
auto_upload: { type: Boolean, required: false, default: false },
4344
})
4445
4546
const { multiple, accept } = toRefs(props)
@@ -83,7 +84,9 @@
8384
8485
if (props.files.length) {
8586
files.value = props.files
86-
upload_files()
87+
if (props.auto_upload) {
88+
upload_files()
89+
}
8790
}
8891
8992
function clear() {

test/components/FileSelector.nuxt.test.js

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @vitest-environment nuxt
22

3-
import { describe, expect, test } from "vitest"
3+
import { describe, expect, test, vi } from "vitest"
44
import { registerEndpoint, mountSuspended } from "@nuxt/test-utils/runtime"
55
import { flushPromises } from "@vue/test-utils"
66

@@ -54,6 +54,7 @@ describe("FileSelector.vue", async () => {
5454
const v_file_input = file_uploader.findComponent(components.VFileInput)
5555
await v_file_input.trigger("click")
5656
const files = [new File(["fake_file"], "fake_file.txt")]
57+
const auto_upload = false
5758
await v_file_input.setValue(files)
5859
await v_file_input.trigger("change")
5960
const v_btn = wrapper.findComponent(components.VBtn)
@@ -63,36 +64,69 @@ describe("FileSelector.vue", async () => {
6364
expect(wrapper.emitted().update_values).toHaveLength(1)
6465
expect(wrapper.emitted().update_values[0][0]).toEqual({
6566
files,
67+
auto_upload,
6668
})
6769
})
6870

69-
test(`Files prop`, async () => {
71+
describe(`Files prop`, () => {
7072
registerEndpoint(allowed_files_schema.$id, {
7173
method: allowed_files_schema.methods[0],
7274
handler: () => ({
7375
extensions: ["1", "2", "3"],
7476
}),
7577
})
7678

77-
const files = [new File(["fake_file"], "fake_file.txt")]
78-
79-
const wrapper = await mountSuspended(FileSelector, {
80-
global: {
81-
plugins: [vuetify, pinia],
82-
},
83-
props: { multiple: false, supported_feature: "test", files: files },
84-
})
8579
registerEndpoint(upload_file_schema.$id, {
8680
method: upload_file_schema.methods[1],
8781
handler: () => ({}),
8882
})
8983

90-
await flushPromises()
84+
const files = [new File(["fake_file"], "fake_file.txt")]
85+
test("auto_upload true", async () => {
86+
const auto_upload = true
87+
const wrapper = await mountSuspended(FileSelector, {
88+
global: {
89+
plugins: [vuetify, pinia],
90+
},
91+
props: {
92+
multiple: false,
93+
supported_feature: "test",
94+
files: files,
95+
auto_upload,
96+
},
97+
})
98+
99+
await flushPromises()
100+
expect(wrapper.componentVM.files).toEqual(files)
101+
expect(wrapper.emitted()).toHaveProperty("update_values")
102+
expect(wrapper.emitted().update_values).toHaveLength(1)
103+
expect(wrapper.emitted().update_values[0][0]).toEqual({
104+
files,
105+
auto_upload: false,
106+
})
107+
})
91108

92-
expect(wrapper.emitted()).toHaveProperty("update_values")
93-
expect(wrapper.emitted().update_values).toHaveLength(1)
94-
expect(wrapper.emitted().update_values[0][0]).toEqual({
95-
files,
109+
test("auto_upload false", async () => {
110+
const auto_upload = false
111+
const wrapper = await mountSuspended(FileSelector, {
112+
global: {
113+
plugins: [vuetify, pinia],
114+
},
115+
props: {
116+
multiple: false,
117+
supported_feature: "test",
118+
files: files,
119+
auto_upload,
120+
},
121+
})
122+
123+
await flushPromises()
124+
125+
const file_uploader = wrapper.findComponent(FileUploader)
126+
console.log("wrapper", wrapper)
127+
expect(wrapper.vm.files).toEqual(files)
128+
const upload_files = vi.spyOn(file_uploader.vm, "upload_files")
129+
expect(upload_files).not.toHaveBeenCalled()
96130
})
97131
})
98132
})

test/components/FileUploader.nuxt.test.js

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,47 @@ describe("FileUploader.vue", async () => {
2727
const geode_store = use_geode_store()
2828
geode_store.base_url = ""
2929

30-
test(`Upload file`, async () => {
31-
registerEndpoint(upload_file_schema.$id, {
32-
method: upload_file_schema.methods[0],
33-
handler: () => ({}),
34-
})
35-
const wrapper = await mountSuspended(FileUploader, {
36-
global: {
37-
plugins: [vuetify, pinia],
38-
},
39-
props: { multiple: false, accept: "*.txt" },
40-
})
41-
const v_file_input = wrapper.findComponent(components.VFileInput)
42-
await v_file_input.trigger("click")
43-
const files = [new File(["fake_file"], "fake_file.txt")]
44-
await v_file_input.setValue(files)
45-
await v_file_input.trigger("change")
46-
const v_btn = wrapper.findComponent(components.VBtn)
47-
48-
registerEndpoint(upload_file_schema.$id, {
49-
method: upload_file_schema.methods[1],
50-
handler: () => ({}),
30+
registerEndpoint(upload_file_schema.$id, {
31+
method: upload_file_schema.methods[0],
32+
handler: () => ({}),
33+
})
34+
registerEndpoint(upload_file_schema.$id, {
35+
method: upload_file_schema.methods[1],
36+
handler: () => ({}),
37+
})
38+
39+
const files = [new File(["fake_file"], "fake_file.txt")]
40+
41+
describe(`Upload file`, async () => {
42+
test(`prop auto_upload false`, async () => {
43+
const wrapper = await mountSuspended(FileUploader, {
44+
global: {
45+
plugins: [vuetify, pinia],
46+
},
47+
props: { multiple: false, accept: "*.txt" },
48+
})
49+
50+
const v_file_input = wrapper.findComponent(components.VFileInput)
51+
await v_file_input.trigger("click")
52+
53+
await v_file_input.setValue(files)
54+
await v_file_input.trigger("change")
55+
const v_btn = wrapper.findComponent(components.VBtn)
56+
57+
await v_btn.trigger("click")
58+
await flushPromises()
59+
expect(wrapper.emitted().files_uploaded[0][0]).toEqual(files)
5160
})
5261

53-
await v_btn.trigger("click")
54-
await flushPromises()
55-
expect(wrapper.emitted().files_uploaded[0][0]).toEqual(files)
62+
test(`prop auto_upload true`, async () => {
63+
const wrapper = await mountSuspended(FileUploader, {
64+
global: {
65+
plugins: [vuetify, pinia],
66+
},
67+
props: { multiple: false, accept: "*.txt", files, auto_upload: true },
68+
})
69+
await flushPromises()
70+
expect(wrapper.emitted().files_uploaded[0][0]).toEqual(files)
71+
})
5672
})
5773
})

0 commit comments

Comments
 (0)