mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
fix(tests): add missing coverage cases for FilerInput
This commit is contained in:
@@ -63,7 +63,16 @@ describe("<FilterInput />", () => {
|
||||
);
|
||||
});
|
||||
|
||||
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("<FilterInput />", () => {
|
||||
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("<FilterInput Autosuggest />", () => {
|
||||
@@ -89,6 +114,15 @@ describe("<FilterInput Autosuggest />", () => {
|
||||
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"]));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user