feat(tests): add test coverage for SilenceMatch

This commit is contained in:
Łukasz Mierzwa
2018-08-27 17:28:21 +01:00
parent 65aa0ac30b
commit d8496418fc

View File

@@ -0,0 +1,37 @@
import React from "react";
import { shallow } from "enzyme";
import { NewEmptyMatcher, MatcherValueToObject } from "Stores/SilenceFormStore";
import { SilenceMatch } from "./SilenceMatch";
let matcher;
beforeEach(() => {
matcher = NewEmptyMatcher();
});
const ShallowLabelValueInput = () => {
return shallow(<SilenceMatch matcher={matcher} />);
};
describe("<SilenceMatch />", () => {
it("allows changing matcher.isRegex value when matcher.values contains 1 element", () => {
matcher.values = [MatcherValueToObject("foo")];
const tree = ShallowLabelValueInput();
expect(matcher.isRegex).toBe(false);
const regex = tree.find("input[type='checkbox']");
regex.simulate("change", { target: { checked: true } });
expect(matcher.isRegex).toBe(true);
});
it("disallows changing matcher.isRegex value when matcher.values contains 2 elements", () => {
matcher.isRegex = true;
matcher.values = [MatcherValueToObject("foo"), MatcherValueToObject("bar")];
const tree = ShallowLabelValueInput();
expect(matcher.isRegex).toBe(true);
const regex = tree.find("input[type='checkbox']");
regex.simulate("change", { target: { checked: false } });
expect(matcher.isRegex).toBe(true);
});
});