mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
feat(ui): add more tests for AlertStore
This commit is contained in:
@@ -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"] }
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user