From 2e4d9d5a1daaafe5792398aa0fee1784aa937060 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Wed, 6 Jul 2022 08:32:39 +0200 Subject: [PATCH] =?UTF-8?q?fix(typebot-js):=20=F0=9F=90=9B=20Open=20iframe?= =?UTF-8?q?=20on=20proactive=20message=20click?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish-lib-to-npm.yml | 5 ++--- packages/typebot-js/package.json | 2 +- .../typebot-js/src/embedTypes/chat/index.ts | 5 +++-- .../tests/chat/proactiveMessage.spec.ts | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-lib-to-npm.yml b/.github/workflows/publish-lib-to-npm.yml index bb08ab6a2..20c2a3707 100644 --- a/.github/workflows/publish-lib-to-npm.yml +++ b/.github/workflows/publish-lib-to-npm.yml @@ -1,9 +1,8 @@ name: Publish package to NPM on: - push: - tags: - - 'js-lib-v*.*.*' + create: + tags: ['js-lib-v*'] jobs: publish: diff --git a/packages/typebot-js/package.json b/packages/typebot-js/package.json index 0efaa670d..24121cc29 100644 --- a/packages/typebot-js/package.json +++ b/packages/typebot-js/package.json @@ -1,6 +1,6 @@ { "name": "typebot-js", - "version": "2.2.8", + "version": "2.2.9", "main": "dist/index.js", "unpkg": "dist/index.umd.min.js", "license": "AGPL-3.0-or-later", diff --git a/packages/typebot-js/src/embedTypes/chat/index.ts b/packages/typebot-js/src/embedTypes/chat/index.ts index d7cb01bab..cb1c90030 100644 --- a/packages/typebot-js/src/embedTypes/chat/index.ts +++ b/packages/typebot-js/src/embedTypes/chat/index.ts @@ -77,8 +77,9 @@ const onProactiveMessageClick = ( bubble: HTMLDivElement, iframe: HTMLIFrameElement ): void => { - loadTypebotIfFirstOpen(iframe) - bubble.classList.add('iframe-opened') + iframe.style.display === 'none' + ? openIframe(bubble, iframe) + : closeIframe(bubble, iframe) bubble.classList.remove('message-opened') } diff --git a/packages/typebot-js/tests/chat/proactiveMessage.spec.ts b/packages/typebot-js/tests/chat/proactiveMessage.spec.ts index 11f0de978..2e4e9943a 100644 --- a/packages/typebot-js/tests/chat/proactiveMessage.spec.ts +++ b/packages/typebot-js/tests/chat/proactiveMessage.spec.ts @@ -75,3 +75,22 @@ it('show after the corresponding delay', async () => { await new Promise((r) => setTimeout(r, 1000)) expect(bubble.classList.contains('message-opened')).toBe(true) }) + +it('show the chat on click', async () => { + expect.assertions(3) + Typebot.initBubble({ + proactiveMessage: { + textContent: 'Hi click here!', + delay: 1000, + }, + url: 'https://typebot.io/typebot-id', + }) + const bubble = document.querySelector('#typebot-bubble') as HTMLDivElement + const iframe = document.querySelector('.typebot-iframe') as HTMLIFrameElement + expect(bubble.classList.contains('message-opened')).toBe(false) + await new Promise((r) => setTimeout(r, 1000)) + expect(bubble.classList.contains('message-opened')).toBe(true) + const message = document.querySelector('.proactive-message') as HTMLDivElement + message.click() + expect(iframe.style.display).not.toBe('none') +})