2
0

🧑‍💻 (typebot-js) Add closeChatBubble event data

This commit is contained in:
Baptiste Arnaud
2022-11-10 12:08:51 +01:00
parent ea84039024
commit 54a1dc0431
4 changed files with 38 additions and 1 deletions

View File

@ -1,4 +1,6 @@
import { createIframe } from '../src/iframe'
import * as Typebot from '../src'
import { TypebotPostMessageData } from '../src'
describe('createIframe', () => {
it('should create a valid iframe element', () => {
@ -111,4 +113,27 @@ describe('createIframe', () => {
expect(n).toBeUndefined()
expect(v).toBeUndefined()
})
it('should close chat when receive close command', async () => {
expect.assertions(2)
const { open } = Typebot.initBubble({
url: 'https://typebot.io/typebot-id2',
})
const bubble = document.getElementById('typebot-bubble')
open()
await new Promise((resolve) => setTimeout(resolve, 50))
expect(bubble?.classList.contains('iframe-opened')).toBe(true)
const messageData: TypebotPostMessageData = {
closeChatBubble: true,
}
window.postMessage(
{
from: 'typebot',
...messageData,
},
'*'
)
await new Promise((resolve) => setTimeout(resolve, 50))
expect(bubble?.classList.contains('iframe-opened')).toBe(false)
})
})