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); + }); +});