From 6952650eeb6d9ebaa369df68f432b3ff8b7d7485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Thu, 30 Aug 2018 22:15:42 +0100 Subject: [PATCH] feat(tests): add test coverage for FaviconBadge --- ui/src/Components/FaviconBadge/index.test.js | 40 ++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ui/src/Components/FaviconBadge/index.test.js diff --git a/ui/src/Components/FaviconBadge/index.test.js b/ui/src/Components/FaviconBadge/index.test.js new file mode 100644 index 000000000..79a946669 --- /dev/null +++ b/ui/src/Components/FaviconBadge/index.test.js @@ -0,0 +1,40 @@ +import React from "react"; + +import { mount } from "enzyme"; + +import { AlertStore } from "Stores/AlertStore"; +import { FaviconBadge } from "."; + +let alertStore; + +beforeEach(() => { + alertStore = new AlertStore([]); +}); + +const MountedFaviconBadge = () => { + return mount(); +}; + +describe("", () => { + it("creates Favico instance on mount", () => { + const tree = MountedFaviconBadge(); + const instance = tree.instance(); + expect(instance.favicon).toBeInstanceOf(Object); + }); + + it("updateBadge is called when alertStore.info.totalAlerts changes", () => { + const tree = MountedFaviconBadge(); + const instance = tree.instance(); + const updateSpy = jest.spyOn(instance, "updateBadge"); + alertStore.info.totalAlerts = 99; + expect(updateSpy).toHaveBeenCalledTimes(1); + }); + + it("updateBadge is called when alertStore.status.error changes", () => { + const tree = MountedFaviconBadge(); + const instance = tree.instance(); + const updateSpy = jest.spyOn(instance, "updateBadge"); + alertStore.status.error = "foo"; + expect(updateSpy).toHaveBeenCalledTimes(1); + }); +});