Skip to content

Commit e87abff

Browse files
Merge pull request #132 from Geode-solutions/drag&drop
Drag&drop
2 parents 926e4c3 + 1183c4a commit e87abff

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

components/FileSelector.vue

Lines changed: 2 additions & 2 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 }"
5+
v-bind="{ multiple, accept, files }"
66
@files_uploaded="files_uploaded_event"
77
/>
88
</template>
@@ -20,6 +20,7 @@
2020
const props = defineProps({
2121
multiple: { type: Boolean, required: true },
2222
supported_feature: { type: String, required: false, default: null },
23+
files: { type: Array, required: false, default: [] },
2324
})
2425
2526
const { multiple, supported_feature } = props
@@ -51,6 +52,5 @@
5152
)
5253
toggle_loading()
5354
}
54-
5555
await get_allowed_files()
5656
</script>

components/FileUploader.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
const props = defineProps({
4040
multiple: { type: Boolean, required: true },
4141
accept: { type: String, required: true },
42+
files: { type: Array, required: false, default: [] },
4243
})
44+
4345
const { multiple, accept } = toRefs(props)
4446
4547
const label = multiple ? "Please select file(s)" : "Please select a file"
@@ -77,6 +79,11 @@
7779
toggle_loading()
7880
}
7981
82+
if (props.files.length) {
83+
files.value = props.files
84+
upload_files()
85+
}
86+
8087
function clear() {
8188
files.value = []
8289
emit("files_uploaded", files.value)

test/components/FileSelector.nuxt.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,34 @@ describe("FileSelector.vue", async () => {
5757
files,
5858
})
5959
})
60+
61+
test(`Files prop`, async () => {
62+
registerEndpoint(allowed_files_schema.$id, {
63+
method: allowed_files_schema.methods[0],
64+
handler: () => ({
65+
extensions: ["1", "2", "3"],
66+
}),
67+
})
68+
69+
const files = [new File(["fake_file"], "fake_file.txt")]
70+
71+
const wrapper = await mountSuspended(FileSelector, {
72+
global: {
73+
plugins: [vuetify],
74+
},
75+
props: { multiple: false, supported_feature: "test", files: files },
76+
})
77+
registerEndpoint(upload_file_schema.$id, {
78+
method: upload_file_schema.methods[1],
79+
handler: () => ({}),
80+
})
81+
82+
await flushPromises()
83+
84+
expect(wrapper.emitted()).toHaveProperty("update_values")
85+
expect(wrapper.emitted().update_values).toHaveLength(1)
86+
expect(wrapper.emitted().update_values[0][0]).toEqual({
87+
files,
88+
})
89+
})
6090
})

0 commit comments

Comments
 (0)