fix jest unit test

This commit is contained in:
Oleg Zharkov
2021-10-11 20:45:53 +02:00
parent 48a9278063
commit d8fed97115
2 changed files with 33 additions and 6 deletions
@@ -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
@@ -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);