Skip to content

Commit

Permalink
fix jests for workflow header and job metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Nov 13, 2024
1 parent 377c5cf commit aca94f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
5 changes: 4 additions & 1 deletion client/src/components/JobMetrics/JobMetrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { getLocalVue } from "tests/jest/helpers";

import JobMetrics from "./JobMetrics";

const NO_METRICS_MESSAGE = "No metrics available for this job.";

// Ignore all axios calls, data is mocked locally -- just say "OKAY!"
jest.mock("axios", () => ({
get: async () => {
Expand All @@ -26,7 +28,8 @@ describe("JobMetrics/JobMetrics.vue", () => {
});

await wrapper.vm.$nextTick();
expect(wrapper.find("div").exists()).toBe(false);
const alert = wrapper.find(".alert-info");
expect(alert.text()).toBe(NO_METRICS_MESSAGE);
});

it("should group plugins by type", async () => {
Expand Down
36 changes: 9 additions & 27 deletions client/src/components/Workflow/WorkflowRunButton.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { mount } from "@vue/test-utils";
import flushPromises from "flush-promises";
import { getLocalVue } from "tests/jest/helpers";

import { generateRandomString } from "./testUtils";
Expand All @@ -9,42 +8,25 @@ import WorkflowRunButton from "./WorkflowRunButton.vue";
const localVue = getLocalVue();

const WORKFLOW_ID = generateRandomString();
const WORKFLOW_VERSION = 1;
const WORKFLOW_RUN_BUTTON_SELECTOR = `[data-workflow-run="${WORKFLOW_ID}"]`;

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

async function mountWorkflowRunButton(props?: { id: string; version: number; full?: boolean }) {
const wrapper = mount(WorkflowRunButton as object, {
propsData: { ...props },
localVue,
mocks: {
$router: mockRouter,
},
});

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

describe("WorkflowRunButton.vue", () => {
it("should render button with icon", async () => {
const { wrapper } = await mountWorkflowRunButton({ id: WORKFLOW_ID });

expect(wrapper.find(WORKFLOW_RUN_BUTTON_SELECTOR).exists()).toBeTruthy();
expect(wrapper.find(WORKFLOW_RUN_BUTTON_SELECTOR).attributes("title")).toBe("Run workflow");
expect(wrapper.find(WORKFLOW_RUN_BUTTON_SELECTOR).text()).toBe("");
});

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

const runButton = wrapper.find(WORKFLOW_RUN_BUTTON_SELECTOR);

await runButton.trigger("click");
await flushPromises();
it("should render button with icon and route", async () => {
const { wrapper } = await mountWorkflowRunButton({ id: WORKFLOW_ID, version: WORKFLOW_VERSION });

expect(mockRouter.push).toHaveBeenCalledTimes(1);
expect(mockRouter.push).toHaveBeenCalledWith(`/workflows/run?id=${WORKFLOW_ID}`);
const button = wrapper.find(WORKFLOW_RUN_BUTTON_SELECTOR);
expect(button.attributes("title")).toBe("Run workflow");
expect(button.text()).toBe("");
expect(button.attributes("href")).toBe(`/workflows/run?id=${WORKFLOW_ID}&version=${WORKFLOW_VERSION}`);
});
});

0 comments on commit aca94f4

Please sign in to comment.