From 7e2f1fb446ffa577f2b875a08b8c5e79a8046435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sat, 1 Sep 2018 21:59:18 +0100 Subject: [PATCH] feat(tests): add annotation tests --- .../__snapshots__/index.test.js.snap | 90 ++++++++++++++++ .../AlertGroup/Annotation/index.test.js | 100 ++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/__snapshots__/index.test.js.snap create mode 100644 ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.test.js diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/__snapshots__/index.test.js.snap b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/__snapshots__/index.test.js.snap new file mode 100644 index 000000000..dfaa05fd2 --- /dev/null +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/__snapshots__/index.test.js.snap @@ -0,0 +1,90 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` matches snapshot 1`] = ` + + + + annotation name + +`; + +exports[` matches snapshot when visible=false 1`] = ` +" +
+ + + + + foo +
+" +`; + +exports[` matches snapshot when visible=true 1`] = ` +" +
+ + + + + + foo: + + + some long text + +
+" +`; diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.test.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.test.js new file mode 100644 index 000000000..ed1edbbad --- /dev/null +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.test.js @@ -0,0 +1,100 @@ +import React from "react"; + +import { shallow, mount } from "enzyme"; + +import toDiffableHtml from "diffable-html"; + +import { AlertStore } from "Stores/AlertStore"; +import { RenderNonLinkAnnotation, RenderLinkAnnotation } from "."; + +let alertStore; + +beforeEach(() => { + alertStore = new AlertStore([]); +}); + +const ShallowLinkAnnotation = () => { + return shallow( + + ); +}; + +describe("", () => { + it("matches snapshot", () => { + const tree = ShallowLinkAnnotation(); + expect(tree).toMatchSnapshot(); + }); + + it("contains a link", () => { + const tree = ShallowLinkAnnotation(); + const link = tree.find("a[href='http://localhost/foo']"); + expect(link).toHaveLength(1); + expect(link.text()).toMatch(/annotation name/); + }); +}); + +const MockAfterUpdate = jest.fn(); + +const ShallowNonLinkAnnotation = visible => { + return shallow( + + ); +}; + +const MountedNonLinkAnnotation = visible => { + return mount( + + ); +}; + +describe("", () => { + it("matches snapshot when visible=true", () => { + const tree = ShallowNonLinkAnnotation(true); + expect(toDiffableHtml(tree.html())).toMatchSnapshot(); + }); + + it("contains value when visible=true", () => { + const tree = ShallowNonLinkAnnotation(true); + expect(tree.html()).toMatch(/some long text/); + }); + + it("matches snapshot when visible=false", () => { + const tree = ShallowNonLinkAnnotation(false); + expect(toDiffableHtml(tree.html())).toMatchSnapshot(); + }); + + it("doesn't contain value when visible=false", () => { + const tree = ShallowNonLinkAnnotation(false); + expect(tree.html()).not.toMatch(/some long text/); + }); + + it("clicking on + icon hides the value", () => { + const tree = MountedNonLinkAnnotation(true); + expect(tree.html()).toMatch(/fa-search-minus/); + expect(tree.html()).toMatch(/some long text/); + tree.find("div").simulate("click"); + expect(tree.html()).toMatch(/fa-search-plus/); + expect(tree.html()).not.toMatch(/some long text/); + }); + + it("clicking on - icon shows the value", () => { + const tree = MountedNonLinkAnnotation(false); + expect(tree.html()).toMatch(/fa-search-plus/); + expect(tree.html()).not.toMatch(/some long text/); + tree.find("div").simulate("click"); + expect(tree.html()).toMatch(/fa-search-minus/); + expect(tree.html()).toMatch(/some long text/); + }); +});