Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-6171 - Vue3 upgrade: fix src/components/feature-board-external-tool-element tests #3033

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import {
import { ExternalToolDisplayData } from "@/store/external-tool";
import { ContextExternalTool } from "@/store/external-tool/context-external-tool";
import { BusinessError } from "@/store/types/commons";
import { I18N_KEY } from "@/utils/inject";
import {
ContextExternalToolConfigurationStatusFactory,
contextExternalToolFactory,
externalToolDisplayDataFactory,
i18nMock,
schoolToolConfigurationStatusFactory,
timestampsResponseFactory,
} from "@@/tests/test-utils";
import createComponentMocks from "@@/tests/test-utils/componentMocks";
import {
createTestingI18n,
createTestingVuetify,
} from "@@/tests/test-utils/setup";
import { useBoardFocusHandler, useContentElementState } from "@data-board";
import {
useContextExternalToolConfigurationStatus,
Expand All @@ -24,9 +25,11 @@ import {
import { createMock, DeepMocked } from "@golevelup/ts-jest";
import { mdiPuzzleOutline } from "@mdi/js";
import { useSharedLastCreatedElement } from "@util-board";
import { MountOptions, shallowMount, Wrapper } from "@vue/test-utils";
import Vue, { ref } from "vue";
import { shallowMount } from "@vue/test-utils";
import { nextTick, ref } from "vue";
import ExternalToolElement from "./ExternalToolElement.vue";
import ExternalToolElementConfigurationDialog from "./ExternalToolElementConfigurationDialog.vue";
import ExternalToolElementAlert from "./ExternalToolElementAlert.vue";

jest.mock("@data-board");
jest.mock("@data-external-tool");
Expand Down Expand Up @@ -101,37 +104,29 @@ describe("ExternalToolElement", () => {
});

const getWrapper = (
props: {
propsData: {
element: ExternalToolElementResponse;
isEditMode: boolean;
},
displayData?: ExternalToolDisplayData
) => {
document.body.setAttribute("data-app", "true");

useContentElementStateMock.modelValue = ref(props.element.content);
useContentElementStateMock.modelValue = ref(propsData.element.content);
useExternalToolElementDisplayStateMock.displayData = ref(displayData);
useExternalToolElementDisplayStateMock.error = ref(undefined);
useSharedLastCreatedElementMock.lastCreatedElementId = ref(undefined);

const wrapper: Wrapper<Vue> = shallowMount(
ExternalToolElement as MountOptions<Vue>,
{
...createComponentMocks({
i18n: true,
}),
propsData: {
isFirstElement: false,
isLastElement: false,
hasMultipleElements: false,
cardId: "cardId",
...props,
},
provide: {
[I18N_KEY.valueOf()]: i18nMock,
},
}
);
const wrapper = shallowMount(ExternalToolElement, {
global: {
plugins: [createTestingVuetify(), createTestingI18n()],
},
props: {
isFirstElement: false,
isLastElement: false,
hasMultipleElements: false,
cardId: "cardId",
...propsData,
},
});

return {
wrapper,
Expand All @@ -158,7 +153,7 @@ describe("ExternalToolElement", () => {
})
);

await Vue.nextTick();
await nextTick();

expect(
useExternalToolElementDisplayStateMock.fetchDisplayData
Expand All @@ -179,7 +174,7 @@ describe("ExternalToolElement", () => {
})
);

await Vue.nextTick();
await nextTick();

expect(
useExternalToolLaunchStateMock.fetchLaunchRequest
Expand All @@ -205,7 +200,7 @@ describe("ExternalToolElement", () => {
})
);

await Vue.nextTick();
await nextTick();

expect(
useExternalToolLaunchStateMock.fetchLaunchRequest
Expand All @@ -230,7 +225,7 @@ describe("ExternalToolElement", () => {
})
);

await Vue.nextTick();
await nextTick();

expect(
useExternalToolLaunchStateMock.fetchLaunchRequest
Expand All @@ -248,10 +243,10 @@ describe("ExternalToolElement", () => {
useSharedLastCreatedElementMock.lastCreatedElementId.value =
EMPTY_TEST_ELEMENT.id;

await Vue.nextTick();
await nextTick();

const dialog = wrapper.find(
'[data-testid="board-external-tool-element-configuration-dialog"]'
const dialog = wrapper.findComponent(
ExternalToolElementConfigurationDialog
);

expect(dialog.props("isOpen")).toEqual(true);
Expand All @@ -263,7 +258,7 @@ describe("ExternalToolElement", () => {
isEditMode: false,
});

await Vue.nextTick();
await nextTick();

expect(
useExternalToolElementDisplayStateMock.fetchDisplayData
Expand All @@ -276,7 +271,7 @@ describe("ExternalToolElement", () => {
isEditMode: false,
});

await Vue.nextTick();
await nextTick();

expect(
useExternalToolLaunchStateMock.fetchLaunchRequest
Expand Down Expand Up @@ -417,7 +412,7 @@ describe("ExternalToolElement", () => {

const title = wrapper
.findComponent({ ref: "externalToolElement" })
.find(".title");
.find(".text-h6");

expect(title.text()).toEqual(
"feature-board-external-tool-element.placeholder.selectTool"
Expand Down Expand Up @@ -447,7 +442,7 @@ describe("ExternalToolElement", () => {

const title = wrapper
.findComponent({ ref: "externalToolElement" })
.find(".title");
.find(".text-h6");

expect(title.text()).toEqual("...");
});
Expand Down Expand Up @@ -483,7 +478,7 @@ describe("ExternalToolElement", () => {

const title = wrapper
.findComponent({ ref: "externalToolElement" })
.find(".title");
.find(".text-h6");

expect(title.text()).toEqual(toolDisplayData.name);
});
Expand Down Expand Up @@ -546,7 +541,7 @@ describe("ExternalToolElement", () => {

const title = wrapper.findComponent({ ref: "externalToolElement" });

expect(title.attributes("loading")).toBeFalsy();
expect(title.attributes("loading")).toBe("false");
});
});
});
Expand Down Expand Up @@ -616,10 +611,10 @@ describe("ExternalToolElement", () => {
});

card.vm.$emit("click");
await Vue.nextTick();
await nextTick();

const dialog = wrapper.find(
'[data-testid="board-external-tool-element-configuration-dialog"]'
const dialog = wrapper.findComponent(
ExternalToolElementConfigurationDialog
);

expect(dialog.props("isOpen")).toEqual(true);
Expand Down Expand Up @@ -648,12 +643,12 @@ describe("ExternalToolElement", () => {
it("should update the elements content", async () => {
const { wrapper, savedTool } = setup();

const dialog = wrapper.find(
'[data-testid="board-external-tool-element-configuration-dialog"]'
const dialog = wrapper.findComponent(
ExternalToolElementConfigurationDialog
);

dialog.vm.$emit("save", savedTool);
await Vue.nextTick();
await nextTick();

expect(useContentElementStateMock.modelValue.value).toEqual({
contextExternalToolId: savedTool.id,
Expand All @@ -663,12 +658,12 @@ describe("ExternalToolElement", () => {
it("should fetch the display data", async () => {
const { wrapper, savedTool } = setup();

const dialog = wrapper.find(
'[data-testid="board-external-tool-element-configuration-dialog"]'
const dialog = wrapper.findComponent(
ExternalToolElementConfigurationDialog
);

dialog.vm.$emit("save", savedTool);
await Vue.nextTick();
await nextTick();

expect(
useExternalToolElementDisplayStateMock.fetchDisplayData
Expand Down Expand Up @@ -701,7 +696,7 @@ describe("ExternalToolElement", () => {
});

card.vm.$emit("click");
await Vue.nextTick();
await nextTick();

expect(useExternalToolLaunchStateMock.launchTool).toHaveBeenCalled();
});
Expand Down Expand Up @@ -742,21 +737,17 @@ describe("ExternalToolElement", () => {
it("should display an outdated alert", async () => {
const { wrapper, toolOutdatedStatus } = setup();

const alert = wrapper.find(
'[data-testid="board-external-tool-element-alert"]'
);
const alert = wrapper.findComponent(ExternalToolElementAlert);

expect(alert.props("toolStatus")).toEqual(toolOutdatedStatus);
});

it("should display an error alert", async () => {
const { wrapper, error } = setup();

await Vue.nextTick();
await nextTick();

const alert = wrapper.find(
'[data-testid="board-external-tool-element-alert"]'
);
const alert = wrapper.findComponent(ExternalToolElementAlert);

expect(alert.props("error")).toEqual(error);
});
Expand Down Expand Up @@ -788,9 +779,7 @@ describe("ExternalToolElement", () => {
it("should display an incomplete alert", async () => {
const { wrapper, toolIncompleteStatus } = setup();

const alert = wrapper.find(
'[data-testid="board-external-tool-element-alert"]'
);
const alert = wrapper.findComponent(ExternalToolElementAlert);

expect(alert.props("toolStatus")).toEqual(toolIncompleteStatus);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
v-show="hasLinkedTool || isEditMode"
class="mb-4"
data-testid="board-external-tool-element"
dense
elevation="0"
variant="outlined"
ref="externalToolElement"
Expand Down
Loading
Loading