Skip to content

Commit

Permalink
Update markdown galaxy test using history link component
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Mar 1, 2025
1 parent 7022f13 commit 3aed7b6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const onImport = async () => {
<template>
<div>
<b-link v-if="showLink" data-description="history import link" :data-history-id="historyId" @click="onImport">
Click to Import History: {{ name }}.
Click to Import History: {{ name }}
</b-link>
<div v-if="imported" class="text-success">
<FontAwesomeIcon icon="check" class="mr-1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const localVue = getLocalVue();
const { server, http } = useServerMock();

describe("Workflow License", () => {
async function mountTarget() {
function mountTarget() {
const pinia = createTestingPinia({ stubActions: false });
server.use(
http.get("/api/workflows/{workflow_id}", ({ response }) =>
Expand All @@ -36,7 +36,7 @@ describe("Workflow License", () => {
}

it("should render name and link", async () => {
const wrapper = await mountTarget();
const wrapper = mountTarget();
expect(wrapper.find("[title='loading']").exists()).toBeTruthy();
await flushPromises();
expect(wrapper.text()).toBe("MIT License");
Expand Down
48 changes: 35 additions & 13 deletions client/src/components/Markdown/Sections/MarkdownGalaxy.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { createTestingPinia } from "@pinia/testing";
import { mount } from "@vue/test-utils";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import flushPromises from "flush-promises";
import { getLocalVue } from "tests/jest/helpers";
import { withPrefix } from "utils/redirect";

import { useServerMock } from "@/api/client/__mocks__";

import MountTarget from "./MarkdownGalaxy.vue";

const { server, http } = useServerMock();

// mock routes
jest.mock("utils/redirect");
withPrefix.mockImplementation((url) => url);
Expand All @@ -23,13 +28,17 @@ jest.mock("@/composables/config", () => ({
const localVue = getLocalVue();
const axiosMock = new MockAdapter(axios);

async function mountComponent(propsData, apiMap = {}) {
function mapAxios(apiMap = {}) {
axiosMock.reset();
for (const [method, apiDetails] of Object.entries(apiMap)) {
for (const [path, response] of Object.entries(apiDetails)) {
axiosMock[method](path).reply(200, response);
}
}
}

async function mountComponent(propsData, apiMap = {}) {
mapAxios(apiMap);
return mount(MountTarget, {
localVue,
propsData,
Expand All @@ -39,6 +48,24 @@ async function mountComponent(propsData, apiMap = {}) {
});
}

function mountComponentWithServer(propsData = {}, apiMap = {}) {
mapAxios(apiMap);
const pinia = createTestingPinia({ stubActions: false });
server.use(
http.get("/api/histories/test_history_id", ({ response }) =>
response(200).json({ id: "test_history_id", name: "history_name" })
)
);
return mount(MountTarget, {
localVue,
pinia,
propsData,
stubs: {
FontAwesomeIcon: true,
},
});
}

describe("MarkdownContainer", () => {
it("Renders version", async () => {
const version = "test_version";
Expand Down Expand Up @@ -74,18 +101,18 @@ describe("MarkdownContainer", () => {
});

it("Renders history link", async () => {
const wrapper = await mountComponent(
const wrapper = mountComponentWithServer(
{
content: `history_link(history_id=test_history_id)`,
content: "history_link(history_id=test_history_id)",
},
{
onGet: { "/api/histories/test_history_id": { name: "history_name" } },
onPost: { "/api/histories": {} },
}
);
expect(wrapper.find("a").text()).toBe("Click to Import History: ...");
await flushPromises();
const link = wrapper.find("a");
expect(link.text()).toBe("Click to Import History: history_name.");
expect(link.text()).toBe("Click to Import History: history_name");
await link.trigger("click");
const postedData = JSON.parse(axiosMock.history.post[0].data);
expect(postedData.history_id).toBe("test_history_id");
Expand All @@ -96,14 +123,9 @@ describe("MarkdownContainer", () => {
});

it("Renders history link (with failing import error message)", async () => {
const wrapper = await mountComponent(
{
content: `history_link(history_id=test_history_id)`,
},
{
onGet: { "/api/histories/test_history_id": { name: "history_name" } },
}
);
const wrapper = mountComponentWithServer({
content: "history_link(history_id=test_history_id)",
});
await wrapper.find("a").trigger("click");
await flushPromises();
const error = wrapper.find(".text-danger");
Expand Down

0 comments on commit 3aed7b6

Please sign in to comment.