diff --git a/public/app.js b/public/app.js index 3f1a5450..380b02d6 100644 --- a/public/app.js +++ b/public/app.js @@ -9,6 +9,7 @@ window.addEventListener("DOMContentLoaded", () => { Twilio.initWebchat({ deploymentKey: urlParams.get("deploymentKey"), region: urlParams.get("region"), + appStatus: urlParams.get("appStatus"), theme: { isLight: isLightTheme } diff --git a/src/__tests__/index.test.tsx b/src/__tests__/index.test.tsx index 9fc27a15..96b7d163 100644 --- a/src/__tests__/index.test.tsx +++ b/src/__tests__/index.test.tsx @@ -6,6 +6,7 @@ import { sessionDataHandler } from "../sessionDataHandler"; import { WebchatWidget } from "../components/WebchatWidget"; import { store } from "../store/store"; import * as initActions from "../store/actions/initActions"; +import * as genericActions from "../store/actions/genericActions"; jest.mock("react-dom"); @@ -28,7 +29,7 @@ describe("Index", () => { const root = document.createElement("div"); root.id = "twilio-webchat-widget-root"; document.body.appendChild(root); - initWebchat({ deploymentKey: "xyz" }); + initWebchat({ deploymentKey: "CV000000" }); expect(renderSpy).toBeCalledWith( @@ -42,7 +43,7 @@ describe("Index", () => { const setRegionSpy = jest.spyOn(sessionDataHandler, "setRegion"); const region = "Foo"; - initWebchat({ deploymentKey: "xyz", region }); + initWebchat({ deploymentKey: "CV000000", region }); expect(setRegionSpy).toBeCalledWith(region); }); @@ -59,7 +60,7 @@ describe("Index", () => { it("initializes config", () => { const initConfigSpy = jest.spyOn(initActions, "initConfig"); - initWebchat({ deploymentKey: "xyz" }); + initWebchat({ deploymentKey: "CV000000" }); expect(initConfigSpy).toBeCalled(); }); @@ -67,7 +68,7 @@ describe("Index", () => { it("initializes config with provided config merged with default config", () => { const initConfigSpy = jest.spyOn(initActions, "initConfig"); - const deploymentKey = "DKxxxxxxxxxxxx"; + const deploymentKey = "CV000000"; initWebchat({ deploymentKey }); expect(initConfigSpy).toBeCalledWith(expect.objectContaining({ deploymentKey, theme: { isLight: true } })); @@ -88,5 +89,26 @@ describe("Index", () => { expect(warningSpy).toBeCalledTimes(1); expect(warningSpy).toHaveBeenCalledWith("someKey is not supported."); }); + + it("triggers expaneded true if appStatus is open", () => { + const changeExpandedStatusSpy = jest.spyOn(genericActions, "changeExpandedStatus"); + + initWebchat({ deploymentKey: "CV000000", appStatus: "open" }); + expect(changeExpandedStatusSpy).toHaveBeenCalledWith({ expanded: true }); + }); + + it("triggers expaneded false if appStatus is closed", () => { + const changeExpandedStatusSpy = jest.spyOn(genericActions, "changeExpandedStatus"); + + initWebchat({ deploymentKey: "CV000000", appStatus: "closed" }); + expect(changeExpandedStatusSpy).toHaveBeenCalledWith({ expanded: false }); + }); + + it("triggers expaneded false with default appStatus", () => { + const changeExpandedStatusSpy = jest.spyOn(genericActions, "changeExpandedStatus"); + + initWebchat({ deploymentKey: "CV000000" }); + expect(changeExpandedStatusSpy).toHaveBeenCalledWith({ expanded: false }); + }); }); }); diff --git a/src/index.tsx b/src/index.tsx index 36044cb7..bf64fb97 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -9,6 +9,7 @@ import { sessionDataHandler } from "./sessionDataHandler"; import { initConfig } from "./store/actions/initActions"; import { ConfigState, UserConfig } from "./store/definitions"; import { initLogger, getLogger } from "./logger"; +import { changeExpandedStatus } from "./store/actions/genericActions"; const defaultConfig: ConfigState = { deploymentKey: "", @@ -24,7 +25,7 @@ const defaultConfig: ConfigState = { }; const initWebchat = async (userConfig: UserConfig) => { - const validKeys = ["deploymentKey", "region", "theme"]; + const validKeys = ["deploymentKey", "region", "theme", "appStatus"]; const logger = window.Twilio.getLogger(`InitWebChat`); if (!userConfig || !userConfig.deploymentKey) { @@ -37,6 +38,9 @@ const initWebchat = async (userConfig: UserConfig) => { } } + store.dispatch(changeExpandedStatus({ expanded: userConfig.appStatus === "open" })); + delete userConfig.appStatus; + const webchatConfig = merge({}, defaultConfig, userConfig); sessionDataHandler.setRegion(webchatConfig.region); diff --git a/src/store/definitions.ts b/src/store/definitions.ts index 18ed0370..a825909c 100644 --- a/src/store/definitions.ts +++ b/src/store/definitions.ts @@ -39,6 +39,7 @@ export type SessionState = { export type UserConfig = { deploymentKey: string; region?: string; + appStatus?: "open"; theme?: { isLight?: boolean; overrides?: Partial;