From 09d1196df0e8e7f12b99e630d4727d15aa0785fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Tue, 1 Jan 2019 21:33:24 +0000 Subject: [PATCH] fix(ui): user alertmanager label as argument for @alertmanager filter --- .../SilenceModal/SilencePreview/index.test.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ui/src/Components/SilenceModal/SilencePreview/index.test.js b/ui/src/Components/SilenceModal/SilencePreview/index.test.js index 9288082bc..5b4d278c6 100644 --- a/ui/src/Components/SilenceModal/SilencePreview/index.test.js +++ b/ui/src/Components/SilenceModal/SilencePreview/index.test.js @@ -75,6 +75,34 @@ describe("", () => { expect(fetch).toHaveBeenCalled(); }); + it("fetch uses correct filters with single Alertmanager instance", async () => { + fetch.mockResponse(JSON.stringify(MockAPIResponse())); + silenceFormStore.data.alertmanagers = [ + { label: "amName", value: ["amValue"] } + ]; + + const tree = MountedSilencePreview(); + await expect(tree.instance().matchedAlerts.fetch).resolves.toBeUndefined(); + expect(fetch).toHaveBeenCalledWith( + "./alerts.json?q=foo%3Dbar&q=%40alertmanager%3D~%5E%28amValue%29%24", + { credentials: "include" } + ); + }); + + it("fetch uses correct filters with multiple Alertmanager instances", async () => { + fetch.mockResponse(JSON.stringify(MockAPIResponse())); + silenceFormStore.data.alertmanagers = [ + { label: "cluster", value: ["am1", "am2"] } + ]; + + const tree = MountedSilencePreview(); + await expect(tree.instance().matchedAlerts.fetch).resolves.toBeUndefined(); + expect(fetch).toHaveBeenCalledWith( + "./alerts.json?q=foo%3Dbar&q=%40alertmanager%3D~%5E%28am1%7Cam2%29%24", + { credentials: "include" } + ); + }); + it("matches snapshot", async () => { fetch.mockResponse(JSON.stringify(MockAPIResponse()));