From af68bedfb397f0f71586c6c6b8c1a9a2b278f60a Mon Sep 17 00:00:00 2001 From: Lukasz Ostrowski Date: Thu, 11 Aug 2022 20:51:02 +0200 Subject: [PATCH] Tests for actions --- src/app-bridge/actions.test.ts | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/app-bridge/actions.test.ts diff --git a/src/app-bridge/actions.test.ts b/src/app-bridge/actions.test.ts new file mode 100644 index 0000000..997f4ef --- /dev/null +++ b/src/app-bridge/actions.test.ts @@ -0,0 +1,37 @@ +import { describe, expect, it } from "vitest"; + +import { actions, NotificationPayload, RedirectPayload } from "./actions"; + +describe("actions.ts", () => { + describe("actions.Notification", () => { + it("Constructs action with \"notification\" type, random id and payload", () => { + const payload: NotificationPayload = { + apiMessage: "test-api-message", + status: "info", + text: "test-text", + title: "test-title", + }; + + const action = actions.Notification(payload); + + expect(action.type).toBe("notification"); + expect(action.payload.actionId).toEqual(expect.any(String)); + expect(action.payload).toEqual(expect.objectContaining(payload)); + }); + }); + + describe("actions.Redirect", () => { + it("Constructs action with \"redirect\" type, random id and payload", () => { + const payload: RedirectPayload = { + newContext: true, + to: "/foo/bar", + }; + + const action = actions.Redirect(payload); + + expect(action.type).toBe("redirect"); + expect(action.payload.actionId).toEqual(expect.any(String)); + expect(action.payload).toEqual(expect.objectContaining(payload)); + }); + }); +});