From d8fed9711555de903fbd8fdafa25ac4786599c58 Mon Sep 17 00:00:00 2001 From: Oleg Zharkov Date: Mon, 11 Oct 2021 20:44:07 +0200 Subject: [PATCH] fix jest unit test --- .../FilesDialog/FilesDialog.test.js | 29 +++++++++++++++++-- .../components/FilesDialog/FilesDialog.vue | 10 ++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/client/src/components/FilesDialog/FilesDialog.test.js b/client/src/components/FilesDialog/FilesDialog.test.js index b289e3af0fe..cbcb8073710 100644 --- a/client/src/components/FilesDialog/FilesDialog.test.js +++ b/client/src/components/FilesDialog/FilesDialog.test.js @@ -1,10 +1,15 @@ import FilesDialog from "./FilesDialog"; import SelectionDialog from "components/SelectionDialog/SelectionDialog"; import DataDialogTable from "components/SelectionDialog/DataDialogTable"; -import { shallowMount } from "@vue/test-utils"; +import { shallowMount, createLocalVue } from "@vue/test-utils"; import flushPromises from "flush-promises"; +import { BButton } from "bootstrap-vue"; import MockAdapter from "axios-mock-adapter"; +import Vue from "vue"; import axios from "axios"; +import BootstrapVue from "bootstrap-vue"; +import SelectionDialogMixin from "components/SelectionDialog/SelectionDialogMixin"; + import { rootId, directoryId, @@ -31,8 +36,13 @@ const api_paths_map = new Map([ ]); const initComponent = async (props) => { const axiosMock = new MockAdapter(axios); + const localVue = createLocalVue(); + + localVue.use(BootstrapVue); + localVue.component("BBtnStub", BButton); const wrapper = shallowMount(FilesDialog, { + localVue, propsData: props, }); @@ -209,9 +219,24 @@ describe("FilesDialog, directory mode", () => { }); it("should select folders", async () => { + // console.log(wrapper.html()); + const btn = wrapper.find("#ok-btn"); + + expect(btn.attributes().disabled).toBe("disabled"); + // const okBtn = buttons.find((btn) => btn.getAttribute("id") === "ok-btn"); await utils.open_root_folder(false); const folder = utils.getRenderedDirectory(directoryId); - await utils.getTable().$emit("clicked", folder); + await utils.getTable().$emit("open", folder); + await flushPromises(); + + const currentDirectory = wrapper.vm.currentDirectory; + expect(currentDirectory.id).toBe(folder.id); + + // make sure that disabled attribute is absent + expect(btn.attributes().disabled).toBe(undefined); + wrapper.vm.selectLeaf(currentDirectory); + await flushPromises(); + // finalize function should be called expect(spyFinalize).toHaveBeenCalled(); //should close modal diff --git a/client/src/components/FilesDialog/FilesDialog.vue b/client/src/components/FilesDialog/FilesDialog.vue index d5a03406597..fe027459de4 100644 --- a/client/src/components/FilesDialog/FilesDialog.vue +++ b/client/src/components/FilesDialog/FilesDialog.vue @@ -34,7 +34,8 @@ size="sm" class="float-right ml-1 file-dialog-modal-ok" variant="primary" - @click="fileMode ? finalize : selectDirectory(currentDirectory)" + id="ok-btn" + @click="fileMode ? finalize : selectLeaf(currentDirectory)" :disabled="(fileMode && !hasValue) || isBusy || (!fileMode && urlTracker.atRoot())" > {{ fileMode ? "Ok" : "Select this folder" }} @@ -55,6 +56,7 @@ import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; import { library } from "@fortawesome/fontawesome-svg-core"; import { faCaretLeft } from "@fortawesome/free-solid-svg-icons"; + library.add(faCaretLeft); export default { mixins: [SelectionDialogMixin], @@ -141,7 +143,7 @@ export default { } if (record.isLeaf) { // record is file - this.selectFile(record); + this.selectLeaf(record); } else { // record is directory // you cannot select entire root directory @@ -173,7 +175,7 @@ export default { this.model.unselectUnderPath(path); } }, - selectFile(file, selectOnly = false) { + selectLeaf(file, selectOnly = false) { const selected = this.model.exists(file.id); if (selected) { this.unselectPath(file.url, true); @@ -208,7 +210,7 @@ export default { const sub_record = this.parseItemFileMode(item); if (sub_record.isLeaf) { // select file under this path - this.selectFile(sub_record, true); + this.selectLeaf(sub_record, true); } else { // select subdirectory this.selectedDirectories.push(sub_record);