feat(tests): add history dropdown visibility test

This commit is contained in:
Łukasz Mierzwa
2018-08-23 21:46:43 +01:00
parent 464e92e76d
commit 29847a97d4
3 changed files with 35 additions and 0 deletions

14
ui/__mocks__/popper.js.js Normal file
View File

@@ -0,0 +1,14 @@
// https://github.com/FezVrasta/popper.js/issues/478#issuecomment-341506071
import PopperJs from "popper.js";
export default class Popper {
static placements = PopperJs.placements;
constructor() {
return {
destroy: () => {},
scheduleUpdate: () => {}
};
}
}

6
ui/__mocks__/react-onclickoutside.js vendored Normal file
View File

@@ -0,0 +1,6 @@
// mock react-onclickoutside so we bypass it due to:
// TypeError: Cannot read property 'isReactComponent' of undefined
export default function onClickOutsideHOC(WrappedComponent, config) {
return WrappedComponent;
}

View File

@@ -1,6 +1,8 @@
import React from "react";
import renderer from "react-test-renderer";
import { mount } from "enzyme";
import { AlertStore, NewUnappliedFilter } from "Stores/AlertStore";
import { Settings } from "Stores/Settings";
import { History, ReduceFilter } from "./History";
@@ -37,6 +39,19 @@ describe("<History />", () => {
);
});
// Due to https://github.com/FezVrasta/popper.js/issues/478 we can't test
// rendered dropdown content, only the fact that toggle value is updated
it("renders dropdown button when menu is visible", () => {
const tree = mount(
<History alertStore={alertStore} settingsStore={settingsStore} />
);
const toggle = tree.find("button.components-navbar-history");
expect(tree.instance().collapse.value).toBe(true);
toggle.simulate("click");
expect(tree.instance().collapse.value).toBe(false);
});
it("saves only applied filters to history", () => {
alertStore.filters.values = [
AppliedFilter("foo", "=", "bar"),