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 89b1332 commit cb66040
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions client/src/components/Upload/DefaultBox.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from "@vue/test-utils";

Check failure on line 1 in client/src/components/Upload/DefaultBox.test.js

View workflow job for this annotation

GitHub Actions / client-unit-test (18)

Run autofix to sort these imports!
import { getLocalVue } from "tests/jest/helpers";
import flushPromises from "flush-promises";

import mountTarget from "./DefaultBox.vue";

Expand All @@ -25,7 +26,32 @@ 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 +60,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 +71,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 +90,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 cb66040

Please sign in to comment.