mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-28 02:58:18 +08:00
Refactor UploadModal.test.js to use server mock
This commit is contained in:
@@ -1,19 +1,14 @@
|
||||
import { mount } from "@vue/test-utils";
|
||||
import axios from "axios";
|
||||
import MockAdapter from "axios-mock-adapter";
|
||||
import { createPinia } from "pinia";
|
||||
import { useHistoryStore } from "stores/historyStore";
|
||||
import { useUserStore } from "stores/userStore";
|
||||
import { getLocalVue } from "tests/jest/helpers";
|
||||
|
||||
import { mockFetcher } from "@/api/schema/__mocks__";
|
||||
import { useServerMock } from "@/api/client/__mocks__";
|
||||
import { useHistoryStore } from "@/stores/historyStore";
|
||||
import { useUserStore } from "@/stores/userStore";
|
||||
|
||||
import UploadContainer from "./UploadContainer.vue";
|
||||
import UploadModal from "./UploadModal.vue";
|
||||
|
||||
jest.mock("app");
|
||||
jest.mock("@/api/schema");
|
||||
|
||||
jest.mock("@/composables/config", () => ({
|
||||
useConfig: jest.fn(() => ({
|
||||
config: {},
|
||||
@@ -21,6 +16,8 @@ jest.mock("@/composables/config", () => ({
|
||||
})),
|
||||
}));
|
||||
|
||||
const { server, http } = useServerMock();
|
||||
|
||||
const fastaResponse = {
|
||||
description_url: "https://wiki.galaxyproject.org/Learn/Datatypes#Fasta",
|
||||
display_in_upload: true,
|
||||
@@ -42,19 +39,23 @@ const propsData = {
|
||||
|
||||
describe("UploadModal.vue", () => {
|
||||
let wrapper;
|
||||
let axiosMock;
|
||||
let userStore;
|
||||
let historyStore;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockFetcher
|
||||
.path("/api/datatypes")
|
||||
.method("get")
|
||||
.mock({ data: [fastaResponse] });
|
||||
mockFetcher.path("/api/genomes").method("get").mock({ data: genomesResponse });
|
||||
server.use(
|
||||
http.get("/api/datatypes", ({ response }) => {
|
||||
return response(200).json([fastaResponse]);
|
||||
}),
|
||||
|
||||
axiosMock = new MockAdapter(axios);
|
||||
axiosMock.onGet(`/api/histories/count`).reply(200, 0);
|
||||
http.get("/api/genomes", ({ response }) => {
|
||||
return response(200).json(genomesResponse);
|
||||
}),
|
||||
|
||||
http.get("/api/histories/count", ({ response }) => {
|
||||
return response(200).json(0);
|
||||
})
|
||||
);
|
||||
|
||||
const localVue = getLocalVue();
|
||||
const pinia = createPinia();
|
||||
@@ -82,11 +83,6 @@ describe("UploadModal.vue", () => {
|
||||
await wrapper.vm.open();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
axiosMock.restore();
|
||||
axiosMock.reset();
|
||||
});
|
||||
|
||||
it("should load with correct defaults", async () => {
|
||||
const contentWrapper = wrapper.findComponent(UploadContainer);
|
||||
expect(contentWrapper.vm.auto.id).toBe("auto");
|
||||
|
||||
Reference in New Issue
Block a user