From 72fc76cb8bf0da811aef30677dad245ca40f0995 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:43:14 +0200 Subject: [PATCH] Refactor HistoryView test to use server mock and update imports --- .../components/History/HistoryView.test.js | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/client/src/components/History/HistoryView.test.js b/client/src/components/History/HistoryView.test.js index d0d371c80e36..85dc95106ede 100644 --- a/client/src/components/History/HistoryView.test.js +++ b/client/src/components/History/HistoryView.test.js @@ -1,20 +1,22 @@ import { getFakeRegisteredUser } from "@tests/test-data"; import { mount } from "@vue/test-utils"; -import axios from "axios"; -import MockAdapter from "axios-mock-adapter"; import flushPromises from "flush-promises"; import { createPinia } from "pinia"; -import { useHistoryStore } from "stores/historyStore"; -import { getHistoryByIdFromServer, setCurrentHistoryOnServer } from "stores/services/history.services"; -import { useUserStore } from "stores/userStore"; import { getLocalVue } from "tests/jest/helpers"; -import ContentItem from "./Content/ContentItem"; -import HistoryView from "./HistoryView"; +import { useServerMock } from "@/api/client/__mocks__"; +import { useHistoryStore } from "@/stores/historyStore"; +import { getHistoryByIdFromServer, setCurrentHistoryOnServer } from "@/stores/services/history.services"; +import { useUserStore } from "@/stores/userStore"; + +import ContentItem from "./Content/ContentItem.vue"; +import HistoryView from "./HistoryView.vue"; const localVue = getLocalVue(); jest.mock("stores/services/history.services"); +const { server, http } = useServerMock(); + function create_history(historyId, userId, purged = false, archived = false) { const historyName = `${userId}'s History ${historyId}`; return { @@ -61,10 +63,18 @@ async function createWrapper(localVue, currentUserId, history) { const pinia = createPinia(); getHistoryByIdFromServer.mockResolvedValue(history); setCurrentHistoryOnServer.mockResolvedValue(history); - const axiosMock = new MockAdapter(axios); - const history_contents_url = `/api/histories/${history.id}/contents?v=dev&order=hid&offset=0&limit=100&q=deleted&qv=false&q=visible&qv=true`; const history_contents_result = create_datasets(history.id, history.count); - axiosMock.onGet(history_contents_url).reply(200, history_contents_result); + + server.use( + http.get("/api/configuration", ({ response }) => { + return response(200).json({}); + }), + + http.get("/api/histories/{history_id}/contents", ({ response }) => { + return response(200).json(history_contents_result); + }) + ); + const wrapper = mount(HistoryView, { propsData: { id: history.id }, localVue,