This commit is contained in:
Laila Los
2022-11-02 15:48:01 +01:00
parent 0691c4a27c
commit 7818047620
@@ -2,12 +2,12 @@ import MockAdapter from "axios-mock-adapter";
import axios from "axios";
import UploadModal from "./UploadModal";
import UploadModalContent from "./UploadModalContent";
import store from "../../store";
import { mount } from "@vue/test-utils";
import { getLocalVue } from "jest/helpers";
import MockCurrentUser from "../providers/MockCurrentUser";
import MockCurrentHistory from "../providers/MockCurrentHistory";
import { getLocalVue, mockModule } from "jest/helpers";
import { userStore } from "store/userStore";
import { historyStore } from "store/historyStore";
import { configStore } from "store/configStore";
import Vuex from "vuex";
jest.mock("app");
@@ -17,6 +17,16 @@ const propsData = {
fileSourcesConfigured: true,
};
const createStore = () => {
return new Vuex.Store({
modules: {
user: mockModule(userStore, { currentUser: { id: "fakeuser" } }),
history: mockModule(historyStore, { currentHistoryId: "fakehistory", histories: { fakehistory: {} } }),
config: mockModule(configStore, { config: {} }),
},
});
};
describe("UploadModal.vue", () => {
let wrapper;
let axiosMock;
@@ -47,17 +57,14 @@ describe("UploadModal.vue", () => {
axiosMock.onGet(`/api/datatypes?extension_only=False`).reply(200, datatypesResponse);
const localVue = getLocalVue();
const store = createStore();
wrapper = await mount(UploadModal, {
store,
provide: { store },
propsData,
localVue,
stubs: {
// Need to stub all this horrible-ness because of the last 2 tests
// which need to dig into the first layer of the mount tree, will remove
// all of this shortly with a PR that completely replaces Upload
CurrentUser: MockCurrentUser({ id: "fakeuser" }),
UserHistories: MockCurrentHistory({ id: "fakehistory" }),
BTabs: true,
BTab: true,
Collection: true,
@@ -66,6 +73,8 @@ describe("UploadModal.vue", () => {
RulesInput: true,
},
});
await wrapper.vm.open();
});
afterEach(() => {
@@ -74,8 +83,9 @@ describe("UploadModal.vue", () => {
});
it("should load with correct defaults", async () => {
expect(wrapper.vm.auto.id).toBe("auto");
expect(wrapper.vm.datatypesDisableAuto).toBe(false);
const contentWrapper = wrapper.findComponent(UploadModalContent);
expect(contentWrapper.vm.auto.id).toBe("auto");
expect(contentWrapper.vm.datatypesDisableAuto).toBe(false);
});
it("should fetch datatypes and parse them", async () => {