From 9fe6494830f68031f565ed778ed0af784e85a034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Tue, 21 Aug 2018 18:36:56 +0100 Subject: [PATCH] feat(test): add mock modules for fetch() and console --- ui/src/__mocks__/Console.js | 4 ++++ ui/src/__mocks__/Fetch.js | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 ui/src/__mocks__/Console.js create mode 100644 ui/src/__mocks__/Fetch.js diff --git a/ui/src/__mocks__/Console.js b/ui/src/__mocks__/Console.js new file mode 100644 index 000000000..a7dfdef42 --- /dev/null +++ b/ui/src/__mocks__/Console.js @@ -0,0 +1,4 @@ +const ConsoleMock = level => + jest.spyOn(console, level).mockImplementation(() => jest.fn()); + +export { ConsoleMock }; diff --git a/ui/src/__mocks__/Fetch.js b/ui/src/__mocks__/Fetch.js new file mode 100644 index 000000000..add9b7a23 --- /dev/null +++ b/ui/src/__mocks__/Fetch.js @@ -0,0 +1,41 @@ +import moment from "moment"; + +const FetchMock = data => + jest.fn().mockImplementation(() => + Promise.resolve({ + json: () => data + }) + ); + +const EmptyAPIResponse = () => ({ + status: "success", + timestamp: moment().toISOString(), + version: "fakeVersion", + upstreams: { + counters: { total: 1, healthy: 1, failed: 0 }, + instances: [{ name: "default", uri: "file:///mock", error: "" }] + }, + silences: { default: {} }, + groups: {}, + totalAlerts: 0, + colors: {}, + filters: [ + { + text: "label=value", + name: "label", + matcher: "=", + value: "value", + hits: 0, + isValid: true + } + ], + counters: {}, + settings: { + staticColorLabels: ["job"], + annotationsDefaultHidden: false, + annotationsHidden: [], + annotationsVisible: [] + } +}); + +export { FetchMock, EmptyAPIResponse };