Skip to content

Commit ffc13c6

Browse files
Merge pull request #152 from Geode-solutions/fix/auto_upload
fix(FileUploader): prop file doesn't auto upload
2 parents a8c336b + 3ec291e commit ffc13c6

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
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: 2 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)
@@ -81,7 +82,7 @@
8182
toggle_loading()
8283
}
8384
84-
if (props.files.length) {
85+
if (props.files.length && props.auto_upload) {
8586
files.value = props.files
8687
upload_files()
8788
}

test/components/FileSelector.nuxt.test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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,6 +64,7 @@ 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

@@ -88,11 +90,6 @@ describe("FileSelector.vue", async () => {
8890
})
8991

9092
await flushPromises()
91-
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,
96-
})
93+
expect(wrapper.componentVM.files).toEqual(files)
9794
})
9895
})

0 commit comments

Comments
 (0)