From d7512d5ef3a7e99ccbf37a8221f27ed622f78371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 20 Aug 2018 13:10:30 +0100 Subject: [PATCH] feat(ui): add more tests for AlertStore --- ui/src/Stores/AlertStore.test.js | 77 +++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/ui/src/Stores/AlertStore.test.js b/ui/src/Stores/AlertStore.test.js index 1e7561a1d..b6247b761 100644 --- a/ui/src/Stores/AlertStore.test.js +++ b/ui/src/Stores/AlertStore.test.js @@ -1,6 +1,11 @@ -import { AlertStore, AlertStoreStatuses } from "Stores/AlertStore"; +import { + AlertStore, + AlertStoreStatuses, + FormatUnseeBackendURI, + DecodeLocationSearch +} from "Stores/AlertStore"; -describe("AlertStore", () => { +describe("AlertStore.status", () => { it("status is initially idle with no error", () => { const store = new AlertStore([]); expect(store.status.value).toEqual(AlertStoreStatuses.Idle); @@ -37,3 +42,71 @@ describe("AlertStore", () => { expect(store.status.error).toBeNull(); }); }); + +describe("FormatUnseeBackendURI", () => { + beforeEach(() => { + // wipe REACT_APP_BACKEND_URI env on each run as it's used by some tests + delete process.env.REACT_APP_BACKEND_URI; + }); + + it("FormatUnseeBackendURI without REACT_APP_BACKEND_URI env returns ./ prefixed URIs", () => { + const uri = FormatUnseeBackendURI("foo/bar"); + expect(uri).toEqual("./foo/bar"); + }); + + it("FormatUnseeBackendURI with REACT_APP_BACKEND_URI env returns env value prefixed URIs", () => { + process.env.REACT_APP_BACKEND_URI = "http://localhost:1234"; + const uri = FormatUnseeBackendURI("foo/bar"); + expect(uri).toEqual("http://localhost:1234/foo/bar"); + }); +}); + +describe("DecodeLocationSearch", () => { + const defaultParams = { + defaultsUsed: true, + params: { q: [] } + }; + + it("empty ('') search param is decoded correctly", () => { + expect(DecodeLocationSearch("")).toMatchObject(defaultParams); + }); + + it("empty ('?') search param is decoded correctly", () => { + expect(DecodeLocationSearch("?")).toMatchObject(defaultParams); + }); + + it("no value q[]= search param is decoded correctly", () => { + expect(DecodeLocationSearch("?q[]=")).toMatchObject({ + defaultsUsed: false, + params: { q: [] } + }); + }); + + it("no value q= search param is decoded correctly", () => { + expect(DecodeLocationSearch("?q=")).toMatchObject({ + defaultsUsed: false, + params: { q: [] } + }); + }); + + it("single value q=foo search param is decoded correctly", () => { + expect(DecodeLocationSearch("?q=foo")).toMatchObject({ + defaultsUsed: false, + params: { q: ["foo"] } + }); + }); + + it("single value q[]=foo search param is decoded correctly", () => { + expect(DecodeLocationSearch("?q[]=foo")).toMatchObject({ + defaultsUsed: false, + params: { q: ["foo"] } + }); + }); + + it("multi value q[]=foo&q[]=bar search param is decoded correctly", () => { + expect(DecodeLocationSearch("?q[]=foo&q[]=bar")).toMatchObject({ + defaultsUsed: false, + params: { q: ["foo", "bar"] } + }); + }); +});