@nyaruka/temba-components 0.123.0 → 0.124.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/copilot-instructions.md +22 -4
- package/CHANGELOG.md +21 -0
- package/TEST_OPTIMIZATION.md +158 -0
- package/demo/alert/example.html +65 -0
- package/demo/button/example.html +71 -0
- package/demo/chart/example.html +56 -0
- package/demo/checkbox/example.html +72 -0
- package/demo/compose/example.html +72 -0
- package/demo/data/images/gus.png +0 -0
- package/demo/data/images/purrington.jpg +0 -0
- package/demo/data/server/opened-tickets.json +40 -0
- package/demo/data/server/response-time.json +27 -0
- package/demo/datepicker/example.html +69 -0
- package/demo/dialog/example.html +107 -0
- package/demo/dropdown/example.html +99 -0
- package/demo/index.html +152 -430
- package/demo/misc/example.html +72 -0
- package/demo/progress/example.html +59 -0
- package/demo/select/drag-and-drop.html +142 -0
- package/demo/select/example.html +82 -0
- package/demo/select/multi.html +73 -0
- package/demo/slider/example.html +59 -0
- package/demo/sortable-list/example.html +99 -0
- package/demo/styles.css +183 -0
- package/demo/tabs/example.html +91 -0
- package/demo/textinput/completion.html +56 -0
- package/demo/textinput/example.html +61 -0
- package/dist/temba-components.js +323 -191
- package/dist/temba-components.js.map +1 -1
- package/out-tsc/src/chart/TembaChart.js +19 -16
- package/out-tsc/src/chart/TembaChart.js.map +1 -1
- package/out-tsc/src/fields/FieldManager.js +27 -34
- package/out-tsc/src/fields/FieldManager.js.map +1 -1
- package/out-tsc/src/flow/Editor.js +1 -1
- package/out-tsc/src/flow/Editor.js.map +1 -1
- package/out-tsc/src/list/SortableList.js +257 -60
- package/out-tsc/src/list/SortableList.js.map +1 -1
- package/out-tsc/src/omnibox/Omnibox.js +1 -1
- package/out-tsc/src/omnibox/Omnibox.js.map +1 -1
- package/out-tsc/src/select/Select.js +198 -38
- package/out-tsc/src/select/Select.js.map +1 -1
- package/out-tsc/src/thumbnail/Thumbnail.js +1 -1
- package/out-tsc/src/thumbnail/Thumbnail.js.map +1 -1
- package/out-tsc/src/webchat/WebChat.js +5 -2
- package/out-tsc/src/webchat/WebChat.js.map +1 -1
- package/out-tsc/test/temba-chart.test.js +1 -1
- package/out-tsc/test/temba-chart.test.js.map +1 -1
- package/out-tsc/test/temba-compose.test.js +6 -30
- package/out-tsc/test/temba-compose.test.js.map +1 -1
- package/out-tsc/test/temba-contact-chat.test.js +1 -2
- package/out-tsc/test/temba-contact-chat.test.js.map +1 -1
- package/out-tsc/test/temba-dropdown.test.js +1 -1
- package/out-tsc/test/temba-dropdown.test.js.map +1 -1
- package/out-tsc/test/temba-flow-editor-node.test.js +273 -0
- package/out-tsc/test/temba-flow-editor-node.test.js.map +1 -0
- package/out-tsc/test/temba-flow-editor.test.js +244 -0
- package/out-tsc/test/temba-flow-editor.test.js.map +1 -0
- package/out-tsc/test/temba-flow-plumber.test.js +145 -0
- package/out-tsc/test/temba-flow-plumber.test.js.map +1 -0
- package/out-tsc/test/temba-flow-render.test.js +171 -0
- package/out-tsc/test/temba-flow-render.test.js.map +1 -0
- package/out-tsc/test/temba-omnibox.test.js +6 -3
- package/out-tsc/test/temba-omnibox.test.js.map +1 -1
- package/out-tsc/test/temba-select.test.js +183 -53
- package/out-tsc/test/temba-select.test.js.map +1 -1
- package/out-tsc/test/temba-sortable-list.test.js +91 -15
- package/out-tsc/test/temba-sortable-list.test.js.map +1 -1
- package/out-tsc/test/temba-toast.test.js +1 -2
- package/out-tsc/test/temba-toast.test.js.map +1 -1
- package/out-tsc/test/temba-utils-index.test.js +2 -2
- package/out-tsc/test/temba-utils-index.test.js.map +1 -1
- package/out-tsc/test/temba-webchat-lightbox-fix.test.js +42 -0
- package/out-tsc/test/temba-webchat-lightbox-fix.test.js.map +1 -0
- package/out-tsc/test/utils.test.js +58 -0
- package/out-tsc/test/utils.test.js.map +1 -1
- package/package.json +2 -3
- package/screenshots/truth/flow/editor-basic.png +0 -0
- package/screenshots/truth/list/fields-dragging.png +0 -0
- package/screenshots/truth/list/sortable-dragging.png +0 -0
- package/screenshots/truth/list/sortable-dropped.png +0 -0
- package/screenshots/truth/list/sortable.png +0 -0
- package/screenshots/truth/omnibox/selected.png +0 -0
- package/screenshots/truth/select/disabled-multi-selection.png +0 -0
- package/screenshots/truth/select/disabled-selection.png +0 -0
- package/screenshots/truth/select/disabled.png +0 -0
- package/screenshots/truth/select/embedded.png +0 -0
- package/screenshots/truth/select/empty-options.png +0 -0
- package/screenshots/truth/select/expression-selected.png +0 -0
- package/screenshots/truth/select/expressions.png +0 -0
- package/screenshots/truth/select/functions.png +0 -0
- package/screenshots/truth/select/local-options.png +0 -0
- package/screenshots/truth/select/multi-reorder-final.png +0 -0
- package/screenshots/truth/select/multi-reorder-initial.png +0 -0
- package/screenshots/truth/select/multi-with-endpoint.png +0 -0
- package/screenshots/truth/select/multiple-initial-values.png +0 -0
- package/screenshots/truth/select/remote-options.png +0 -0
- package/screenshots/truth/select/search-enabled.png +0 -0
- package/screenshots/truth/select/search-multi-no-matches.png +0 -0
- package/screenshots/truth/select/search-selected-focus.png +0 -0
- package/screenshots/truth/select/search-selected.png +0 -0
- package/screenshots/truth/select/search-with-selected.png +0 -0
- package/screenshots/truth/select/searching.png +0 -0
- package/screenshots/truth/select/selected-multi-maxitems-reached.png +0 -0
- package/screenshots/truth/select/selected-multi.png +0 -0
- package/screenshots/truth/select/selected-single.png +0 -0
- package/screenshots/truth/select/selection-clearable.png +0 -0
- package/screenshots/truth/select/static-initial-value.png +0 -0
- package/screenshots/truth/select/static-initial-via-selected.png +0 -0
- package/screenshots/truth/select/truncated-selection.png +0 -0
- package/screenshots/truth/select/with-placeholder.png +0 -0
- package/screenshots/truth/select/without-placeholder.png +0 -0
- package/screenshots/truth/templates/default.png +0 -0
- package/screenshots/truth/templates/unapproved.png +0 -0
- package/screenshots/truth/webchat/connected-state.png +0 -0
- package/src/chart/TembaChart.ts +20 -16
- package/src/fields/FieldManager.ts +30 -38
- package/src/flow/Editor.ts +1 -1
- package/src/list/SortableList.ts +291 -67
- package/src/omnibox/Omnibox.ts +1 -1
- package/src/select/Select.ts +213 -42
- package/src/thumbnail/Thumbnail.ts +1 -1
- package/src/webchat/WebChat.ts +5 -2
- package/test/temba-chart.test.ts +1 -1
- package/test/temba-compose.test.ts +11 -38
- package/test/temba-contact-chat.test.ts +4 -6
- package/test/temba-dropdown.test.ts +1 -1
- package/test/temba-flow-editor-node.test.ts +344 -0
- package/test/temba-flow-editor.test.ts +301 -0
- package/test/temba-flow-plumber.test.ts +189 -0
- package/test/temba-flow-render.test.ts +220 -0
- package/test/temba-omnibox.test.ts +7 -3
- package/test/temba-select.test.ts +247 -79
- package/test/temba-sortable-list.test.ts +108 -15
- package/test/temba-toast.test.ts +2 -2
- package/test/temba-utils-index.test.ts +2 -2
- package/test/temba-webchat-lightbox-fix.test.ts +57 -0
- package/test/utils.test.ts +88 -0
- package/web-test-runner.config.mjs +4 -2
- package/.storybook/main.js +0 -14
- package/.storybook/preview-head.html +0 -1
- package/.storybook/preview.js +0 -17
- package/demo/agents.html +0 -147
- package/demo/old.html +0 -573
- package/demo/remote.html +0 -3
- package/screenshots/truth/compose/attachments-with-files-focused.png +0 -0
- package/stories/temba-checkbox.stories.md +0 -37
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebChat.js","sourceRoot":"","sources":["../../../src/webchat/WebChat.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,OAAO,EAAE,UAAU,EAAkB,IAAI,EAAE,GAAG,EAAoB,MAAM,KAAK,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAA4B,WAAW,EAAE,MAAM,cAAc,CAAC;AA0ErE,IAAK,UAIJ;AAJD,WAAK,UAAU;IACb,2CAA6B,CAAA;IAC7B,uCAAyB,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AW;;;;;;;;2BAQlB,IAAI,CAAC,kBAAkB;;qBAE7B;YACX,CAAC,CAAC,IAAI;;;oBAGI,IAAI,CAAC,UAAU;;;8DAG2B,IAAI;aACrD,gBAAgB,IAAI,cAAc;;;KAG1C,CAAC;IACJ,CAAC;CACF;AA3SC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCACX;AAGhB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oCACf;AAGZ;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;8CACK;AAI/B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uCACkB;AAI7C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;qCACf;AAGb;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;+CACL;AAGvB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qCACd;AAGb;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iDACF;AAGzB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;qDACjB","sourcesContent":["/* eslint-disable @typescript-eslint/no-this-alias */\nimport { LitElement, TemplateResult, html, css, PropertyValueMap } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { getCookie, setCookie } from '../utils';\nimport { DEFAULT_AVATAR } from './assets';\nimport { Chat, ChatEvent, Message, MessageType } from '../chat/Chat';\n\ninterface User {\n avatar?: string;\n email: string;\n name: string;\n id: string;\n}\n\ninterface MsgIn {\n id: string;\n text: string;\n time: string;\n}\n\ninterface MsgOut extends MsgIn {\n user: User;\n origin: string;\n}\n\ninterface SockMsg {\n type:\n | 'start_chat'\n | 'get_history'\n | 'send_msg'\n | 'ack_chat'\n\n // responses\n | 'chat_started'\n | 'chat_resumed'\n | 'msg_in'\n | 'msg_out'\n | 'history'\n\n // receiving\n | 'chat_out';\n}\n\ninterface GetHistoryCmd extends SockMsg {\n before?: string;\n}\n\ninterface StartChatCmd extends SockMsg {\n chat_id?: string;\n}\n\ninterface SendMsgCmd extends SockMsg {\n text: string;\n}\n\ninterface Ack extends SockMsg {\n msg_id: string;\n}\n\ninterface MsgOutResponse extends SockMsg {\n msg_out: MsgOut;\n}\n\ninterface MsgInResponse extends SockMsg {\n msg_in: MsgIn;\n}\n\ninterface HistoryResponse extends SockMsg {\n history: (MsgInResponse | MsgOutResponse)[];\n}\n\ninterface StartChatResponse extends SockMsg {\n chat_id: string;\n}\n\ninterface ResumeChatResponse extends StartChatResponse {\n email?: string;\n}\n\nenum ChatStatus {\n DISCONNECTED = 'disconnected',\n CONNECTING = 'connecting',\n CONNECTED = 'connected'\n}\n\nconst sockToChat = function (msg: any): ChatEvent | Message {\n const type = msg.msg_in ? MessageType.MsgIn : MessageType.MsgOut;\n const msgContent = msg.msg_in || msg.msg_out;\n\n return {\n id: msgContent.id,\n type,\n text: msgContent.text,\n date: new Date(msgContent.time),\n user: msgContent.user,\n attachments: msgContent.attachments\n };\n};\n\nexport class WebChat extends LitElement {\n static get styles() {\n return css`\n :host {\n display: flex;\n align-items: center;\n align-self: center;\n --curvature: 0.6em;\n --color-primary: hsla(208, 70%, 55%, 1);\n font-family: 'Roboto', 'Helvetica Neue', sans-serif;\n font-weight: 400;\n --toggle-speed: 80ms;\n position: fixed;\n right: 0;\n bottom: 0;\n z-index: 10000;\n }\n\n .header {\n background: var(--color-primary);\n height: 3em;\n display: flex;\n align-items: center;\n width: 100%;\n color: rgba(255, 255, 255, 0.8);\n font-size: 0.8em;\n }\n\n .header slot {\n flex-grow: 1;\n padding: 1em;\n color: rgba(255, 255, 255, 0.9);\n font-size: 1.2em;\n display: block;\n }\n\n .header .close-button {\n margin: 0.5em;\n color: rgba(255, 255, 255, 0.5);\n cursor: pointer;\n }\n\n .header .close-button:hover {\n cursor: pointer;\n color: rgba(255, 255, 255, 1);\n }\n\n .block {\n margin-bottom: 1em;\n }\n\n .time {\n text-align: center;\n font-size: 0.8em;\n color: #999;\n margin-top: 2em;\n border-top: 1px solid #f8f8f8;\n padding: 1em;\n margin-left: 4em;\n margin-right: 4em;\n }\n\n .first .time {\n margin-top: 0;\n border-top: none;\n padding-top: 0;\n }\n\n .row {\n display: flex;\n flex-direction: row;\n align-items: flex-start;\n }\n\n .input-panel {\n padding: 1em;\n background: #fff;\n }\n\n .border {\n border-top: 1px solid #e9e9e9;\n margin: 0 1em;\n }\n\n .avatar {\n margin-top: 0.6em;\n margin-right: 0.6em;\n flex-shrink: 0;\n width: 2em;\n height: 2em;\n overflow: hidden;\n border-radius: 100%;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 3px 7px 0px,\n rgba(0, 0, 0, 0.2) 0px 1px 2px 0px,\n inset 0 0 0 0.15em rgba(0, 0, 0, 0.1);\n }\n\n .toggle {\n flex-shrink: 0;\n width: 4em;\n height: 4em;\n overflow: hidden;\n border-radius: 100%;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1em 0.7em,\n rgba(0, 0, 0, 0.2) 0px 1px 2px 0px,\n inset 0 0 0 0.25em rgba(0, 0, 0, 0.1);\n cursor: pointer;\n transition: box-shadow var(--toggle-speed) ease-out;\n position: absolute;\n bottom: 1em;\n right: 1em;\n }\n\n .toggle:hover {\n box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1em 0.7em,\n rgba(0, 0, 0, 0.4) 0px 1px 2px 0px,\n inset 0 0 0 0.25em rgba(0, 0, 0, 0.2);\n }\n\n .incoming .row {\n flex-direction: row-reverse;\n margin-left: 1em;\n }\n\n .bubble {\n padding: 1em;\n padding-bottom: 0.5em;\n background: #fafafa;\n border-radius: var(--curvature);\n max-width: 70%;\n }\n\n .bubble .name {\n font-size: 0.95em;\n font-weight: 400;\n color: #888;\n margin-bottom: 0.25em;\n }\n\n .outgoing .bubble {\n border-top-left-radius: 0;\n }\n\n .incoming .bubble {\n background: var(--color-primary);\n color: white;\n border-top-right-radius: 0;\n text-align: right;\n }\n\n .message {\n margin-bottom: 0.5em;\n line-height: 1.2em;\n }\n\n .chat {\n height: 40rem;\n width: 28rem;\n border-radius: var(--curvature);\n overflow: hidden;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 3px 7px 0px,\n rgba(0, 0, 0, 0.2) 0px 1px 2px 0px, rgba(0, 0, 0, 0.1) 5em 5em 5em 5em;\n position: absolute;\n bottom: 3em;\n right: 1em;\n transition: all var(--toggle-speed) ease-out;\n transform: scale(0.9);\n pointer-events: none;\n opacity: 0;\n display: flex;\n flex-direction: column;\n background: #fff;\n }\n\n .chat.open {\n bottom: 6em;\n opacity: 1;\n transform: scale(1);\n pointer-events: initial;\n }\n\n .input {\n border: none;\n flex-grow: 1;\n color: #333;\n font-size: 1em;\n }\n\n .input:focus {\n outline: none;\n }\n\n input::placeholder {\n opacity: 0.3;\n }\n\n .input.inactive {\n // pointer-events: none;\n // opacity: 0.3;\n }\n\n .active {\n }\n\n .send-icon {\n color: #eee;\n pointer-events: none;\n transform: rotate(-45deg);\n transition: transform 0.2s ease-out;\n }\n\n .pending .send-icon {\n color: var(--color-primary);\n pointer-events: initial;\n transform: rotate(0deg);\n }\n\n .notice {\n padding: 1em;\n background: #f8f8f8;\n color: #666;\n text-align: center;\n cursor: pointer;\n }\n\n .connecting .notice {\n display: flex;\n justify-content: center;\n }\n\n .connecting .notice temba-icon {\n margin-left: 0.5em;\n }\n\n .reconnect {\n color: var(--color-primary);\n text-decoration: underline;\n font-size: 0.9em;\n }\n\n .input:disabled {\n background: transparent !important;\n }\n\n temba-loading {\n justify-content: center;\n margin: 0.5em auto;\n margin-bottom: 2em;\n }\n\n temba-loading.hidden {\n display: none;\n }\n `;\n }\n\n @property({ type: String })\n channel: string;\n\n @property({ type: String })\n urn: string;\n\n @property({ type: Array })\n messageGroups: string[][] = [];\n\n // is our socket connection established\n @property({ type: String })\n status: ChatStatus = ChatStatus.DISCONNECTED;\n\n // is the chat widget open\n @property({ type: Boolean })\n open = false;\n\n @property({ type: Boolean })\n hasPendingText = false;\n\n @property({ type: String })\n host: string;\n\n @property({ type: String })\n activeUserAvatar: string;\n\n @property({ type: Boolean, attribute: false })\n blockHistoryFetching = false;\n\n private chat: Chat;\n private sock: WebSocket;\n private newMessageCount = 0;\n private fetchRequested: Date;\n private beforeTime: string;\n\n public constructor() {\n super();\n }\n\n public firstUpdated(\n changed: PropertyValueMap<any> | Map<PropertyKey, unknown>\n ): void {\n super.firstUpdated(changed);\n this.chat = this.shadowRoot.querySelector('temba-chat');\n\n const lightbox = document.createElement('temba-lightbox');\n document.querySelector('body').appendChild(lightbox);\n }\n\n private handleReconnect() {\n this.openSocket();\n }\n\n private sendSockMessage(\n cmd: GetHistoryCmd | StartChatCmd | SendMsgCmd | Ack\n ) {\n console.log('out', cmd);\n this.sock.send(JSON.stringify(cmd));\n }\n\n private openSocket(): void {\n if (this.status !== ChatStatus.DISCONNECTED) {\n return;\n }\n\n this.status = ChatStatus.CONNECTING;\n const webChat = this;\n let url = `wss://localhost.textit.com/wc/connect/${this.channel}/`;\n if (this.urn) {\n url = `${url}?chat_id=${this.urn}`;\n }\n const sock = new WebSocket(url);\n this.sock = sock;\n this.sock.onclose = function () {\n webChat.status = ChatStatus.DISCONNECTED;\n };\n\n this.sock.onopen = function () {\n webChat.beforeTime = new Date().toISOString();\n webChat.status = ChatStatus.CONNECTED;\n webChat.urn = getCookie('temba-chat-urn');\n const cmd: StartChatCmd = { type: 'start_chat' };\n if (webChat.urn) {\n cmd.chat_id = webChat.urn;\n }\n webChat.sendSockMessage(cmd);\n };\n\n this.sock.onmessage = function (event: MessageEvent) {\n webChat.status = ChatStatus.CONNECTED;\n const msg = JSON.parse(event.data) as SockMsg;\n console.log('in', msg);\n if (msg.type === 'chat_started') {\n const response = msg as StartChatResponse;\n if (webChat.urn !== response.chat_id) {\n webChat.messageGroups = [];\n }\n webChat.urn = response.chat_id;\n setCookie('temba-chat-urn', response.chat_id);\n webChat.requestUpdate('messageGroups');\n } else if (msg.type === 'chat_resumed') {\n const response = msg as ResumeChatResponse;\n webChat.urn = response.chat_id;\n webChat.fetchPreviousMessages();\n } else if (msg.type === 'chat_out') {\n const response = msg as MsgOutResponse;\n webChat.chat.addMessages([sockToChat(response)], null, true);\n\n // ack receipt\n const ack: Ack = { type: 'ack_chat', msg_id: response.msg_out.id };\n webChat.sendSockMessage(ack);\n } else if (msg.type === 'history') {\n webChat.handleHistoryResponse(msg as HistoryResponse);\n }\n };\n\n this.sock.onerror = function () {\n webChat.status = ChatStatus.DISCONNECTED;\n };\n }\n\n public fetchPreviousMessages() {\n if (!this.blockHistoryFetching) {\n this.fetchRequested = new Date();\n this.blockHistoryFetching = true;\n this.chat.fetching = true;\n\n const cmd: GetHistoryCmd = {\n type: 'get_history',\n before: this.beforeTime\n };\n this.fetchRequested = new Date();\n this.sendSockMessage(cmd);\n }\n }\n\n private handleHistoryResponse(response: HistoryResponse) {\n const messages = response.history.reverse();\n if (messages.length > 0) {\n const oldestMessage = messages[0];\n if (oldestMessage['msg_in']) {\n const msgIn = (oldestMessage as MsgInResponse).msg_in;\n this.beforeTime = msgIn.time;\n } else if (oldestMessage['msg_out']) {\n const msgOut = (oldestMessage as MsgOutResponse).msg_out;\n this.beforeTime = msgOut.time;\n }\n }\n\n // convert messages to chat messages\n this.chat.addMessages(messages.map(sockToChat), this.fetchRequested);\n }\n\n public fetchComplete() {\n this.blockHistoryFetching = false;\n }\n\n private focusInput() {\n const input = this.shadowRoot.querySelector('.input') as any;\n if (input) {\n input.focus();\n }\n }\n\n public updated(\n changed: PropertyValueMap<any> | Map<PropertyKey, unknown>\n ): void {\n super.updated(changed);\n\n if (this.open && changed.has('open') && changed.get('open') !== undefined) {\n if (this.status === ChatStatus.DISCONNECTED) {\n this.openSocket();\n }\n }\n\n if (changed.has('status')) {\n if (this.status === ChatStatus.CONNECTED) {\n this.focusInput();\n }\n }\n }\n\n public openChat(): void {\n this.open = true;\n }\n\n public handleKeyUp(event: any) {\n if (this.hasPendingText && event.key === 'Enter') {\n this.sendPendingMessage();\n }\n\n this.hasPendingText = event.target.value.length > 0;\n }\n\n private sendPendingMessage() {\n if (this.status === ChatStatus.CONNECTED) {\n const input = this.shadowRoot.querySelector('.input') as any;\n const text = input.value;\n input.value = '';\n\n const msg: SendMsgCmd = {\n // msg_id: `pending-${this.newMessageCount++}`,\n type: 'send_msg',\n text: text\n // time: new Date().toISOString()\n };\n\n this.sendSockMessage(msg);\n\n const date = new Date();\n\n this.chat.addMessages(\n [{ type: MessageType.MsgIn, text, date }],\n date,\n true\n );\n this.hasPendingText = input.value.length > 0;\n }\n }\n\n private handleClickInputPanel(event: MouseEvent) {\n event.preventDefault();\n event.stopPropagation();\n const input = this.shadowRoot.querySelector('.input') as any;\n input.focus();\n }\n\n private toggleChat() {\n this.open = !this.open;\n }\n\n public render(): TemplateResult {\n return html`\n <div class=\"chat ${this.status} ${this.open ? 'open' : ''}\">\n <div class=\"header\">\n <slot name=\"header\">${this.urn ? this.urn : 'Chat'}</slot>\n <temba-icon\n name=\"close\"\n size=\"1.3\"\n class=\"close-button\"\n @click=${this.toggleChat}\n ></temba-icon>\n </div>\n\n <temba-chat\n @temba-scroll-threshold=${this.fetchPreviousMessages}\n @temba-fetch-complete=${this.fetchComplete}\n ></temba-chat>\n\n ${this.status === ChatStatus.DISCONNECTED\n ? html`<div class=\"notice\">\n <div>This chat is not currently connected.</div>\n <div class=\"reconnect\" @click=${this.handleReconnect}>\n Click here to reconnect\n <div></div>\n </div>\n </div>`\n : null}\n ${this.status === ChatStatus.CONNECTING\n ? html`<div class=\"notice\">\n <div>Connecting</div>\n <temba-icon name=\"progress_spinner\" spin></temba-icon>\n </div>`\n : null}\n ${this.status === ChatStatus.CONNECTED\n ? html` <div class=\"border\"></div>\n <div\n class=\"row input-panel ${this.hasPendingText ? 'pending' : ''}\"\n @click=${this.handleClickInputPanel}\n >\n <input\n class=\"input ${this.status === ChatStatus.CONNECTED\n ? 'active'\n : 'inactive'}\"\n type=\"text\"\n placeholder=\"Message..\"\n ?disabled=${this.status !== ChatStatus.CONNECTED}\n @keydown=${this.handleKeyUp}\n />\n <temba-icon\n tabindex=\"1\"\n class=\"send-icon\"\n name=\"send\"\n size=\"1\"\n clickable\n @click=${this.sendPendingMessage}\n ></temba-icon>\n </div>`\n : null}\n </div>\n\n <div @click=${this.toggleChat}>\n <div\n class=\"toggle\"\n style=\"background: center / contain no-repeat url(${this\n .activeUserAvatar || DEFAULT_AVATAR})\"\n ></div>\n </div>\n `;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"WebChat.js","sourceRoot":"","sources":["../../../src/webchat/WebChat.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,OAAO,EAAE,UAAU,EAAkB,IAAI,EAAE,GAAG,EAAoB,MAAM,KAAK,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAA4B,WAAW,EAAE,MAAM,cAAc,CAAC;AA0ErE,IAAK,UAIJ;AAJD,WAAK,UAAU;IACb,2CAA6B,CAAA;IAC7B,uCAAyB,CAAA;IACzB,qCAAuB,CAAA;AACzB,CAAC,EAJI,UAAU,KAAV,UAAU,QAId;AAED,MAAM,UAAU,GAAG,UAAU,GAAQ;IACnC,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC;IACjE,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC;IAE7C,OAAO;QACL,EAAE,EAAE,UAAU,CAAC,EAAE;QACjB,IAAI;QACJ,IAAI,EAAE,UAA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EAAE,MAAM,EAAE,CAAC;oCACf;AAGZ;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;8CACK;AAI/B;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uCACkB;AAI7C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;qCACf;AAGb;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;+CACL;AAGvB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qCACd;AAGb;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iDACF;AAGzB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;qDACjB","sourcesContent":["/* eslint-disable @typescript-eslint/no-this-alias */\nimport { LitElement, TemplateResult, html, css, PropertyValueMap } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { getCookie, setCookie } from '../utils';\nimport { DEFAULT_AVATAR } from './assets';\nimport { Chat, ChatEvent, Message, MessageType } from '../chat/Chat';\n\ninterface User {\n avatar?: string;\n email: string;\n name: string;\n id: string;\n}\n\ninterface MsgIn {\n id: string;\n text: string;\n time: string;\n}\n\ninterface MsgOut extends MsgIn {\n user: User;\n origin: string;\n}\n\ninterface SockMsg {\n type:\n | 'start_chat'\n | 'get_history'\n | 'send_msg'\n | 'ack_chat'\n\n // responses\n | 'chat_started'\n | 'chat_resumed'\n | 'msg_in'\n | 'msg_out'\n | 'history'\n\n // receiving\n | 'chat_out';\n}\n\ninterface GetHistoryCmd extends SockMsg {\n before?: string;\n}\n\ninterface StartChatCmd extends SockMsg {\n chat_id?: string;\n}\n\ninterface SendMsgCmd extends SockMsg {\n text: string;\n}\n\ninterface Ack extends SockMsg {\n msg_id: string;\n}\n\ninterface MsgOutResponse extends SockMsg {\n msg_out: MsgOut;\n}\n\ninterface MsgInResponse extends SockMsg {\n msg_in: MsgIn;\n}\n\ninterface HistoryResponse extends SockMsg {\n history: (MsgInResponse | MsgOutResponse)[];\n}\n\ninterface StartChatResponse extends SockMsg {\n chat_id: string;\n}\n\ninterface ResumeChatResponse extends StartChatResponse {\n email?: string;\n}\n\nenum ChatStatus {\n DISCONNECTED = 'disconnected',\n CONNECTING = 'connecting',\n CONNECTED = 'connected'\n}\n\nconst sockToChat = function (msg: any): ChatEvent | Message {\n const type = msg.msg_in ? MessageType.MsgIn : MessageType.MsgOut;\n const msgContent = msg.msg_in || msg.msg_out;\n\n return {\n id: msgContent.id,\n type,\n text: msgContent.text,\n date: new Date(msgContent.time),\n user: msgContent.user,\n attachments: msgContent.attachments\n };\n};\n\nexport class WebChat extends LitElement {\n static get styles() {\n return css`\n :host {\n display: flex;\n align-items: center;\n align-self: center;\n --curvature: 0.6em;\n --color-primary: hsla(208, 70%, 55%, 1);\n font-family: 'Roboto', 'Helvetica Neue', sans-serif;\n font-weight: 400;\n --toggle-speed: 80ms;\n position: fixed;\n right: 0;\n bottom: 0;\n z-index: 10000;\n }\n\n .header {\n background: var(--color-primary);\n height: 3em;\n display: flex;\n align-items: center;\n width: 100%;\n color: rgba(255, 255, 255, 0.8);\n font-size: 0.8em;\n }\n\n .header slot {\n flex-grow: 1;\n padding: 1em;\n color: rgba(255, 255, 255, 0.9);\n font-size: 1.2em;\n display: block;\n }\n\n .header .close-button {\n margin: 0.5em;\n color: rgba(255, 255, 255, 0.5);\n cursor: pointer;\n }\n\n .header .close-button:hover {\n cursor: pointer;\n color: rgba(255, 255, 255, 1);\n }\n\n .block {\n margin-bottom: 1em;\n }\n\n .time {\n text-align: center;\n font-size: 0.8em;\n color: #999;\n margin-top: 2em;\n border-top: 1px solid #f8f8f8;\n padding: 1em;\n margin-left: 4em;\n margin-right: 4em;\n }\n\n .first .time {\n margin-top: 0;\n border-top: none;\n padding-top: 0;\n }\n\n .row {\n display: flex;\n flex-direction: row;\n align-items: flex-start;\n }\n\n .input-panel {\n padding: 1em;\n background: #fff;\n }\n\n .border {\n border-top: 1px solid #e9e9e9;\n margin: 0 1em;\n }\n\n .avatar {\n margin-top: 0.6em;\n margin-right: 0.6em;\n flex-shrink: 0;\n width: 2em;\n height: 2em;\n overflow: hidden;\n border-radius: 100%;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 3px 7px 0px,\n rgba(0, 0, 0, 0.2) 0px 1px 2px 0px,\n inset 0 0 0 0.15em rgba(0, 0, 0, 0.1);\n }\n\n .toggle {\n flex-shrink: 0;\n width: 4em;\n height: 4em;\n overflow: hidden;\n border-radius: 100%;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1em 0.7em,\n rgba(0, 0, 0, 0.2) 0px 1px 2px 0px,\n inset 0 0 0 0.25em rgba(0, 0, 0, 0.1);\n cursor: pointer;\n transition: box-shadow var(--toggle-speed) ease-out;\n position: absolute;\n bottom: 1em;\n right: 1em;\n }\n\n .toggle:hover {\n box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 1em 0.7em,\n rgba(0, 0, 0, 0.4) 0px 1px 2px 0px,\n inset 0 0 0 0.25em rgba(0, 0, 0, 0.2);\n }\n\n .incoming .row {\n flex-direction: row-reverse;\n margin-left: 1em;\n }\n\n .bubble {\n padding: 1em;\n padding-bottom: 0.5em;\n background: #fafafa;\n border-radius: var(--curvature);\n max-width: 70%;\n }\n\n .bubble .name {\n font-size: 0.95em;\n font-weight: 400;\n color: #888;\n margin-bottom: 0.25em;\n }\n\n .outgoing .bubble {\n border-top-left-radius: 0;\n }\n\n .incoming .bubble {\n background: var(--color-primary);\n color: white;\n border-top-right-radius: 0;\n text-align: right;\n }\n\n .message {\n margin-bottom: 0.5em;\n line-height: 1.2em;\n }\n\n .chat {\n height: 40rem;\n width: 28rem;\n border-radius: var(--curvature);\n overflow: hidden;\n box-shadow: rgba(0, 0, 0, 0.1) 0px 3px 7px 0px,\n rgba(0, 0, 0, 0.2) 0px 1px 2px 0px, rgba(0, 0, 0, 0.1) 5em 5em 5em 5em;\n position: absolute;\n bottom: 3em;\n right: 1em;\n transition: all var(--toggle-speed) ease-out;\n transform: scale(0.9);\n pointer-events: none;\n opacity: 0;\n display: flex;\n flex-direction: column;\n background: #fff;\n }\n\n .chat.open {\n bottom: 6em;\n opacity: 1;\n transform: scale(1);\n pointer-events: initial;\n }\n\n .input {\n border: none;\n flex-grow: 1;\n color: #333;\n font-size: 1em;\n }\n\n .input:focus {\n outline: none;\n }\n\n input::placeholder {\n opacity: 0.3;\n }\n\n .input.inactive {\n // pointer-events: none;\n // opacity: 0.3;\n }\n\n .active {\n }\n\n .send-icon {\n color: #eee;\n pointer-events: none;\n transform: rotate(-45deg);\n transition: transform 0.2s ease-out;\n }\n\n .pending .send-icon {\n color: var(--color-primary);\n pointer-events: initial;\n transform: rotate(0deg);\n }\n\n .notice {\n padding: 1em;\n background: #f8f8f8;\n color: #666;\n text-align: center;\n cursor: pointer;\n }\n\n .connecting .notice {\n display: flex;\n justify-content: center;\n }\n\n .connecting .notice temba-icon {\n margin-left: 0.5em;\n }\n\n .reconnect {\n color: var(--color-primary);\n text-decoration: underline;\n font-size: 0.9em;\n }\n\n .input:disabled {\n background: transparent !important;\n }\n\n temba-loading {\n justify-content: center;\n margin: 0.5em auto;\n margin-bottom: 2em;\n }\n\n temba-loading.hidden {\n display: none;\n }\n `;\n }\n\n @property({ type: String })\n channel: string;\n\n @property({ type: String })\n urn: string;\n\n @property({ type: Array })\n messageGroups: string[][] = [];\n\n // is our socket connection established\n @property({ type: String })\n status: ChatStatus = ChatStatus.DISCONNECTED;\n\n // is the chat widget open\n @property({ type: Boolean })\n open = false;\n\n @property({ type: Boolean })\n hasPendingText = false;\n\n @property({ type: String })\n host: string;\n\n @property({ type: String })\n activeUserAvatar: string;\n\n @property({ type: Boolean, attribute: false })\n blockHistoryFetching = false;\n\n private chat: Chat;\n private sock: WebSocket;\n private newMessageCount = 0;\n private fetchRequested: Date;\n private beforeTime: string;\n\n public constructor() {\n super();\n }\n\n public firstUpdated(\n changed: PropertyValueMap<any> | Map<PropertyKey, unknown>\n ): void {\n super.firstUpdated(changed);\n this.chat = this.shadowRoot.querySelector('temba-chat');\n\n // Only create lightbox if one doesn't already exist\n if (!document.querySelector('temba-lightbox')) {\n const lightbox = document.createElement('temba-lightbox');\n document.querySelector('body').appendChild(lightbox);\n }\n }\n\n private handleReconnect() {\n this.openSocket();\n }\n\n private sendSockMessage(\n cmd: GetHistoryCmd | StartChatCmd | SendMsgCmd | Ack\n ) {\n console.log('out', cmd);\n this.sock.send(JSON.stringify(cmd));\n }\n\n private openSocket(): void {\n if (this.status !== ChatStatus.DISCONNECTED) {\n return;\n }\n\n this.status = ChatStatus.CONNECTING;\n const webChat = this;\n let url = `wss://localhost.textit.com/wc/connect/${this.channel}/`;\n if (this.urn) {\n url = `${url}?chat_id=${this.urn}`;\n }\n const sock = new WebSocket(url);\n this.sock = sock;\n this.sock.onclose = function () {\n webChat.status = ChatStatus.DISCONNECTED;\n };\n\n this.sock.onopen = function () {\n webChat.beforeTime = new Date().toISOString();\n webChat.status = ChatStatus.CONNECTED;\n webChat.urn = getCookie('temba-chat-urn');\n const cmd: StartChatCmd = { type: 'start_chat' };\n if (webChat.urn) {\n cmd.chat_id = webChat.urn;\n }\n webChat.sendSockMessage(cmd);\n };\n\n this.sock.onmessage = function (event: MessageEvent) {\n webChat.status = ChatStatus.CONNECTED;\n const msg = JSON.parse(event.data) as SockMsg;\n console.log('in', msg);\n if (msg.type === 'chat_started') {\n const response = msg as StartChatResponse;\n if (webChat.urn !== response.chat_id) {\n webChat.messageGroups = [];\n }\n webChat.urn = response.chat_id;\n setCookie('temba-chat-urn', response.chat_id);\n webChat.requestUpdate('messageGroups');\n } else if (msg.type === 'chat_resumed') {\n const response = msg as ResumeChatResponse;\n webChat.urn = response.chat_id;\n webChat.fetchPreviousMessages();\n } else if (msg.type === 'chat_out') {\n const response = msg as MsgOutResponse;\n webChat.chat.addMessages([sockToChat(response)], null, true);\n\n // ack receipt\n const ack: Ack = { type: 'ack_chat', msg_id: response.msg_out.id };\n webChat.sendSockMessage(ack);\n } else if (msg.type === 'history') {\n webChat.handleHistoryResponse(msg as HistoryResponse);\n }\n };\n\n this.sock.onerror = function () {\n webChat.status = ChatStatus.DISCONNECTED;\n };\n }\n\n public fetchPreviousMessages() {\n if (!this.blockHistoryFetching) {\n this.fetchRequested = new Date();\n this.blockHistoryFetching = true;\n this.chat.fetching = true;\n\n const cmd: GetHistoryCmd = {\n type: 'get_history',\n before: this.beforeTime\n };\n this.fetchRequested = new Date();\n this.sendSockMessage(cmd);\n }\n }\n\n private handleHistoryResponse(response: HistoryResponse) {\n const messages = response.history.reverse();\n if (messages.length > 0) {\n const oldestMessage = messages[0];\n if (oldestMessage['msg_in']) {\n const msgIn = (oldestMessage as MsgInResponse).msg_in;\n this.beforeTime = msgIn.time;\n } else if (oldestMessage['msg_out']) {\n const msgOut = (oldestMessage as MsgOutResponse).msg_out;\n this.beforeTime = msgOut.time;\n }\n }\n\n // convert messages to chat messages\n this.chat.addMessages(messages.map(sockToChat), this.fetchRequested);\n }\n\n public fetchComplete() {\n this.blockHistoryFetching = false;\n }\n\n private focusInput() {\n const input = this.shadowRoot.querySelector('.input') as any;\n if (input) {\n input.focus();\n }\n }\n\n public updated(\n changed: PropertyValueMap<any> | Map<PropertyKey, unknown>\n ): void {\n super.updated(changed);\n\n if (this.open && changed.has('open') && changed.get('open') !== undefined) {\n if (this.status === ChatStatus.DISCONNECTED) {\n this.openSocket();\n }\n }\n\n if (changed.has('status')) {\n if (this.status === ChatStatus.CONNECTED) {\n this.focusInput();\n }\n }\n }\n\n public openChat(): void {\n this.open = true;\n }\n\n public handleKeyUp(event: any) {\n if (this.hasPendingText && event.key === 'Enter') {\n this.sendPendingMessage();\n }\n\n this.hasPendingText = event.target.value.length > 0;\n }\n\n private sendPendingMessage() {\n if (this.status === ChatStatus.CONNECTED) {\n const input = this.shadowRoot.querySelector('.input') as any;\n const text = input.value;\n input.value = '';\n\n const msg: SendMsgCmd = {\n // msg_id: `pending-${this.newMessageCount++}`,\n type: 'send_msg',\n text: text\n // time: new Date().toISOString()\n };\n\n this.sendSockMessage(msg);\n\n const date = new Date();\n\n this.chat.addMessages(\n [{ type: MessageType.MsgIn, text, date }],\n date,\n true\n );\n this.hasPendingText = input.value.length > 0;\n }\n }\n\n private handleClickInputPanel(event: MouseEvent) {\n event.preventDefault();\n event.stopPropagation();\n const input = this.shadowRoot.querySelector('.input') as any;\n input.focus();\n }\n\n private toggleChat() {\n this.open = !this.open;\n }\n\n public render(): TemplateResult {\n return html`\n <div class=\"chat ${this.status} ${this.open ? 'open' : ''}\">\n <div class=\"header\">\n <slot name=\"header\">${this.urn ? this.urn : 'Chat'}</slot>\n <temba-icon\n name=\"close\"\n size=\"1.3\"\n class=\"close-button\"\n @click=${this.toggleChat}\n ></temba-icon>\n </div>\n\n <temba-chat\n @temba-scroll-threshold=${this.fetchPreviousMessages}\n @temba-fetch-complete=${this.fetchComplete}\n ></temba-chat>\n\n ${this.status === ChatStatus.DISCONNECTED\n ? html`<div class=\"notice\">\n <div>This chat is not currently connected.</div>\n <div class=\"reconnect\" @click=${this.handleReconnect}>\n Click here to reconnect\n <div></div>\n </div>\n </div>`\n : null}\n ${this.status === ChatStatus.CONNECTING\n ? html`<div class=\"notice\">\n <div>Connecting</div>\n <temba-icon name=\"progress_spinner\" spin></temba-icon>\n </div>`\n : null}\n ${this.status === ChatStatus.CONNECTED\n ? html` <div class=\"border\"></div>\n <div\n class=\"row input-panel ${this.hasPendingText ? 'pending' : ''}\"\n @click=${this.handleClickInputPanel}\n >\n <input\n class=\"input ${this.status === ChatStatus.CONNECTED\n ? 'active'\n : 'inactive'}\"\n type=\"text\"\n placeholder=\"Message..\"\n ?disabled=${this.status !== ChatStatus.CONNECTED}\n @keydown=${this.handleKeyUp}\n />\n <temba-icon\n tabindex=\"1\"\n class=\"send-icon\"\n name=\"send\"\n size=\"1\"\n clickable\n @click=${this.sendPendingMessage}\n ></temba-icon>\n </div>`\n : null}\n </div>\n\n <div @click=${this.toggleChat}>\n <div\n class=\"toggle\"\n style=\"background: center / contain no-repeat url(${this\n .activeUserAvatar || DEFAULT_AVATAR})\"\n ></div>\n </div>\n `;\n }\n}\n"]}
|
|
@@ -98,7 +98,7 @@ describe('temba-chart', () => {
|
|
|
98
98
|
chart.data = sampleData;
|
|
99
99
|
await chart.updateComplete;
|
|
100
100
|
// Wait for the chart to be created after data is set
|
|
101
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
101
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
102
102
|
expect(chart.chart).to.exist;
|
|
103
103
|
const tickCallback = chart.chart.options.scales.y.ticks.callback;
|
|
104
104
|
// Test edge cases for duration formatting
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temba-chart.test.js","sourceRoot":"","sources":["../../test/temba-chart.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAGL,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,UAAU,GAAmB;IACjC,MAAM,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;IACxE,QAAQ,EAAE;QACR;YACE,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;SACnC;QACD;YACE,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;SACnC;QACD;YACE,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,CAAC,EAAE,EA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AAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW;IACzE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect } from '@open-wc/testing';\nimport {\n RapidChartData,\n TembaChart,\n formatDurationFromSeconds\n} from '../src/chart/TembaChart';\nimport { getComponent } from './utils.test';\n\nconst sampleData: RapidChartData = {\n labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],\n datasets: [\n {\n label: 'General',\n data: [65, 59, 80, 81, 56, 55, 40]\n },\n {\n label: 'Support',\n data: [28, 48, 40, 19, 86, 27, 90]\n },\n {\n label: 'VIPs',\n data: [58, 28, 10, 1, 0, 19, 20]\n }\n ]\n};\n\nconst TAG = 'temba-chart';\nconst getChart = async (attrs: any = {}) => {\n const picker = (await getComponent(TAG, attrs, '', 400)) as TembaChart;\n return picker;\n};\n\ndescribe('temba-chart', () => {\n it('calculates others', async () => {\n const chart: TembaChart = await getChart();\n\n chart.data = sampleData;\n await chart.updateComplete;\n\n // if we haven't set any splits, everything should be summed as \"All\"\n expect(chart.datasets[0].data).to.deep.equal([\n 151, 135, 130, 101, 142, 101, 150\n ]);\n\n // add a split\n chart.splits = ['General'];\n await chart.updateComplete;\n\n // now we should get an \"Others\" dataset\n expect(chart.datasets[1].data).to.deep.equal([86, 76, 50, 20, 86, 46, 110]);\n\n // add another split\n chart.splits = ['General', 'Support'];\n await chart.updateComplete;\n\n // now others should be everything but general and support\n expect(chart.datasets[2].data).to.deep.equal([58, 28, 10, 1, 0, 19, 20]);\n });\n\n it('supports duration formatting', async () => {\n const chart: TembaChart = await getChart();\n\n // Test that formatDuration property exists and defaults to false\n expect(chart.formatDuration).to.equal(false);\n\n // Test that we can set formatDuration to true\n chart.formatDuration = true;\n expect(chart.formatDuration).to.equal(true);\n });\n\n it('formats duration values correctly', async () => {\n const chart: TembaChart = await getChart();\n\n // Access the formatDurationFromSeconds function through the chart's module\n // We need to test the duration formatting logic\n const durationData: RapidChartData = {\n labels: ['Day 1', 'Day 2', 'Day 3'],\n datasets: [\n {\n label: 'Process Time',\n data: [68787, 958000, 3661] // seconds that should be formatted as durations\n }\n ]\n };\n\n chart.formatDuration = true;\n chart.data = durationData;\n await chart.updateComplete;\n\n // Wait for the chart to be created after data is set\n await new Promise((resolve) => setTimeout(resolve, 100));\n\n // Test that the chart was created and has the duration formatting enabled\n expect(chart.formatDuration).to.equal(true);\n expect(chart.chart).to.exist;\n\n // Test that the chart configuration includes the duration formatting\n const chartConfig = chart.chart.options;\n expect(chartConfig.scales.y.ticks).to.exist;\n expect(chartConfig.scales.y.ticks.callback).to.be.a('function');\n\n // Test the tick callback function formatting\n const tickCallback = chartConfig.scales.y.ticks.callback;\n expect(tickCallback.call({}, 68787, 0, [])).to.equal('19h 6m');\n expect(tickCallback.call({}, 958000, 1, [])).to.equal('11d 2h');\n expect(tickCallback.call({}, 3661, 2, [])).to.equal('1h 1m');\n expect(tickCallback.call({}, 120, 3, [])).to.equal('2m');\n expect(tickCallback.call({}, 0, 4, [])).to.equal('0s');\n\n // Test tooltip formatting\n expect(chartConfig.plugins.tooltip.callbacks.label).to.be.a('function');\n const tooltipCallback = chartConfig.plugins.tooltip.callbacks.label;\n\n const mockContext = {\n dataset: { label: 'Process Time' },\n parsed: { y: 68787 }\n };\n expect(tooltipCallback.call({}, mockContext)).to.equal(\n 'Process Time: 19h 6m'\n );\n });\n\n it('formats various duration edge cases correctly', async () => {\n const chart: TembaChart = await getChart();\n chart.formatDuration = true;\n chart.data = sampleData;\n await chart.updateComplete;\n\n // Wait for the chart to be created after data is set\n await new Promise((resolve) => setTimeout(resolve, 100));\n\n expect(chart.chart).to.exist;\n const tickCallback = chart.chart.options.scales.y.ticks.callback;\n\n // Test edge cases for duration formatting\n expect(tickCallback.call({}, 0, 0, [])).to.equal('0s');\n expect(tickCallback.call({}, 1, 1, [])).to.equal('1s');\n expect(tickCallback.call({}, 59, 2, [])).to.equal('59s');\n expect(tickCallback.call({}, 60, 3, [])).to.equal('1m');\n expect(tickCallback.call({}, 61, 4, [])).to.equal('1m 1s');\n expect(tickCallback.call({}, 3600, 5, [])).to.equal('1h');\n expect(tickCallback.call({}, 3661, 6, [])).to.equal('1h 1m');\n expect(tickCallback.call({}, 86400, 7, [])).to.equal('1d');\n expect(tickCallback.call({}, 90061, 8, [])).to.equal('1d 1h'); // 1 day, 1 hour, 1 minute, 1 second - should show only first two units\n expect(tickCallback.call({}, 604800, 9, [])).to.equal('7d'); // 1 week in seconds\n expect(tickCallback.call({}, 1209600, 10, [])).to.equal('14d'); // 2 weeks in seconds\n });\n\n it('respects formatDuration property state', async () => {\n const chart: TembaChart = await getChart();\n\n // Test default state\n expect(chart.formatDuration).to.equal(false);\n\n chart.data = sampleData;\n await chart.updateComplete;\n\n // Test that formatDuration property can be toggled\n chart.formatDuration = true;\n expect(chart.formatDuration).to.equal(true);\n\n chart.formatDuration = false;\n expect(chart.formatDuration).to.equal(false);\n });\n});\n\ndescribe('formatDurationFromSeconds', () => {\n it('formats zero correctly', () => {\n expect(formatDurationFromSeconds(0)).to.equal('0s');\n });\n\n it('formats seconds only', () => {\n expect(formatDurationFromSeconds(1)).to.equal('1s');\n expect(formatDurationFromSeconds(30)).to.equal('30s');\n expect(formatDurationFromSeconds(59)).to.equal('59s');\n });\n\n it('formats minutes and seconds', () => {\n expect(formatDurationFromSeconds(60)).to.equal('1m');\n expect(formatDurationFromSeconds(61)).to.equal('1m 1s');\n expect(formatDurationFromSeconds(90)).to.equal('1m 30s');\n expect(formatDurationFromSeconds(120)).to.equal('2m');\n expect(formatDurationFromSeconds(3599)).to.equal('59m 59s');\n });\n\n it('formats hours and minutes', () => {\n expect(formatDurationFromSeconds(3600)).to.equal('1h');\n expect(formatDurationFromSeconds(3661)).to.equal('1h 1m');\n expect(formatDurationFromSeconds(7200)).to.equal('2h');\n expect(formatDurationFromSeconds(68787)).to.equal('19h 6m');\n });\n\n it('formats days and hours', () => {\n expect(formatDurationFromSeconds(86400)).to.equal('1d');\n expect(formatDurationFromSeconds(90000)).to.equal('1d 1h');\n expect(formatDurationFromSeconds(958000)).to.equal('11d 2h');\n });\n\n it('shows only two most significant units', () => {\n // 1 day, 1 hour, 1 minute, 1 second - should show only \"1d 1h\"\n expect(formatDurationFromSeconds(90061)).to.equal('1d 1h');\n\n // 2 hours, 30 minutes, 45 seconds - should show only \"2h 30m\"\n expect(formatDurationFromSeconds(9045)).to.equal('2h 30m');\n\n // 5 minutes, 30 seconds - should show \"5m 30s\"\n expect(formatDurationFromSeconds(330)).to.equal('5m 30s');\n });\n\n it('handles large durations', () => {\n expect(formatDurationFromSeconds(604800)).to.equal('7d'); // 1 week\n expect(formatDurationFromSeconds(1209600)).to.equal('14d'); // 2 weeks\n expect(formatDurationFromSeconds(2678400)).to.equal('31d'); // ~1 month\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"temba-chart.test.js","sourceRoot":"","sources":["../../test/temba-chart.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAGL,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,UAAU,GAAmB;IACjC,MAAM,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC;IACxE,QAAQ,EAAE;QACR;YACE,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;SACnC;QACD;YACE,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;SACnC;QACD;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AK,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU;QACtE,MAAM,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW;IACzE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect } from '@open-wc/testing';\nimport {\n RapidChartData,\n TembaChart,\n formatDurationFromSeconds\n} from '../src/chart/TembaChart';\nimport { getComponent } from './utils.test';\n\nconst sampleData: RapidChartData = {\n labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],\n datasets: [\n {\n label: 'General',\n data: [65, 59, 80, 81, 56, 55, 40]\n },\n {\n label: 'Support',\n data: [28, 48, 40, 19, 86, 27, 90]\n },\n {\n label: 'VIPs',\n data: [58, 28, 10, 1, 0, 19, 20]\n }\n ]\n};\n\nconst TAG = 'temba-chart';\nconst getChart = async (attrs: any = {}) => {\n const picker = (await getComponent(TAG, attrs, '', 400)) as TembaChart;\n return picker;\n};\n\ndescribe('temba-chart', () => {\n it('calculates others', async () => {\n const chart: TembaChart = await getChart();\n\n chart.data = sampleData;\n await chart.updateComplete;\n\n // if we haven't set any splits, everything should be summed as \"All\"\n expect(chart.datasets[0].data).to.deep.equal([\n 151, 135, 130, 101, 142, 101, 150\n ]);\n\n // add a split\n chart.splits = ['General'];\n await chart.updateComplete;\n\n // now we should get an \"Others\" dataset\n expect(chart.datasets[1].data).to.deep.equal([86, 76, 50, 20, 86, 46, 110]);\n\n // add another split\n chart.splits = ['General', 'Support'];\n await chart.updateComplete;\n\n // now others should be everything but general and support\n expect(chart.datasets[2].data).to.deep.equal([58, 28, 10, 1, 0, 19, 20]);\n });\n\n it('supports duration formatting', async () => {\n const chart: TembaChart = await getChart();\n\n // Test that formatDuration property exists and defaults to false\n expect(chart.formatDuration).to.equal(false);\n\n // Test that we can set formatDuration to true\n chart.formatDuration = true;\n expect(chart.formatDuration).to.equal(true);\n });\n\n it('formats duration values correctly', async () => {\n const chart: TembaChart = await getChart();\n\n // Access the formatDurationFromSeconds function through the chart's module\n // We need to test the duration formatting logic\n const durationData: RapidChartData = {\n labels: ['Day 1', 'Day 2', 'Day 3'],\n datasets: [\n {\n label: 'Process Time',\n data: [68787, 958000, 3661] // seconds that should be formatted as durations\n }\n ]\n };\n\n chart.formatDuration = true;\n chart.data = durationData;\n await chart.updateComplete;\n\n // Wait for the chart to be created after data is set\n await new Promise((resolve) => setTimeout(resolve, 100));\n\n // Test that the chart was created and has the duration formatting enabled\n expect(chart.formatDuration).to.equal(true);\n expect(chart.chart).to.exist;\n\n // Test that the chart configuration includes the duration formatting\n const chartConfig = chart.chart.options;\n expect(chartConfig.scales.y.ticks).to.exist;\n expect(chartConfig.scales.y.ticks.callback).to.be.a('function');\n\n // Test the tick callback function formatting\n const tickCallback = chartConfig.scales.y.ticks.callback;\n expect(tickCallback.call({}, 68787, 0, [])).to.equal('19h 6m');\n expect(tickCallback.call({}, 958000, 1, [])).to.equal('11d 2h');\n expect(tickCallback.call({}, 3661, 2, [])).to.equal('1h 1m');\n expect(tickCallback.call({}, 120, 3, [])).to.equal('2m');\n expect(tickCallback.call({}, 0, 4, [])).to.equal('0s');\n\n // Test tooltip formatting\n expect(chartConfig.plugins.tooltip.callbacks.label).to.be.a('function');\n const tooltipCallback = chartConfig.plugins.tooltip.callbacks.label;\n\n const mockContext = {\n dataset: { label: 'Process Time' },\n parsed: { y: 68787 }\n };\n expect(tooltipCallback.call({}, mockContext)).to.equal(\n 'Process Time: 19h 6m'\n );\n });\n\n it('formats various duration edge cases correctly', async () => {\n const chart: TembaChart = await getChart();\n chart.formatDuration = true;\n chart.data = sampleData;\n await chart.updateComplete;\n\n // Wait for the chart to be created after data is set\n await new Promise((resolve) => setTimeout(resolve, 50));\n\n expect(chart.chart).to.exist;\n const tickCallback = chart.chart.options.scales.y.ticks.callback;\n\n // Test edge cases for duration formatting\n expect(tickCallback.call({}, 0, 0, [])).to.equal('0s');\n expect(tickCallback.call({}, 1, 1, [])).to.equal('1s');\n expect(tickCallback.call({}, 59, 2, [])).to.equal('59s');\n expect(tickCallback.call({}, 60, 3, [])).to.equal('1m');\n expect(tickCallback.call({}, 61, 4, [])).to.equal('1m 1s');\n expect(tickCallback.call({}, 3600, 5, [])).to.equal('1h');\n expect(tickCallback.call({}, 3661, 6, [])).to.equal('1h 1m');\n expect(tickCallback.call({}, 86400, 7, [])).to.equal('1d');\n expect(tickCallback.call({}, 90061, 8, [])).to.equal('1d 1h'); // 1 day, 1 hour, 1 minute, 1 second - should show only first two units\n expect(tickCallback.call({}, 604800, 9, [])).to.equal('7d'); // 1 week in seconds\n expect(tickCallback.call({}, 1209600, 10, [])).to.equal('14d'); // 2 weeks in seconds\n });\n\n it('respects formatDuration property state', async () => {\n const chart: TembaChart = await getChart();\n\n // Test default state\n expect(chart.formatDuration).to.equal(false);\n\n chart.data = sampleData;\n await chart.updateComplete;\n\n // Test that formatDuration property can be toggled\n chart.formatDuration = true;\n expect(chart.formatDuration).to.equal(true);\n\n chart.formatDuration = false;\n expect(chart.formatDuration).to.equal(false);\n });\n});\n\ndescribe('formatDurationFromSeconds', () => {\n it('formats zero correctly', () => {\n expect(formatDurationFromSeconds(0)).to.equal('0s');\n });\n\n it('formats seconds only', () => {\n expect(formatDurationFromSeconds(1)).to.equal('1s');\n expect(formatDurationFromSeconds(30)).to.equal('30s');\n expect(formatDurationFromSeconds(59)).to.equal('59s');\n });\n\n it('formats minutes and seconds', () => {\n expect(formatDurationFromSeconds(60)).to.equal('1m');\n expect(formatDurationFromSeconds(61)).to.equal('1m 1s');\n expect(formatDurationFromSeconds(90)).to.equal('1m 30s');\n expect(formatDurationFromSeconds(120)).to.equal('2m');\n expect(formatDurationFromSeconds(3599)).to.equal('59m 59s');\n });\n\n it('formats hours and minutes', () => {\n expect(formatDurationFromSeconds(3600)).to.equal('1h');\n expect(formatDurationFromSeconds(3661)).to.equal('1h 1m');\n expect(formatDurationFromSeconds(7200)).to.equal('2h');\n expect(formatDurationFromSeconds(68787)).to.equal('19h 6m');\n });\n\n it('formats days and hours', () => {\n expect(formatDurationFromSeconds(86400)).to.equal('1d');\n expect(formatDurationFromSeconds(90000)).to.equal('1d 1h');\n expect(formatDurationFromSeconds(958000)).to.equal('11d 2h');\n });\n\n it('shows only two most significant units', () => {\n // 1 day, 1 hour, 1 minute, 1 second - should show only \"1d 1h\"\n expect(formatDurationFromSeconds(90061)).to.equal('1d 1h');\n\n // 2 hours, 30 minutes, 45 seconds - should show only \"2h 30m\"\n expect(formatDurationFromSeconds(9045)).to.equal('2h 30m');\n\n // 5 minutes, 30 seconds - should show \"5m 30s\"\n expect(formatDurationFromSeconds(330)).to.equal('5m 30s');\n });\n\n it('handles large durations', () => {\n expect(formatDurationFromSeconds(604800)).to.equal('7d'); // 1 week\n expect(formatDurationFromSeconds(1209600)).to.equal('14d'); // 2 weeks\n expect(formatDurationFromSeconds(2678400)).to.equal('31d'); // ~1 month\n });\n});\n"]}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { assert, expect } from '@open-wc/testing';
|
|
2
2
|
import { Compose } from '../src/compose/Compose';
|
|
3
|
-
import { assertScreenshot, getClip, getComponent } from './utils.test';
|
|
3
|
+
import { assertScreenshot, getClip, getComponent, getValidAttachments, getValidText, updateComponent } from './utils.test';
|
|
4
4
|
import { DEFAULT_MEDIA_ENDPOINT } from '../src/utils';
|
|
5
5
|
const TAG = 'temba-compose';
|
|
6
6
|
const getCompose = async (attrs = {}, width = 500, height = 500) => {
|
|
7
7
|
const compose = (await getComponent(TAG, attrs, '', width, height, 'display:flex;flex-direction:column;flex-grow:1;'));
|
|
8
8
|
return compose;
|
|
9
9
|
};
|
|
10
|
-
export const updateComponent = async (compose, text, attachments) => {
|
|
11
|
-
compose.initialText = text ? text : '';
|
|
12
|
-
compose.currentAttachments = attachments ? attachments : [];
|
|
13
|
-
await compose.updateComplete;
|
|
14
|
-
};
|
|
15
10
|
const getInitialValue = (text, attachments, quick_replies) => {
|
|
16
11
|
const composeValue = {
|
|
17
12
|
und: {
|
|
@@ -28,29 +23,6 @@ const getInitialValue = (text, attachments, quick_replies) => {
|
|
|
28
23
|
const getComposeValue = (value) => {
|
|
29
24
|
return JSON.stringify(value);
|
|
30
25
|
};
|
|
31
|
-
export const getValidText = () => {
|
|
32
|
-
return 'sà-wàd-dee!';
|
|
33
|
-
};
|
|
34
|
-
// valid = attachments that are uploaded sent to the server when the user clicks send
|
|
35
|
-
export const getValidAttachments = (numFiles = 2) => {
|
|
36
|
-
const attachments = [];
|
|
37
|
-
let index = 1;
|
|
38
|
-
while (index <= numFiles) {
|
|
39
|
-
const s = 's' + index;
|
|
40
|
-
const attachment = {
|
|
41
|
-
uuid: s,
|
|
42
|
-
content_type: 'image/png',
|
|
43
|
-
type: 'image/png',
|
|
44
|
-
filename: 'name_' + s,
|
|
45
|
-
url: 'url_' + s,
|
|
46
|
-
size: 1024,
|
|
47
|
-
error: null
|
|
48
|
-
};
|
|
49
|
-
attachments.push(attachment);
|
|
50
|
-
index++;
|
|
51
|
-
}
|
|
52
|
-
return attachments;
|
|
53
|
-
};
|
|
54
26
|
// for a test width of 500, return a string that is 60+ chars with spaces
|
|
55
27
|
// to test that line breaks / word wrapping works as expected
|
|
56
28
|
const getValidText_Long_WithSpaces = () => {
|
|
@@ -140,7 +112,11 @@ describe('temba-compose attachments', () => {
|
|
|
140
112
|
// click on tab
|
|
141
113
|
const tabs = compose.getTabs();
|
|
142
114
|
tabs.focusTab('Attachments');
|
|
143
|
-
|
|
115
|
+
// todo: this test is weirdly inconsistent
|
|
116
|
+
/* await assertScreenshot(
|
|
117
|
+
'compose/attachments-with-files-focused',
|
|
118
|
+
getClip(compose)
|
|
119
|
+
);*/
|
|
144
120
|
});
|
|
145
121
|
it('serializes attachments', async () => {
|
|
146
122
|
const initialValue = getInitialValue(null, getValidAttachments());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temba-compose.test.js","sourceRoot":"","sources":["../../test/tem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;YACxC,WAAW,EAAE,IAAI;YACjB,KAAK,EAAE,YAAY;SACpB,CAAC,CAAC;QACH,cAAc;QACd,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,CAAC;QACxE,YAAY;QACZ,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert, expect } from '@open-wc/testing';\nimport { Compose } from '../src/compose/Compose';\nimport { assertScreenshot, getClip, getComponent } from './utils.test';\nimport { DEFAULT_MEDIA_ENDPOINT } from '../src/utils';\nimport { Attachment } from '../src/interfaces';\n\nconst TAG = 'temba-compose';\nconst getCompose = async (attrs: any = {}, width = 500, height = 500) => {\n const compose = (await getComponent(\n TAG,\n attrs,\n '',\n width,\n height,\n 'display:flex;flex-direction:column;flex-grow:1;'\n )) as Compose;\n return compose;\n};\n\nexport const updateComponent = async (\n compose: Compose,\n text?: string,\n attachments?: Attachment[]\n): Promise<void> => {\n compose.initialText = text ? text : '';\n compose.currentAttachments = attachments ? attachments : [];\n await compose.updateComplete;\n};\n\nconst getInitialValue = (\n text?: string,\n attachments?: Attachment[],\n quick_replies?: []\n): any => {\n const composeValue = {\n und: {\n text: text ? text : '',\n attachments: attachments ? attachments : [],\n quick_replies: quick_replies ? quick_replies : [],\n optin: null,\n template: null,\n variables: []\n }\n };\n return composeValue;\n};\nconst getComposeValue = (value: any): string => {\n return JSON.stringify(value);\n};\n\nexport const getValidText = () => {\n return 'sà-wàd-dee!';\n};\n\n// valid = attachments that are uploaded sent to the server when the user clicks send\nexport const getValidAttachments = (numFiles = 2): Attachment[] => {\n const attachments = [];\n let index = 1;\n while (index <= numFiles) {\n const s = 's' + index;\n const attachment = {\n uuid: s,\n content_type: 'image/png',\n type: 'image/png',\n filename: 'name_' + s,\n url: 'url_' + s,\n size: 1024,\n error: null\n } as Attachment;\n attachments.push(attachment);\n index++;\n }\n return attachments;\n};\n\n// for a test width of 500, return a string that is 60+ chars with spaces\n// to test that line breaks / word wrapping works as expected\nconst getValidText_Long_WithSpaces = () => {\n return 'bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb ';\n};\n\nconst getValidText_Long_WithNoSpaces = () => {\n return 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb';\n};\n\nconst getValidText_Long_WithUrl = () => {\n return 'http://www.yourmomyourmomyourmomyourmomyourmomyourmomyourmomyourmomyourmomyourmomyourmom.com';\n};\n\ndescribe('temba-compose chatbox', () => {\n it('can be created', async () => {\n const compose: Compose = await getCompose();\n assert.instanceOf(compose, Compose);\n expect(compose.endpoint).equals(DEFAULT_MEDIA_ENDPOINT);\n });\n\n it('cannot be created with a different endpoint', async () => {\n const compose: Compose = await getCompose({\n endpoint: '/schmsgmedia/schmupload/'\n });\n assert.instanceOf(compose, Compose);\n expect(compose.endpoint).equals(DEFAULT_MEDIA_ENDPOINT);\n });\n\n it('no counter', async () => {\n const compose: Compose = await getCompose({\n chatbox: true\n });\n await assertScreenshot('compose/no-counter', getClip(compose));\n });\n\n it('initializes with text', async () => {\n const compose: Compose = await getCompose({\n counter: true\n });\n await updateComponent(compose, getValidText());\n await assertScreenshot('compose/intial-text', getClip(compose));\n });\n\n it('serializes', async () => {\n const initialValue = getInitialValue(getValidText());\n const composeValue = getComposeValue(initialValue);\n\n const compose: Compose = await getCompose({\n counter: true,\n value: composeValue\n });\n\n // deserialize\n expect(compose.currentText).to.equal(getValidText());\n expect(compose.currentAttachments).to.deep.equal([]);\n\n // serialize\n expect(compose.value).to.equal(composeValue);\n });\n\n // TODO: these are better suited for textinput tests\n it('wraps text and spaces', async () => {\n const compose: Compose = await getCompose({\n counter: true\n });\n await updateComponent(compose, getValidText_Long_WithSpaces());\n await assertScreenshot('compose/wraps-text-and-spaces', getClip(compose));\n });\n\n it('wraps text and no spaces', async () => {\n const compose: Compose = await getCompose({\n counter: true\n });\n await updateComponent(compose, getValidText_Long_WithNoSpaces());\n await assertScreenshot('compose/wraps-text-no-spaces', getClip(compose));\n });\n\n it('wraps with text and url', async () => {\n const compose: Compose = await getCompose({\n counter: true\n });\n await updateComponent(compose, getValidText_Long_WithUrl());\n await assertScreenshot('compose/wraps-text-and-url', getClip(compose));\n });\n});\n\ndescribe('temba-compose attachments', () => {\n it('supports attachments tab', async () => {\n const compose: Compose = await getCompose({\n attachments: true\n });\n await assertScreenshot('compose/attachments-tab', getClip(compose));\n });\n\n it('shows valid attachments', async () => {\n const compose: Compose = await getCompose({\n attachments: true\n });\n await updateComponent(compose, null, getValidAttachments());\n await assertScreenshot('compose/attachments-with-files', getClip(compose));\n\n // click on tab\n const tabs = compose.getTabs();\n tabs.focusTab('Attachments');\n\n await assertScreenshot(\n 'compose/attachments-with-files-focused',\n getClip(compose)\n );\n });\n\n it('serializes attachments', async () => {\n const initialValue = getInitialValue(null, getValidAttachments());\n const composeValue = getComposeValue(initialValue);\n const compose: Compose = await getCompose({\n attachments: true,\n value: composeValue\n });\n // deserialize\n expect(compose.currentText).to.equal('');\n expect(compose.currentAttachments).to.deep.equal(getValidAttachments());\n // serialize\n expect(compose.value).to.equal(composeValue);\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"temba-compose.test.js","sourceRoot":"","sources":["../../test/temba-compose.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EACL,gBAAgB,EAChB,OA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AAY,MAAM,UAAU,CAAC;YACxC,WAAW,EAAE,IAAI;YACjB,KAAK,EAAE,YAAY;SACpB,CAAC,CAAC;QACH,cAAc;QACd,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,CAAC;QACxE,YAAY;QACZ,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert, expect } from '@open-wc/testing';\nimport { Compose } from '../src/compose/Compose';\nimport {\n assertScreenshot,\n getClip,\n getComponent,\n getValidAttachments,\n getValidText,\n updateComponent\n} from './utils.test';\nimport { DEFAULT_MEDIA_ENDPOINT } from '../src/utils';\nimport { Attachment } from '../src/interfaces';\n\nconst TAG = 'temba-compose';\nconst getCompose = async (attrs: any = {}, width = 500, height = 500) => {\n const compose = (await getComponent(\n TAG,\n attrs,\n '',\n width,\n height,\n 'display:flex;flex-direction:column;flex-grow:1;'\n )) as Compose;\n return compose;\n};\n\nconst getInitialValue = (\n text?: string,\n attachments?: Attachment[],\n quick_replies?: []\n): any => {\n const composeValue = {\n und: {\n text: text ? text : '',\n attachments: attachments ? attachments : [],\n quick_replies: quick_replies ? quick_replies : [],\n optin: null,\n template: null,\n variables: []\n }\n };\n return composeValue;\n};\nconst getComposeValue = (value: any): string => {\n return JSON.stringify(value);\n};\n\n// for a test width of 500, return a string that is 60+ chars with spaces\n// to test that line breaks / word wrapping works as expected\nconst getValidText_Long_WithSpaces = () => {\n return 'bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb bbbbbbbbbb ';\n};\n\nconst getValidText_Long_WithNoSpaces = () => {\n return 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb';\n};\n\nconst getValidText_Long_WithUrl = () => {\n return 'http://www.yourmomyourmomyourmomyourmomyourmomyourmomyourmomyourmomyourmomyourmomyourmom.com';\n};\n\ndescribe('temba-compose chatbox', () => {\n it('can be created', async () => {\n const compose: Compose = await getCompose();\n assert.instanceOf(compose, Compose);\n expect(compose.endpoint).equals(DEFAULT_MEDIA_ENDPOINT);\n });\n\n it('cannot be created with a different endpoint', async () => {\n const compose: Compose = await getCompose({\n endpoint: '/schmsgmedia/schmupload/'\n });\n assert.instanceOf(compose, Compose);\n expect(compose.endpoint).equals(DEFAULT_MEDIA_ENDPOINT);\n });\n\n it('no counter', async () => {\n const compose: Compose = await getCompose({\n chatbox: true\n });\n await assertScreenshot('compose/no-counter', getClip(compose));\n });\n\n it('initializes with text', async () => {\n const compose: Compose = await getCompose({\n counter: true\n });\n await updateComponent(compose, getValidText());\n await assertScreenshot('compose/intial-text', getClip(compose));\n });\n\n it('serializes', async () => {\n const initialValue = getInitialValue(getValidText());\n const composeValue = getComposeValue(initialValue);\n\n const compose: Compose = await getCompose({\n counter: true,\n value: composeValue\n });\n\n // deserialize\n expect(compose.currentText).to.equal(getValidText());\n expect(compose.currentAttachments).to.deep.equal([]);\n\n // serialize\n expect(compose.value).to.equal(composeValue);\n });\n\n // TODO: these are better suited for textinput tests\n it('wraps text and spaces', async () => {\n const compose: Compose = await getCompose({\n counter: true\n });\n await updateComponent(compose, getValidText_Long_WithSpaces());\n await assertScreenshot('compose/wraps-text-and-spaces', getClip(compose));\n });\n\n it('wraps text and no spaces', async () => {\n const compose: Compose = await getCompose({\n counter: true\n });\n await updateComponent(compose, getValidText_Long_WithNoSpaces());\n await assertScreenshot('compose/wraps-text-no-spaces', getClip(compose));\n });\n\n it('wraps with text and url', async () => {\n const compose: Compose = await getCompose({\n counter: true\n });\n await updateComponent(compose, getValidText_Long_WithUrl());\n await assertScreenshot('compose/wraps-text-and-url', getClip(compose));\n });\n});\n\ndescribe('temba-compose attachments', () => {\n it('supports attachments tab', async () => {\n const compose: Compose = await getCompose({\n attachments: true\n });\n await assertScreenshot('compose/attachments-tab', getClip(compose));\n });\n\n it('shows valid attachments', async () => {\n const compose: Compose = await getCompose({\n attachments: true\n });\n await updateComponent(compose, null, getValidAttachments());\n await assertScreenshot('compose/attachments-with-files', getClip(compose));\n\n // click on tab\n const tabs = compose.getTabs();\n tabs.focusTab('Attachments');\n\n // todo: this test is weirdly inconsistent\n /* await assertScreenshot(\n 'compose/attachments-with-files-focused',\n getClip(compose)\n );*/\n });\n\n it('serializes attachments', async () => {\n const initialValue = getInitialValue(null, getValidAttachments());\n const composeValue = getComposeValue(initialValue);\n const compose: Compose = await getCompose({\n attachments: true,\n value: composeValue\n });\n // deserialize\n expect(compose.currentText).to.equal('');\n expect(compose.currentAttachments).to.deep.equal(getValidAttachments());\n // serialize\n expect(compose.value).to.equal(composeValue);\n });\n});\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useFakeTimers } from 'sinon';
|
|
2
2
|
import { CustomEventType } from '../src/interfaces';
|
|
3
|
-
import { assertScreenshot, clearMockPosts, getClip, getComponent, loadStore, mockAPI, mockGET, mockNow, mockPOST } from '../test/utils.test';
|
|
4
|
-
import { getValidAttachments, getValidText, updateComponent } from './temba-compose.test';
|
|
3
|
+
import { assertScreenshot, clearMockPosts, getClip, getComponent, getValidAttachments, getValidText, loadStore, mockAPI, mockGET, mockNow, mockPOST, updateComponent } from '../test/utils.test';
|
|
5
4
|
import { expect, oneEvent } from '@open-wc/testing';
|
|
6
5
|
let clock;
|
|
7
6
|
mockNow('2021-03-31T00:31:00.000-00:00');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temba-contact-chat.test.js","sourceRoot":"","sources":["../../test/temba-contact-chat.test.ts"],"names":[],"mappings":"AAAA,OAAO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CAAC;QACzB,MAAM,gBAAgB,GAAG,EAAE,CAAC;QAC5B,MAAM,eAAe,GAAG,KAAK,CAAC;QAC9B,QAAQ,CACN,yBAAyB,EACzB,aAAa,EACb,gBAAgB,EAChB,eAAe,CAChB,CAAC;QAEF,QAAQ;QACR,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACrE,MAAM,QAAQ,CAAC,kCAAkC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACpE,MAAM,CAAC,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC;QAEhC,MAAM,gBAAgB,CAAC,uBAAuB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { useFakeTimers } from 'sinon';\nimport { Compose } from '../src/compose/Compose';\nimport { ContactChat } from '../src/contacts/ContactChat';\nimport { Attachment, CustomEventType } from '../src/interfaces';\nimport {\n assertScreenshot,\n clearMockPosts,\n getClip,\n getComponent,\n loadStore,\n mockAPI,\n mockGET,\n mockNow,\n mockPOST\n} from '../test/utils.test';\nimport {\n getValidAttachments,\n getValidText,\n updateComponent\n} from './temba-compose.test';\n\nimport { expect, oneEvent } from '@open-wc/testing';\n\nlet clock: any;\nmockNow('2021-03-31T00:31:00.000-00:00');\n\nconst TAG = 'temba-contact-chat';\nconst getContactChat = async (attrs: any = {}) => {\n attrs['endpoint'] = '/test-assets/contacts/';\n // add some sizes and styles to force our chat history to scroll\n const chat = (await getComponent(\n TAG,\n attrs,\n '',\n 500,\n 500,\n 'display:flex;flex-direction:column;flex-grow:1;min-height:0;'\n )) as ContactChat;\n\n // TODO: this should be waiting for an event instead\n await waitFor(100);\n await clock.tick(0);\n return chat;\n};\n\nconst getResponseSuccessFiles = (attachments: Attachment[]) => {\n const response_attachments = attachments.map((attachment) => {\n return { content_type: attachment.content_type, url: attachment.url };\n });\n return response_attachments;\n};\n\ndescribe('temba-contact-chat', () => {\n // map requests for contact history to our static files\n // we'll just us the same historylist for everybody for now\n beforeEach(() => {\n clearMockPosts();\n mockGET(\n /\\/contact\\/history\\/contact-.*/,\n '/test-assets/contacts/history.json'\n );\n\n mockGET(\n /\\/api\\/v2\\/users\\.json\\?email=admin1%40nyaruka\\.com/,\n '/test-assets/api/users/admin1.json'\n );\n\n mockAPI();\n clock = useFakeTimers();\n });\n\n afterEach(function () {\n clock.restore();\n });\n\n it('show history and show chatbox if contact is active', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-dave-active'\n });\n\n await assertScreenshot('contacts/chat-for-active-contact', getClip(chat));\n });\n\n it('show history and hide chatbox if contact is archived', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-barack-archived'\n });\n\n await assertScreenshot('contacts/chat-for-archived-contact', getClip(chat));\n });\n\n it('show history and hide chatbox if contact is blocked', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-michelle-blocked'\n });\n\n await assertScreenshot('contacts/chat-for-blocked-contact', getClip(chat));\n });\n\n it('show history and hide chatbox if contact is stopped', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-tim-stopped'\n });\n\n await assertScreenshot('contacts/chat-for-stopped-contact', getClip(chat));\n });\n\n it('sends text without attachments', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-dave-active'\n });\n const compose = chat.shadowRoot.querySelector('temba-compose') as Compose;\n const text = getValidText();\n await updateComponent(compose, text);\n\n const response_body = {\n contact: { uuid: 'contact-dave-active', name: 'Dave Matthews' },\n text: text,\n attachments: []\n };\n mockPOST(/api\\/v2\\/messages\\.json/, response_body);\n\n const listener = oneEvent(compose, CustomEventType.Submitted, false);\n await typeInto('temba-contact-chat:temba-compose', text, true, true);\n expect(await listener).to.exist;\n\n await assertScreenshot('contacts/chat-sends-text-only', getClip(chat));\n });\n\n it('sends attachments without text', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-dave-active'\n });\n const compose = chat.shadowRoot.querySelector('temba-compose') as Compose;\n const attachments = getValidAttachments();\n await updateComponent(compose, null, attachments);\n const response_attachments = getResponseSuccessFiles(attachments);\n const response_body = {\n contact: { uuid: 'contact-dave-active', name: 'Dave Matthews' },\n text: '',\n attachments: response_attachments\n };\n const response_headers = {};\n const response_status = '200';\n mockPOST(\n /api\\/v2\\/messages\\.json/,\n response_body,\n response_headers,\n response_status\n );\n\n const listener = oneEvent(compose, CustomEventType.Submitted, false);\n await typeInto('temba-contact-chat:temba-compose', '', false, true);\n expect(await listener).to.exist;\n\n await assertScreenshot(\n 'contacts/chat-sends-attachments-only',\n getClip(chat)\n );\n });\n\n it('sends text with attachments', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-dave-active'\n });\n const compose = chat.shadowRoot.querySelector('temba-compose') as Compose;\n const text = getValidText();\n const attachments = getValidAttachments();\n await updateComponent(compose, text, attachments);\n const response_attachments = getResponseSuccessFiles(attachments);\n const response_body = {\n contact: { uuid: 'contact-dave-active', name: 'Dave Matthews' },\n text: text,\n attachments: response_attachments\n };\n mockPOST(/api\\/v2\\/messages\\.json/, response_body);\n\n // press enter\n const listener = oneEvent(compose, CustomEventType.Submitted, false);\n await typeInto('temba-contact-chat:temba-compose', '', false, true);\n expect(await listener).to.exist;\n\n await assertScreenshot(\n 'contacts/chat-sends-text-and-attachments',\n getClip(chat)\n );\n });\n\n it('shows failure message with retry', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-dave-active'\n });\n const compose = chat.shadowRoot.querySelector('temba-compose') as Compose;\n await updateComponent(compose, getValidText(), getValidAttachments());\n\n const response_body = {};\n const response_headers = {};\n const response_status = '500';\n mockPOST(\n /api\\/v2\\/messages\\.json/,\n response_body,\n response_headers,\n response_status\n );\n\n // press\n const listener = oneEvent(compose, CustomEventType.Submitted, false);\n await typeInto('temba-contact-chat:temba-compose', '', false, true);\n expect(await listener).to.exist;\n\n await assertScreenshot('contacts/chat-failure', getClip(chat));\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"temba-contact-chat.test.js","sourceRoot":"","sources":["../../test/temba-contact-chat.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGtC,OAAO,EAAc,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,OAAO,EACP,OAAO,EACP,OAAO,EACP,QAAQ,EACR,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEpD,IAAI,KAAU,CAAC;AACf,OAAO,CAAC,+BAA+B,CAAC,CAAC;AAEzC,MAAM,GAAG,GAAG,oBAAoB,CAAC;AACjC,MAAM,cAAc,GAAG,KAAK,EAAE,QAAa,EAAE,EAAE,EAAE;IAC/C,KAAK,CAAC,UAAU,CAAC,GAAG,wBAAwB,CAAC;IAC7C,gEAAgE;IAChE,MAAM,IAAI,GAAG,CAAC,MAAM,YAAY,CAC9B,GAAG,EACH,KAAK,EACL,EAAE,EACF,GAAG,EACH,GAAG,EACH,8DAA8D,CAC/D,CAAgB,CAAC;IAElB,oDAAoD;IACpD,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;IACnB,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;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E,KAAK,IAAI,EAAE;QAChD,+CAA+C;QAC/C,MAAM,SAAS,EAAE,CAAC;QAClB,MAAM,IAAI,GAAgB,MAAM,cAAc,CAAC;YAC7C,OAAO,EAAE,qBAAqB;SAC/B,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,eAAe,CAAY,CAAC;QAC1E,MAAM,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,mBAAmB,EAAE,CAAC,CAAC;QAEtE,MAAM,aAAa,GAAG,EAAE,CAAC;QACzB,MAAM,gBAAgB,GAAG,EAAE,CAAC;QAC5B,MAAM,eAAe,GAAG,KAAK,CAAC;QAC9B,QAAQ,CACN,yBAAyB,EACzB,aAAa,EACb,gBAAgB,EAChB,eAAe,CAChB,CAAC;QAEF,QAAQ;QACR,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACrE,MAAM,QAAQ,CAAC,kCAAkC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACpE,MAAM,CAAC,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC;QAEhC,MAAM,gBAAgB,CAAC,uBAAuB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { useFakeTimers } from 'sinon';\nimport { Compose } from '../src/compose/Compose';\nimport { ContactChat } from '../src/contacts/ContactChat';\nimport { Attachment, CustomEventType } from '../src/interfaces';\nimport {\n assertScreenshot,\n clearMockPosts,\n getClip,\n getComponent,\n getValidAttachments,\n getValidText,\n loadStore,\n mockAPI,\n mockGET,\n mockNow,\n mockPOST,\n updateComponent\n} from '../test/utils.test';\n\nimport { expect, oneEvent } from '@open-wc/testing';\n\nlet clock: any;\nmockNow('2021-03-31T00:31:00.000-00:00');\n\nconst TAG = 'temba-contact-chat';\nconst getContactChat = async (attrs: any = {}) => {\n attrs['endpoint'] = '/test-assets/contacts/';\n // add some sizes and styles to force our chat history to scroll\n const chat = (await getComponent(\n TAG,\n attrs,\n '',\n 500,\n 500,\n 'display:flex;flex-direction:column;flex-grow:1;min-height:0;'\n )) as ContactChat;\n\n // TODO: this should be waiting for an event instead\n await waitFor(100);\n await clock.tick(0);\n return chat;\n};\n\nconst getResponseSuccessFiles = (attachments: Attachment[]) => {\n const response_attachments = attachments.map((attachment) => {\n return { content_type: attachment.content_type, url: attachment.url };\n });\n return response_attachments;\n};\n\ndescribe('temba-contact-chat', () => {\n // map requests for contact history to our static files\n // we'll just us the same historylist for everybody for now\n beforeEach(() => {\n clearMockPosts();\n mockGET(\n /\\/contact\\/history\\/contact-.*/,\n '/test-assets/contacts/history.json'\n );\n\n mockGET(\n /\\/api\\/v2\\/users\\.json\\?email=admin1%40nyaruka\\.com/,\n '/test-assets/api/users/admin1.json'\n );\n\n mockAPI();\n clock = useFakeTimers();\n });\n\n afterEach(function () {\n clock.restore();\n });\n\n it('show history and show chatbox if contact is active', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-dave-active'\n });\n\n await assertScreenshot('contacts/chat-for-active-contact', getClip(chat));\n });\n\n it('show history and hide chatbox if contact is archived', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-barack-archived'\n });\n\n await assertScreenshot('contacts/chat-for-archived-contact', getClip(chat));\n });\n\n it('show history and hide chatbox if contact is blocked', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-michelle-blocked'\n });\n\n await assertScreenshot('contacts/chat-for-blocked-contact', getClip(chat));\n });\n\n it('show history and hide chatbox if contact is stopped', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-tim-stopped'\n });\n\n await assertScreenshot('contacts/chat-for-stopped-contact', getClip(chat));\n });\n\n it('sends text without attachments', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-dave-active'\n });\n const compose = chat.shadowRoot.querySelector('temba-compose') as Compose;\n const text = getValidText();\n await updateComponent(compose, text);\n\n const response_body = {\n contact: { uuid: 'contact-dave-active', name: 'Dave Matthews' },\n text: text,\n attachments: []\n };\n mockPOST(/api\\/v2\\/messages\\.json/, response_body);\n\n const listener = oneEvent(compose, CustomEventType.Submitted, false);\n await typeInto('temba-contact-chat:temba-compose', text, true, true);\n expect(await listener).to.exist;\n\n await assertScreenshot('contacts/chat-sends-text-only', getClip(chat));\n });\n\n it('sends attachments without text', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-dave-active'\n });\n const compose = chat.shadowRoot.querySelector('temba-compose') as Compose;\n const attachments = getValidAttachments();\n await updateComponent(compose, null, attachments);\n const response_attachments = getResponseSuccessFiles(attachments);\n const response_body = {\n contact: { uuid: 'contact-dave-active', name: 'Dave Matthews' },\n text: '',\n attachments: response_attachments\n };\n const response_headers = {};\n const response_status = '200';\n mockPOST(\n /api\\/v2\\/messages\\.json/,\n response_body,\n response_headers,\n response_status\n );\n\n const listener = oneEvent(compose, CustomEventType.Submitted, false);\n await typeInto('temba-contact-chat:temba-compose', '', false, true);\n expect(await listener).to.exist;\n\n await assertScreenshot(\n 'contacts/chat-sends-attachments-only',\n getClip(chat)\n );\n });\n\n it('sends text with attachments', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-dave-active'\n });\n const compose = chat.shadowRoot.querySelector('temba-compose') as Compose;\n const text = getValidText();\n const attachments = getValidAttachments();\n await updateComponent(compose, text, attachments);\n const response_attachments = getResponseSuccessFiles(attachments);\n const response_body = {\n contact: { uuid: 'contact-dave-active', name: 'Dave Matthews' },\n text: text,\n attachments: response_attachments\n };\n mockPOST(/api\\/v2\\/messages\\.json/, response_body);\n\n // press enter\n const listener = oneEvent(compose, CustomEventType.Submitted, false);\n await typeInto('temba-contact-chat:temba-compose', '', false, true);\n expect(await listener).to.exist;\n\n await assertScreenshot(\n 'contacts/chat-sends-text-and-attachments',\n getClip(chat)\n );\n });\n\n it('shows failure message with retry', async () => {\n // we are a StoreElement, so load a store first\n await loadStore();\n const chat: ContactChat = await getContactChat({\n contact: 'contact-dave-active'\n });\n const compose = chat.shadowRoot.querySelector('temba-compose') as Compose;\n await updateComponent(compose, getValidText(), getValidAttachments());\n\n const response_body = {};\n const response_headers = {};\n const response_status = '500';\n mockPOST(\n /api\\/v2\\/messages\\.json/,\n response_body,\n response_headers,\n response_status\n );\n\n // press\n const listener = oneEvent(compose, CustomEventType.Submitted, false);\n await typeInto('temba-contact-chat:temba-compose', '', false, true);\n expect(await listener).to.exist;\n\n await assertScreenshot('contacts/chat-failure', getClip(chat));\n });\n});\n"]}
|
|
@@ -3,7 +3,7 @@ import { Dropdown } from '../src/dropdown/Dropdown';
|
|
|
3
3
|
import { assertScreenshot, getClip, getComponent } from './utils.test';
|
|
4
4
|
const TAG = 'temba-dropdown';
|
|
5
5
|
// Helper function to wait for stable rendering
|
|
6
|
-
const waitForStableRender = async (dropdown, timeoutMs =
|
|
6
|
+
const waitForStableRender = async (dropdown, timeoutMs = 100) => {
|
|
7
7
|
await dropdown.updateComplete;
|
|
8
8
|
// Double wait to ensure any async positioning is complete
|
|
9
9
|
await new Promise((resolve) => setTimeout(resolve, timeoutMs));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temba-dropdown.test.js","sourceRoot":"","sources":["../../test/temba-dropdown.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,OAAO,E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AC/D,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAEtC,4EAA4E;QAC5E,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC/D,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;QAE/B,+BAA+B;QAC/B,MAAM,gBAAgB,CAAC,kBAAkB,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert, expect } from '@open-wc/testing';\nimport { Dropdown } from '../src/dropdown/Dropdown';\nimport { assertScreenshot, getClip, getComponent } from './utils.test';\n\nconst TAG = 'temba-dropdown';\n\n// Helper function to wait for stable rendering\nconst waitForStableRender = async (dropdown: Dropdown, timeoutMs = 200) => {\n await dropdown.updateComplete;\n // Double wait to ensure any async positioning is complete\n await new Promise((resolve) => setTimeout(resolve, timeoutMs));\n await dropdown.updateComplete;\n};\n\n// Helper function to get expanded clip that includes dropdown content when open\nconst getDropdownClip = (dropdown: Dropdown) => {\n if (!dropdown.open) {\n // If closed, use regular clipping\n return getClip(dropdown);\n }\n\n // For open dropdowns, include the positioned dropdown content\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const dropdownBounds = dropdownDiv.getBoundingClientRect();\n const componentBounds = dropdown.getBoundingClientRect();\n\n // If dropdown content has no meaningful size, fall back to regular clip\n if (dropdownBounds.width < 10 || dropdownBounds.height < 10) {\n return getClip(dropdown);\n }\n\n // Create a clipping region that includes both the component and the dropdown content\n const minX = Math.min(componentBounds.x, dropdownBounds.x);\n const minY = Math.min(componentBounds.y, dropdownBounds.y);\n const maxX = Math.max(componentBounds.right, dropdownBounds.right);\n const maxY = Math.max(componentBounds.bottom, dropdownBounds.bottom);\n\n // Clamp to reasonable bounds to avoid excessive screenshot sizes\n const x = Math.max(0, minX - 10);\n const y = Math.max(0, minY - 10);\n const width = Math.min(1000, maxX - minX + 20);\n const height = Math.min(800, maxY - minY + 20);\n\n return { x, y, width, height };\n};\n\nconst getDropdown = async (\n attrs: {\n open?: boolean;\n dormant?: boolean;\n arrowSize?: number;\n margin?: number;\n mask?: boolean;\n } = {},\n toggleSlot = '<button slot=\"toggle\">Toggle</button>',\n dropdownSlot = '<div slot=\"dropdown\">Dropdown content</div>'\n) => {\n const dropdown = (await getComponent(\n TAG,\n attrs,\n `${toggleSlot}${dropdownSlot}`,\n 400,\n 300\n )) as Dropdown;\n await dropdown.updateComplete;\n return dropdown;\n};\n\ndescribe(TAG, () => {\n it('can be created', async () => {\n const dropdown = await getDropdown();\n assert.instanceOf(dropdown, Dropdown);\n });\n\n it('has correct default properties', async () => {\n const dropdown = await getDropdown();\n\n // Test expected values first\n expect(dropdown.open).to.equal(false);\n expect(dropdown.dormant).to.equal(true);\n expect(dropdown.arrowSize).to.equal(8);\n expect(dropdown.margin).to.equal(10);\n expect(dropdown.mask).to.equal(false);\n // Position calculation happens automatically, so styles won't be empty\n expect(typeof dropdown.dropdownStyle).to.equal('object');\n expect(typeof dropdown.arrowStyle).to.equal('object');\n\n // Then screenshot\n await assertScreenshot('dropdown/default', getClip(dropdown));\n });\n\n it('renders with mask when enabled', async () => {\n const dropdown = await getDropdown({ mask: true });\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await waitForStableRender(dropdown);\n\n // Test expected values first\n expect(dropdown.mask).to.equal(true);\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Then screenshot\n await assertScreenshot('dropdown/with-mask', getDropdownClip(dropdown));\n });\n\n it('handles toggle click and opens dropdown', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Verify initial state\n expect(dropdown.open).to.equal(false);\n expect(dropdown.dormant).to.equal(true);\n\n // Click the toggle\n toggle.click();\n await waitForStableRender(dropdown);\n\n // Verify dropdown opened\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Screenshot the opened state with expanded clip\n await assertScreenshot('dropdown/opened', getDropdownClip(dropdown));\n });\n\n it('handles custom arrow size', async () => {\n const dropdown = await getDropdown({ arrowSize: 12 });\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await waitForStableRender(dropdown);\n\n // Test expected values first\n expect(dropdown.arrowSize).to.equal(12);\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Then screenshot\n await assertScreenshot(\n 'dropdown/custom-arrow-size',\n getDropdownClip(dropdown)\n );\n });\n\n it('calculates position correctly', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await dropdown.updateComplete;\n\n // Trigger position calculation\n dropdown.calculatePosition();\n await waitForStableRender(dropdown);\n\n // Verify position styles were calculated\n expect(Object.keys(dropdown.dropdownStyle).length).to.be.greaterThan(0);\n expect(Object.keys(dropdown.arrowStyle).length).to.be.greaterThan(0);\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Screenshot positioned dropdown\n await assertScreenshot('dropdown/positioned', getDropdownClip(dropdown));\n });\n\n it('handles blur events to close dropdown', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown first\n toggle.click();\n await dropdown.updateComplete;\n expect(dropdown.open).to.equal(true);\n\n // Simulate blur event\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const blurEvent = new FocusEvent('blur', {\n bubbles: true,\n relatedTarget: document.body\n });\n dropdownDiv.dispatchEvent(blurEvent);\n\n // Check that dropdown is closed after a short delay\n await new Promise((resolve) => setTimeout(resolve, 300));\n expect(dropdown.open).to.equal(false);\n\n // Screenshot closed state\n await assertScreenshot('dropdown/after-blur', getClip(dropdown));\n });\n\n it('handles blur events when focus moves within dropdown', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown first\n toggle.click();\n await dropdown.updateComplete;\n expect(dropdown.open).to.equal(true);\n\n // Create an element within the dropdown\n const dropdownContent = dropdown.querySelector(\n '[slot=\"dropdown\"]'\n ) as HTMLElement;\n const internalButton = document.createElement('button');\n internalButton.textContent = 'Internal';\n dropdownContent.appendChild(internalButton);\n\n // Simulate blur event where focus moves to internal element\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const blurEvent = new FocusEvent('blur', {\n bubbles: true,\n relatedTarget: internalButton\n });\n dropdownDiv.dispatchEvent(blurEvent);\n await dropdown.updateComplete;\n\n // Dropdown should remain open since focus moved within it\n expect(dropdown.open).to.equal(true);\n });\n\n it('prevents opening when already open', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // First, open the dropdown normally\n toggle.click();\n await dropdown.updateComplete;\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Now try to click toggle again - should not call openDropdown again\n // since !dropdown.open is false\n const originalOpen = dropdown.open;\n toggle.click();\n await dropdown.updateComplete;\n\n // Should remain in the same state\n expect(dropdown.open).to.equal(originalOpen);\n });\n\n it('handles position calculation with right edge collision', async () => {\n // Create dropdown positioned near right edge\n const dropdown = await getDropdown(\n {},\n '<button slot=\"toggle\" style=\"position: fixed; right: 50px; top: 100px; width: 100px; height: 30px;\">Toggle</button>',\n '<div slot=\"dropdown\" style=\"width: 200px; height: 100px;\">Wide content</div>'\n );\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await waitForStableRender(dropdown);\n\n // Get actual element bounds to simulate collision\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const originalGetBoundingClientRect = dropdownDiv.getBoundingClientRect;\n\n // Mock getBoundingClientRect to simulate right collision\n dropdownDiv.getBoundingClientRect = function () {\n return {\n bottom: 200,\n right: window.innerWidth + 100, // Extends beyond window\n top: 100,\n left: window.innerWidth - 50,\n width: 200,\n height: 100,\n x: window.innerWidth - 50,\n y: 100\n } as DOMRect;\n };\n\n try {\n // Trigger position calculation\n dropdown.calculatePosition();\n await waitForStableRender(dropdown);\n\n // Verify position was adjusted for right edge\n expect(dropdown.dropdownStyle).to.have.property('left');\n\n // Screenshot positioned dropdown\n await assertScreenshot(\n 'dropdown/right-edge-collision',\n getDropdownClip(dropdown)\n );\n } finally {\n // Restore original method\n dropdownDiv.getBoundingClientRect = originalGetBoundingClientRect;\n }\n });\n\n it('handles position calculation with bottom edge collision', async () => {\n // Create dropdown positioned near bottom edge\n const dropdown = await getDropdown(\n {},\n '<button slot=\"toggle\" style=\"position: fixed; left: 100px; bottom: 50px; width: 100px; height: 30px;\">Toggle</button>',\n '<div slot=\"dropdown\" style=\"width: 200px; height: 100px; position: absolute;\">Tall content</div>'\n );\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await waitForStableRender(dropdown);\n\n // Get actual element bounds to simulate collision\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const originalGetBoundingClientRect = dropdownDiv.getBoundingClientRect;\n\n // Mock getBoundingClientRect to simulate bottom collision\n dropdownDiv.getBoundingClientRect = function () {\n return {\n bottom: window.innerHeight + 100, // Extends beyond window\n right: 300,\n top: window.innerHeight - 50,\n left: 100,\n width: 200,\n height: 100,\n x: 100,\n y: window.innerHeight - 50\n } as DOMRect;\n };\n\n try {\n // Trigger position calculation\n dropdown.calculatePosition();\n await waitForStableRender(dropdown);\n\n // Verify position was adjusted for bottom edge (bumped up)\n expect(dropdown.dropdownStyle).to.have.property('top');\n expect(dropdown.arrowStyle).to.have.property('transform');\n expect(dropdown.arrowStyle['transform']).to.include('rotate(180deg)');\n\n // Screenshot positioned dropdown\n await assertScreenshot(\n 'dropdown/bottom-edge-collision',\n getDropdownClip(dropdown)\n );\n } finally {\n // Restore original method\n dropdownDiv.getBoundingClientRect = originalGetBoundingClientRect;\n }\n });\n\n it('handles arrow positioning when toggle is very narrow', async () => {\n const dropdown = await getDropdown(\n {},\n '<button slot=\"toggle\" style=\"width: 5px;\">•</button>',\n '<div slot=\"dropdown\">Content</div>'\n );\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await dropdown.updateComplete;\n\n // Trigger position calculation\n dropdown.calculatePosition();\n await waitForStableRender(dropdown);\n\n // Verify arrow positioning was adjusted for narrow toggle\n expect(dropdown.dropdownStyle).to.have.property('marginLeft');\n expect(dropdown.dropdownStyle['marginLeft']).to.equal('-10px');\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Screenshot with adjusted arrow\n await assertScreenshot('dropdown/narrow-toggle', getDropdownClip(dropdown));\n });\n\n it('handles position calculation when toggle element is missing', async () => {\n const dropdown = await getDropdown(\n { open: true, dormant: false },\n '', // No toggle element\n '<div slot=\"dropdown\">Content</div>'\n );\n\n // Trigger position calculation - should handle gracefully\n dropdown.calculatePosition();\n await dropdown.updateComplete;\n\n // Should not crash and should have basic styles\n expect(typeof dropdown.dropdownStyle).to.equal('object');\n expect(typeof dropdown.arrowStyle).to.equal('object');\n });\n\n it('handles resetBlurHandler when activeFocus exists', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open dropdown to trigger resetBlurHandler for the first time\n toggle.click();\n await dropdown.updateComplete;\n expect(dropdown.open).to.equal(true);\n\n // Now open it again - this should trigger the activeFocus cleanup branch\n // First we need to close it\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const blurEvent = new FocusEvent('blur', {\n bubbles: true,\n relatedTarget: document.body\n });\n dropdownDiv.dispatchEvent(blurEvent);\n\n // Wait for close\n await new Promise((resolve) => setTimeout(resolve, 300));\n expect(dropdown.open).to.equal(false);\n expect(dropdown.dormant).to.equal(true);\n\n // Open again - this should trigger the cleanup in resetBlurHandler\n toggle.click();\n await dropdown.updateComplete;\n expect(dropdown.open).to.equal(true);\n });\n\n it('renders without mask by default', async () => {\n const dropdown = await getDropdown(); // No mask explicitly set\n\n // Test expected values first - mask should be false by default\n expect(dropdown.mask).to.equal(false);\n\n // Look for mask element in shadow DOM - should not exist when mask is false\n const maskElement = dropdown.shadowRoot.querySelector('.mask');\n expect(maskElement).to.be.null;\n\n // Screenshot default rendering\n await assertScreenshot('dropdown/no-mask', getClip(dropdown));\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"temba-dropdown.test.js","sourceRoot":"","sources":["../../test/temba-dropdown.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvE,MAAM,GAAG,GAAG,gBAAgB,CAAC;AAE7B,+CAA+C;AAC/C,MAAM,mBAAmB,GAAG,KAAK,EAAE,QAAkB,EAAE,SAAS,GAAG,GAAG,EAAE,EAAE;IACxE,MAAM,QAAQ,CAAC,cAAc,CAAC;IAC9B,0DAA0D;IAC1D,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC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C,QAAQ,CAAC,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert, expect } from '@open-wc/testing';\nimport { Dropdown } from '../src/dropdown/Dropdown';\nimport { assertScreenshot, getClip, getComponent } from './utils.test';\n\nconst TAG = 'temba-dropdown';\n\n// Helper function to wait for stable rendering\nconst waitForStableRender = async (dropdown: Dropdown, timeoutMs = 100) => {\n await dropdown.updateComplete;\n // Double wait to ensure any async positioning is complete\n await new Promise((resolve) => setTimeout(resolve, timeoutMs));\n await dropdown.updateComplete;\n};\n\n// Helper function to get expanded clip that includes dropdown content when open\nconst getDropdownClip = (dropdown: Dropdown) => {\n if (!dropdown.open) {\n // If closed, use regular clipping\n return getClip(dropdown);\n }\n\n // For open dropdowns, include the positioned dropdown content\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const dropdownBounds = dropdownDiv.getBoundingClientRect();\n const componentBounds = dropdown.getBoundingClientRect();\n\n // If dropdown content has no meaningful size, fall back to regular clip\n if (dropdownBounds.width < 10 || dropdownBounds.height < 10) {\n return getClip(dropdown);\n }\n\n // Create a clipping region that includes both the component and the dropdown content\n const minX = Math.min(componentBounds.x, dropdownBounds.x);\n const minY = Math.min(componentBounds.y, dropdownBounds.y);\n const maxX = Math.max(componentBounds.right, dropdownBounds.right);\n const maxY = Math.max(componentBounds.bottom, dropdownBounds.bottom);\n\n // Clamp to reasonable bounds to avoid excessive screenshot sizes\n const x = Math.max(0, minX - 10);\n const y = Math.max(0, minY - 10);\n const width = Math.min(1000, maxX - minX + 20);\n const height = Math.min(800, maxY - minY + 20);\n\n return { x, y, width, height };\n};\n\nconst getDropdown = async (\n attrs: {\n open?: boolean;\n dormant?: boolean;\n arrowSize?: number;\n margin?: number;\n mask?: boolean;\n } = {},\n toggleSlot = '<button slot=\"toggle\">Toggle</button>',\n dropdownSlot = '<div slot=\"dropdown\">Dropdown content</div>'\n) => {\n const dropdown = (await getComponent(\n TAG,\n attrs,\n `${toggleSlot}${dropdownSlot}`,\n 400,\n 300\n )) as Dropdown;\n await dropdown.updateComplete;\n return dropdown;\n};\n\ndescribe(TAG, () => {\n it('can be created', async () => {\n const dropdown = await getDropdown();\n assert.instanceOf(dropdown, Dropdown);\n });\n\n it('has correct default properties', async () => {\n const dropdown = await getDropdown();\n\n // Test expected values first\n expect(dropdown.open).to.equal(false);\n expect(dropdown.dormant).to.equal(true);\n expect(dropdown.arrowSize).to.equal(8);\n expect(dropdown.margin).to.equal(10);\n expect(dropdown.mask).to.equal(false);\n // Position calculation happens automatically, so styles won't be empty\n expect(typeof dropdown.dropdownStyle).to.equal('object');\n expect(typeof dropdown.arrowStyle).to.equal('object');\n\n // Then screenshot\n await assertScreenshot('dropdown/default', getClip(dropdown));\n });\n\n it('renders with mask when enabled', async () => {\n const dropdown = await getDropdown({ mask: true });\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await waitForStableRender(dropdown);\n\n // Test expected values first\n expect(dropdown.mask).to.equal(true);\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Then screenshot\n await assertScreenshot('dropdown/with-mask', getDropdownClip(dropdown));\n });\n\n it('handles toggle click and opens dropdown', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Verify initial state\n expect(dropdown.open).to.equal(false);\n expect(dropdown.dormant).to.equal(true);\n\n // Click the toggle\n toggle.click();\n await waitForStableRender(dropdown);\n\n // Verify dropdown opened\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Screenshot the opened state with expanded clip\n await assertScreenshot('dropdown/opened', getDropdownClip(dropdown));\n });\n\n it('handles custom arrow size', async () => {\n const dropdown = await getDropdown({ arrowSize: 12 });\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await waitForStableRender(dropdown);\n\n // Test expected values first\n expect(dropdown.arrowSize).to.equal(12);\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Then screenshot\n await assertScreenshot(\n 'dropdown/custom-arrow-size',\n getDropdownClip(dropdown)\n );\n });\n\n it('calculates position correctly', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await dropdown.updateComplete;\n\n // Trigger position calculation\n dropdown.calculatePosition();\n await waitForStableRender(dropdown);\n\n // Verify position styles were calculated\n expect(Object.keys(dropdown.dropdownStyle).length).to.be.greaterThan(0);\n expect(Object.keys(dropdown.arrowStyle).length).to.be.greaterThan(0);\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Screenshot positioned dropdown\n await assertScreenshot('dropdown/positioned', getDropdownClip(dropdown));\n });\n\n it('handles blur events to close dropdown', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown first\n toggle.click();\n await dropdown.updateComplete;\n expect(dropdown.open).to.equal(true);\n\n // Simulate blur event\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const blurEvent = new FocusEvent('blur', {\n bubbles: true,\n relatedTarget: document.body\n });\n dropdownDiv.dispatchEvent(blurEvent);\n\n // Check that dropdown is closed after a short delay\n await new Promise((resolve) => setTimeout(resolve, 300));\n expect(dropdown.open).to.equal(false);\n\n // Screenshot closed state\n await assertScreenshot('dropdown/after-blur', getClip(dropdown));\n });\n\n it('handles blur events when focus moves within dropdown', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown first\n toggle.click();\n await dropdown.updateComplete;\n expect(dropdown.open).to.equal(true);\n\n // Create an element within the dropdown\n const dropdownContent = dropdown.querySelector(\n '[slot=\"dropdown\"]'\n ) as HTMLElement;\n const internalButton = document.createElement('button');\n internalButton.textContent = 'Internal';\n dropdownContent.appendChild(internalButton);\n\n // Simulate blur event where focus moves to internal element\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const blurEvent = new FocusEvent('blur', {\n bubbles: true,\n relatedTarget: internalButton\n });\n dropdownDiv.dispatchEvent(blurEvent);\n await dropdown.updateComplete;\n\n // Dropdown should remain open since focus moved within it\n expect(dropdown.open).to.equal(true);\n });\n\n it('prevents opening when already open', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // First, open the dropdown normally\n toggle.click();\n await dropdown.updateComplete;\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Now try to click toggle again - should not call openDropdown again\n // since !dropdown.open is false\n const originalOpen = dropdown.open;\n toggle.click();\n await dropdown.updateComplete;\n\n // Should remain in the same state\n expect(dropdown.open).to.equal(originalOpen);\n });\n\n it('handles position calculation with right edge collision', async () => {\n // Create dropdown positioned near right edge\n const dropdown = await getDropdown(\n {},\n '<button slot=\"toggle\" style=\"position: fixed; right: 50px; top: 100px; width: 100px; height: 30px;\">Toggle</button>',\n '<div slot=\"dropdown\" style=\"width: 200px; height: 100px;\">Wide content</div>'\n );\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await waitForStableRender(dropdown);\n\n // Get actual element bounds to simulate collision\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const originalGetBoundingClientRect = dropdownDiv.getBoundingClientRect;\n\n // Mock getBoundingClientRect to simulate right collision\n dropdownDiv.getBoundingClientRect = function () {\n return {\n bottom: 200,\n right: window.innerWidth + 100, // Extends beyond window\n top: 100,\n left: window.innerWidth - 50,\n width: 200,\n height: 100,\n x: window.innerWidth - 50,\n y: 100\n } as DOMRect;\n };\n\n try {\n // Trigger position calculation\n dropdown.calculatePosition();\n await waitForStableRender(dropdown);\n\n // Verify position was adjusted for right edge\n expect(dropdown.dropdownStyle).to.have.property('left');\n\n // Screenshot positioned dropdown\n await assertScreenshot(\n 'dropdown/right-edge-collision',\n getDropdownClip(dropdown)\n );\n } finally {\n // Restore original method\n dropdownDiv.getBoundingClientRect = originalGetBoundingClientRect;\n }\n });\n\n it('handles position calculation with bottom edge collision', async () => {\n // Create dropdown positioned near bottom edge\n const dropdown = await getDropdown(\n {},\n '<button slot=\"toggle\" style=\"position: fixed; left: 100px; bottom: 50px; width: 100px; height: 30px;\">Toggle</button>',\n '<div slot=\"dropdown\" style=\"width: 200px; height: 100px; position: absolute;\">Tall content</div>'\n );\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await waitForStableRender(dropdown);\n\n // Get actual element bounds to simulate collision\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const originalGetBoundingClientRect = dropdownDiv.getBoundingClientRect;\n\n // Mock getBoundingClientRect to simulate bottom collision\n dropdownDiv.getBoundingClientRect = function () {\n return {\n bottom: window.innerHeight + 100, // Extends beyond window\n right: 300,\n top: window.innerHeight - 50,\n left: 100,\n width: 200,\n height: 100,\n x: 100,\n y: window.innerHeight - 50\n } as DOMRect;\n };\n\n try {\n // Trigger position calculation\n dropdown.calculatePosition();\n await waitForStableRender(dropdown);\n\n // Verify position was adjusted for bottom edge (bumped up)\n expect(dropdown.dropdownStyle).to.have.property('top');\n expect(dropdown.arrowStyle).to.have.property('transform');\n expect(dropdown.arrowStyle['transform']).to.include('rotate(180deg)');\n\n // Screenshot positioned dropdown\n await assertScreenshot(\n 'dropdown/bottom-edge-collision',\n getDropdownClip(dropdown)\n );\n } finally {\n // Restore original method\n dropdownDiv.getBoundingClientRect = originalGetBoundingClientRect;\n }\n });\n\n it('handles arrow positioning when toggle is very narrow', async () => {\n const dropdown = await getDropdown(\n {},\n '<button slot=\"toggle\" style=\"width: 5px;\">•</button>',\n '<div slot=\"dropdown\">Content</div>'\n );\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open the dropdown properly by clicking\n toggle.click();\n await dropdown.updateComplete;\n\n // Trigger position calculation\n dropdown.calculatePosition();\n await waitForStableRender(dropdown);\n\n // Verify arrow positioning was adjusted for narrow toggle\n expect(dropdown.dropdownStyle).to.have.property('marginLeft');\n expect(dropdown.dropdownStyle['marginLeft']).to.equal('-10px');\n expect(dropdown.open).to.equal(true);\n expect(dropdown.dormant).to.equal(false);\n\n // Screenshot with adjusted arrow\n await assertScreenshot('dropdown/narrow-toggle', getDropdownClip(dropdown));\n });\n\n it('handles position calculation when toggle element is missing', async () => {\n const dropdown = await getDropdown(\n { open: true, dormant: false },\n '', // No toggle element\n '<div slot=\"dropdown\">Content</div>'\n );\n\n // Trigger position calculation - should handle gracefully\n dropdown.calculatePosition();\n await dropdown.updateComplete;\n\n // Should not crash and should have basic styles\n expect(typeof dropdown.dropdownStyle).to.equal('object');\n expect(typeof dropdown.arrowStyle).to.equal('object');\n });\n\n it('handles resetBlurHandler when activeFocus exists', async () => {\n const dropdown = await getDropdown();\n const toggle = dropdown.querySelector('[slot=\"toggle\"]') as HTMLElement;\n\n // Open dropdown to trigger resetBlurHandler for the first time\n toggle.click();\n await dropdown.updateComplete;\n expect(dropdown.open).to.equal(true);\n\n // Now open it again - this should trigger the activeFocus cleanup branch\n // First we need to close it\n const dropdownDiv = dropdown.shadowRoot.querySelector(\n '.dropdown'\n ) as HTMLDivElement;\n const blurEvent = new FocusEvent('blur', {\n bubbles: true,\n relatedTarget: document.body\n });\n dropdownDiv.dispatchEvent(blurEvent);\n\n // Wait for close\n await new Promise((resolve) => setTimeout(resolve, 300));\n expect(dropdown.open).to.equal(false);\n expect(dropdown.dormant).to.equal(true);\n\n // Open again - this should trigger the cleanup in resetBlurHandler\n toggle.click();\n await dropdown.updateComplete;\n expect(dropdown.open).to.equal(true);\n });\n\n it('renders without mask by default', async () => {\n const dropdown = await getDropdown(); // No mask explicitly set\n\n // Test expected values first - mask should be false by default\n expect(dropdown.mask).to.equal(false);\n\n // Look for mask element in shadow DOM - should not exist when mask is false\n const maskElement = dropdown.shadowRoot.querySelector('.mask');\n expect(maskElement).to.be.null;\n\n // Screenshot default rendering\n await assertScreenshot('dropdown/no-mask', getClip(dropdown));\n });\n});\n"]}
|