Skip to content

Commit

Permalink
Merge branch 'main' into BC-4482-revert-incorrect-board-menu-item
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverHappe authored Oct 18, 2023
2 parents 912e2af + c5373a9 commit 35f8ecb
Show file tree
Hide file tree
Showing 41 changed files with 1,335 additions and 495 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import createComponentMocks from "@@/tests/test-utils/componentMocks";
import { fileElementResponseFactory } from "@@/tests/test-utils/factory/fileElementResponseFactory";
import { fileRecordResponseFactory } from "@@/tests/test-utils/factory/filerecordResponse.factory";
import { MountOptions, shallowMount } from "@vue/test-utils";
import Vue from "vue";
import FileContentElement from "./FileContentElement.vue";
import Vue, { computed } from "vue";
import { useFileAlerts } from "./content/alert/useFileAlerts.composable";
import FileContent from "./content/FileContent.vue";
import FileContentElement from "./FileContentElement.vue";
import { FileProperties } from "./shared/types/file-properties";
import { FileAlert } from "./shared/types/FileAlert.enum";
import FileUpload from "./upload/FileUpload.vue";

jest.mock("@data-board", () => {
Expand All @@ -27,6 +29,7 @@ jest.mock("@data-board", () => {
});
jest.mock("@feature-board");
jest.mock("./shared/composables/FileStorageApi.composable");
jest.mock("./content/alert/useFileAlerts.composable");

describe("FileContentElement", () => {
const notifierModule = createModuleMocks(NotifierModule);
Expand All @@ -35,6 +38,13 @@ describe("FileContentElement", () => {
isEditMode: boolean;
}) => {
const menu = "slot-menu";

const addAlertMock = jest.fn();
jest.mocked(useFileAlerts).mockReturnValue({
addAlert: addAlertMock,
alerts: computed(() => []),
});

const wrapper = shallowMount(FileContentElement as MountOptions<Vue>, {
...createComponentMocks({ i18n: true }),
provide: {
Expand All @@ -47,7 +57,7 @@ describe("FileContentElement", () => {
},
});

return { wrapper, menu };
return { wrapper, menu, addAlertMock };
};

describe("when component is not in edit mode", () => {
Expand Down Expand Up @@ -142,9 +152,10 @@ describe("FileContentElement", () => {
size: fileRecordResponse.size,
previewStatus: fileRecordResponse.previewStatus,
element,
mimeType: fileRecordResponse.mimeType,
};

const { wrapper, menu } = getWrapper({
const { wrapper, menu, addAlertMock } = getWrapper({
element,
isEditMode: false,
});
Expand All @@ -156,6 +167,7 @@ describe("FileContentElement", () => {
element,
expectedFileProperties,
menu,
addAlertMock,
};
};

Expand All @@ -167,6 +179,35 @@ describe("FileContentElement", () => {
expect(card.props("outlined")).toBe(false);
});

describe("when file content emits add:alert event", () => {
it("should add event payload to emittedAlerts", async () => {
const { wrapper, addAlertMock } = setup();

await wrapper.vm.$nextTick();

const fileContent = wrapper.findComponent(FileContent);
const alert = FileAlert.VIDEO_FORMAT_ERROR;
fileContent.vm.$emit("add:alert", alert);

expect(addAlertMock).toHaveBeenCalledWith(alert);
});
});

describe("when file content emits fetch:file event", () => {
it("should call fetchFile when FileContent emits fetch:file event", async () => {
const { wrapper, fetchFile } = setup();

await wrapper.vm.$nextTick();

expect(fetchFile).toHaveBeenCalledTimes(1);

const fileContent = wrapper.findComponent(FileContent);
fileContent.vm.$emit("fetch:file");

expect(fetchFile).toHaveBeenCalledTimes(2);
});
});

describe("when v-card emits keydown.down event", () => {
it("should emit move-keyboard:edit event", async () => {
const { wrapper } = setup();
Expand Down Expand Up @@ -244,21 +285,6 @@ describe("FileContentElement", () => {
expect(fileProperties).toEqual(expectedFileProperties);
});

it("should call fetchFile when FileContent emits fetch:file event", async () => {
const { wrapper, fetchFile } = setup();

await wrapper.vm.$nextTick();

expect(fetchFile).toHaveBeenCalledTimes(1);

const fileContent = wrapper.findComponent(FileContent);
fileContent.vm.$emit("fetch:file");

await wrapper.vm.$nextTick();

expect(fetchFile).toHaveBeenCalledTimes(2);
});

it("should not render File Upload component", async () => {
const { wrapper } = setup();
await wrapper.vm.$nextTick();
Expand Down Expand Up @@ -455,6 +481,7 @@ describe("FileContentElement", () => {
size: fileRecordResponse.size,
previewStatus: fileRecordResponse.previewStatus,
element,
mimeType: fileRecordResponse.mimeType,
};

const { wrapper, menu } = getWrapper({
Expand Down
14 changes: 13 additions & 1 deletion src/components/feature-board-file-element/FileContentElement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
<FileContent
v-if="fileProperties"
:file-properties="fileProperties"
@fetch:file="onFetchFile"
:alerts="alerts"
:is-edit-mode="isEditMode"
@fetch:file="onFetchFile"
@update:alternativeText="onUpdateAlternativeText"
@update:caption="onUpdateCaption"
@add:alert="onAddAlert"
>
<BoardMenu scope="element" v-if="isEditMode">
<BoardMenuActionMoveUp @click="onMoveUp" />
Expand Down Expand Up @@ -61,8 +63,10 @@ import {
ref,
toRef,
} from "vue";
import { useFileAlerts } from "./content/alert/useFileAlerts.composable";
import FileContent from "./content/FileContent.vue";
import { useFileStorageApi } from "./shared/composables/FileStorageApi.composable";
import { FileAlert } from "./shared/types/FileAlert.enum";
import FileUpload from "./upload/FileUpload.vue";
export default defineComponent({
Expand Down Expand Up @@ -97,6 +101,8 @@ export default defineComponent({
FileRecordParentType.BOARDNODES
);
const { alerts, addAlert } = useFileAlerts(fileRecord);
const fileProperties = computed(() => {
if (fileRecord.value === undefined) {
return;
Expand All @@ -115,6 +121,7 @@ export default defineComponent({
isDownloadAllowed: isDownloadAllowed(
fileRecord.value.securityCheckStatus
),
mimeType: fileRecord.value.mimeType,
element: props.element,
};
});
Expand Down Expand Up @@ -161,6 +168,9 @@ export default defineComponent({
modelValue.value.caption = value;
};
const onAddAlert = (alert: FileAlert) => {
addAlert(alert);
};
const onDelete = () => emit("delete:element", element.value.id);
const onMoveUp = () => emit("move-up:edit");
const onMoveDown = () => emit("move-down:edit");
Expand All @@ -172,11 +182,13 @@ export default defineComponent({
hasFileRecord,
isOutlined,
modelValue,
alerts,
onKeydownArrow,
onUploadFile,
onFetchFile,
onUpdateAlternativeText,
onUpdateCaption,
onAddAlert,
onDelete,
onMoveUp,
onMoveDown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { PreviewStatus } from "@/fileStorageApi/v3";
import { fileElementResponseFactory } from "@@/tests/test-utils";
import createComponentMocks from "@@/tests/test-utils/componentMocks";
import { shallowMount } from "@vue/test-utils";
import { FileAlert } from "../shared/types/FileAlert.enum";
import FileAlerts from "./alert/FileAlerts.vue";
import FileDisplay from "./display/FileDisplay.vue";
import FileContent from "./FileContent.vue";
import FileAlert from "./alert/FileAlert.vue";
import ContentElementFooter from "./footer/ContentElementFooter.vue";
import FileInputs from "./inputs/FileInputs.vue";

Expand All @@ -24,24 +26,28 @@ describe("FileContent", () => {
isDownloadAllowed: true,
element,
};

const alerts = [FileAlert.AWAITING_SCAN_STATUS];
const wrapper = shallowMount(FileContent, {
propsData: {
fileProperties,
isEditMode: true,
alerts,
},
...createComponentMocks({}),
});

return {
wrapper,
fileProperties,
alerts,
};
};

it("should pass props to FileContent", () => {
it("should pass props to FileDisplay", () => {
const { wrapper, fileProperties } = setup();

const fileContent = wrapper.findComponent(FileContent);
const fileContent = wrapper.findComponent(FileDisplay);

expect(fileContent.props()).toEqual({
fileProperties,
Expand All @@ -61,54 +67,73 @@ describe("FileContent", () => {
});

it("should pass props to FileAlert", () => {
const { wrapper, fileProperties } = setup();
const { wrapper, alerts } = setup();

const fileAlert = wrapper.findComponent(FileAlert);
const fileAlert = wrapper.findComponent(FileAlerts);

expect(fileAlert.props()).toEqual({
previewStatus: fileProperties.previewStatus,
alerts,
});
});

it("should FileInputs component be in dom", () => {
const { wrapper } = setup();
it("should pass props to FileInputs", () => {
const { wrapper, fileProperties } = setup();

const fileInputs = wrapper.findComponent(FileInputs);

expect(fileInputs.exists()).toBe(true);
expect(fileInputs.props()).toEqual({
fileProperties,
isEditMode: true,
});
});

it("should emit update:alternativeText event, when it receives update:text event from file inputs component", async () => {
const { wrapper } = setup();
describe("when file inputs emit update:alternativeText", () => {
it("should emit update:alternativeText", async () => {
const { wrapper } = setup();

const fileInputs = wrapper.findComponent(FileInputs);
const fileInputs = wrapper.findComponent(FileInputs);

fileInputs.vm.$emit("update:alternativeText");
fileInputs.vm.$emit("update:alternativeText");

expect(wrapper.emitted("update:alternativeText")).toHaveLength(1);
expect(wrapper.emitted("update:alternativeText")).toHaveLength(1);
});
});

it("should emit update:caption event, when it receives update:caption event from file inputs component", async () => {
const { wrapper } = setup();
describe("when file inputs emit update:caption", () => {
it("should emit update:caption event, when it receives update:caption event from file inputs component", async () => {
const { wrapper } = setup();

const fileInputs = wrapper.findComponent(FileInputs);
const fileInputs = wrapper.findComponent(FileInputs);

fileInputs.vm.$emit("update:caption");
fileInputs.vm.$emit("update:caption");

expect(wrapper.emitted("update:caption")).toHaveLength(1);
expect(wrapper.emitted("update:caption")).toHaveLength(1);
});
});

describe("when alert emits on-status-reload", () => {
describe("when file alerts emits on-status-reload", () => {
it("should emit fetch:file event", async () => {
const { wrapper } = setup();

const fileAlert = wrapper.findComponent(FileAlert);
const fileAlert = wrapper.findComponent(FileAlerts);

await fileAlert.vm.$emit("on-status-reload");

expect(wrapper.emitted("fetch:file")).toBeTruthy();
});
});

describe("when file display emits add:alert", () => {
it("should emit add:alert event", async () => {
const { wrapper } = setup();

const fileDisplay = wrapper.findComponent(FileDisplay);

fileDisplay.vm.$emit("add:alert");

expect(wrapper.emitted("add:alert")).toHaveLength(1);
});
});
});
});
});
Loading

0 comments on commit 35f8ecb

Please sign in to comment.