From d8496418fc57b52c666a58c64c85413991386b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 27 Aug 2018 17:28:21 +0100 Subject: [PATCH] feat(tests): add test coverage for SilenceMatch --- .../SilenceModal/SilenceMatch.test.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ui/src/Components/SilenceModal/SilenceMatch.test.js diff --git a/ui/src/Components/SilenceModal/SilenceMatch.test.js b/ui/src/Components/SilenceModal/SilenceMatch.test.js new file mode 100644 index 000000000..5a8ebb9c9 --- /dev/null +++ b/ui/src/Components/SilenceModal/SilenceMatch.test.js @@ -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(); +}; + +describe("", () => { + 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); + }); +});