diff --git a/ui/src/Components/NavBar/FilterInput/index.test.js b/ui/src/Components/NavBar/FilterInput/index.test.js index 996e56193..296835244 100644 --- a/ui/src/Components/NavBar/FilterInput/index.test.js +++ b/ui/src/Components/NavBar/FilterInput/index.test.js @@ -63,7 +63,16 @@ describe("", () => { ); }); - it("Clicking on form-control div focuses input", () => { + it("submit should be no-op if input value is empty", () => { + const tree = MountedInput(); + const instance = tree.instance(); + instance.inputStore.value = ""; + expect(alertStore.filters.values).toHaveLength(0); + tree.find("form").simulate("submit"); + expect(alertStore.filters.values).toHaveLength(0); + }); + + it("clicking on form-control div focuses input", () => { const tree = MountedInput(); const instance = tree.instance(); const inputSpy = jest.spyOn(instance.inputStore.ref.input, "focus"); @@ -71,6 +80,22 @@ describe("", () => { formControl.simulate("click"); expect(inputSpy).toHaveBeenCalledTimes(1); }); + + it("clicking on a label doesn't trigger input focus", () => { + alertStore.filters.values = [NewUnappliedFilter("foo=bar")]; + const tree = MountedInput(); + const instance = tree.instance(); + const inputSpy = jest.spyOn(instance.inputStore.ref.input, "focus"); + tree.find("FilterInputLabel").simulate("click"); + expect(inputSpy).not.toHaveBeenCalled(); + }); + + it("componentDidMount executes even when inputStore.ref=null", () => { + const tree = MountedInput(); + const instance = tree.instance(); + instance.inputStore.ref = null; + instance.componentDidMount(); + }); }); describe("", () => { @@ -89,6 +114,15 @@ describe("", () => { expect(instance.inputStore.suggestions).toContain("foo=~bar"); }); + it("doesn't fetch any suggestion if the input value is empty", () => { + fetch.mockResponseOnce(JSON.stringify(["foo=bar", "foo=~bar"])); + + const tree = MountedInput(); + const instance = tree.instance(); + instance.onSuggestionsFetchRequested({ value: "" }); + expect(fetch.mock.calls).toHaveLength(0); + }); + it("clicking on a suggestion adds it to filters", async () => { fetch.mockResponse(JSON.stringify(["foo=bar", "foo=~bar"]));