Skip to content

Commit

Permalink
adjust WorkflowRunButton jest for router push
Browse files Browse the repository at this point in the history
The `BButton :to`, was replaced with a `BButton @click` because the styling in `WorkflowNavigationTitle` worked better with a non `<a>` BButton (using `:to` turns the `<button>` into an `<a>`)
  • Loading branch information
ahmedhamidawan authored and hujambo-dunia committed Nov 5, 2024
1 parent 78d4898 commit fa118ba
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions client/src/components/Workflow/WorkflowRunButton.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mount } from "@vue/test-utils";
import flushPromises from "flush-promises";
import { getLocalVue } from "tests/jest/helpers";

import { generateRandomString } from "./testUtils";
Expand All @@ -11,12 +12,19 @@ const WORKFLOW_ID = generateRandomString();
const WORKFLOW_RUN_BUTTON_SELECTOR = `[data-workflow-run="${WORKFLOW_ID}"]`;

async function mountWorkflowRunButton(props?: { id: string; full?: boolean }) {
const mockRouter = {
push: jest.fn(),
};

const wrapper = mount(WorkflowRunButton as object, {
propsData: { ...props },
localVue,
mocks: {
$router: mockRouter,
},
});

return { wrapper };
return { wrapper, mockRouter };
}

describe("WorkflowRunButton.vue", () => {
Expand All @@ -29,10 +37,14 @@ describe("WorkflowRunButton.vue", () => {
});

it("should redirect to workflow run page", async () => {
const { wrapper } = await mountWorkflowRunButton({ id: WORKFLOW_ID });
const { wrapper, mockRouter } = await mountWorkflowRunButton({ id: WORKFLOW_ID });

const runButton = wrapper.find(WORKFLOW_RUN_BUTTON_SELECTOR);

const runButton = await wrapper.find(WORKFLOW_RUN_BUTTON_SELECTOR);
await runButton.trigger("click");
await flushPromises();

expect(runButton.attributes("href")).toBe(`/workflows/run?id=${WORKFLOW_ID}`);
expect(mockRouter.push).toHaveBeenCalledTimes(1);
expect(mockRouter.push).toHaveBeenCalledWith(`/workflows/run?id=${WORKFLOW_ID}`);
});
});

0 comments on commit fa118ba

Please sign in to comment.