Skip to content

Commit

Permalink
Fixup test output for DefaultBox.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Nov 22, 2024
1 parent d14939f commit 0f06ae8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions client/src/components/Upload/DefaultBox.test.js
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 mountTarget from "./DefaultBox.vue";
Expand Down Expand Up @@ -26,6 +27,30 @@ function getWrapper() {
}

describe("Default", () => {
let UnpatchedIntersectionObserver;

beforeEach(() => {
UnpatchedIntersectionObserver = global.IntersectionObserver;

// The use of b-textarea in this DefaultRow causes the following warning:
// [Vue warn]: Error in directive b-visible unbind hook: "TypeError: this.observer.disconnect is not a function"
// I don't think there is a problem with the usage so I think this a bug in bootstrap vue, it can be worked around
// with the following code - but just suppressing the warning is probably better?
const observerMock = jest.fn(function IntersectionObserver(callback) {
this.observe = jest.fn();
this.disconnect = jest.fn();
// Optionally add a trigger() method to manually trigger a change
this.trigger = (mockedMutationsList) => {
callback(mockedMutationsList, this);
};
});
global.IntersectionObserver = observerMock;
});

afterEach(() => {
global.IntersectionObserver = UnpatchedIntersectionObserver;
});

it("rendering", async () => {
const wrapper = getWrapper();
expect(wrapper.vm.counterAnnounce).toBe(0);
Expand All @@ -34,6 +59,7 @@ describe("Default", () => {
expect(wrapper.find("#btn-reset").classes()).toEqual(expect.arrayContaining(["disabled"]));
expect(wrapper.find("#btn-start").classes()).toEqual(expect.arrayContaining(["disabled"]));
expect(wrapper.find("#btn-stop").classes()).toEqual(expect.arrayContaining(["disabled"]));
await flushPromises();
});

it("resets properly", async () => {
Expand All @@ -44,13 +70,15 @@ describe("Default", () => {
expect(wrapper.vm.counterAnnounce).toBe(1);
await wrapper.find("#btn-reset").trigger("click");
expect(wrapper.vm.showHelper).toBe(true);
await flushPromises();
});

it("does render remote files button", async () => {
const wrapper = getWrapper();
expect(wrapper.find("#btn-remote-files").exists()).toBeTruthy();
await wrapper.setProps({ fileSourcesConfigured: false });
expect(wrapper.find("#btn-remote-files").exists()).toBeFalsy();
await flushPromises();
});

it("renders a limited set", async () => {
Expand All @@ -61,5 +89,6 @@ describe("Default", () => {
expect(wrapper.findAll(".upload-row").length).toBe(3);
const textMessage = wrapper.find("[data-description='lazyload message']");
expect(textMessage.text()).toBe("Only showing first 3 of 5 entries.");
await flushPromises();
});
});

0 comments on commit 0f06ae8

Please sign in to comment.