feat(ui): add more tests for AlertStore

This commit is contained in:
Łukasz Mierzwa
2018-08-20 13:10:30 +01:00
parent 4c41d37c21
commit d7512d5ef3

View File

@@ -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"] }
});
});
});