2022-03-07 18:21:01 +01:00
|
|
|
import test, { expect } from '@playwright/test'
|
2023-02-10 15:06:02 +01:00
|
|
|
import { createId } from '@paralleldrive/cuid2'
|
2022-06-11 07:27:38 +02:00
|
|
|
import {
|
|
|
|
defaultSettings,
|
|
|
|
defaultTextInputOptions,
|
|
|
|
InputBlockType,
|
2022-11-15 10:28:03 +01:00
|
|
|
Metadata,
|
2023-03-15 08:35:16 +01:00
|
|
|
} from '@typebot.io/schemas'
|
|
|
|
import {
|
|
|
|
createTypebots,
|
|
|
|
updateTypebot,
|
|
|
|
} from '@typebot.io/lib/playwright/databaseActions'
|
|
|
|
import { parseDefaultGroupWithBlock } from '@typebot.io/lib/playwright/databaseHelpers'
|
2022-03-07 18:21:01 +01:00
|
|
|
|
2023-02-21 15:25:14 +01:00
|
|
|
test('Result should be overwritten on page refresh', async ({ page }) => {
|
2023-02-10 15:06:02 +01:00
|
|
|
const typebotId = createId()
|
2022-03-07 18:21:01 +01:00
|
|
|
await createTypebots([
|
|
|
|
{
|
|
|
|
id: typebotId,
|
2023-02-23 09:21:18 +01:00
|
|
|
settings: {
|
|
|
|
...defaultSettings,
|
|
|
|
general: {
|
|
|
|
...defaultSettings.general,
|
|
|
|
isNewResultOnRefreshEnabled: false,
|
|
|
|
},
|
|
|
|
},
|
2022-06-11 07:27:38 +02:00
|
|
|
...parseDefaultGroupWithBlock({
|
|
|
|
type: InputBlockType.TEXT,
|
2022-03-07 18:21:01 +01:00
|
|
|
options: defaultTextInputOptions,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
])
|
2023-02-21 15:25:14 +01:00
|
|
|
|
|
|
|
const [, response] = await Promise.all([
|
2022-03-21 17:05:51 +01:00
|
|
|
page.goto(`/${typebotId}-public`),
|
2023-02-21 15:25:14 +01:00
|
|
|
page.waitForResponse(/sendMessage/),
|
2022-03-21 17:05:51 +01:00
|
|
|
])
|
2023-02-21 15:25:14 +01:00
|
|
|
const { resultId } = await response.json()
|
2022-03-07 18:21:01 +01:00
|
|
|
expect(resultId).toBeDefined()
|
2023-02-21 15:25:14 +01:00
|
|
|
await expect(page.getByRole('textbox')).toBeVisible()
|
|
|
|
|
|
|
|
const [, secondResponse] = await Promise.all([
|
|
|
|
page.reload(),
|
|
|
|
page.waitForResponse(/sendMessage/),
|
|
|
|
])
|
|
|
|
const { resultId: secondResultId } = await secondResponse.json()
|
|
|
|
expect(secondResultId).toBe(resultId)
|
2022-03-07 18:21:01 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
test.describe('Create result on page refresh enabled', () => {
|
|
|
|
test('should work', async ({ page }) => {
|
2023-02-10 15:06:02 +01:00
|
|
|
const typebotId = createId()
|
2022-03-07 18:21:01 +01:00
|
|
|
await createTypebots([
|
|
|
|
{
|
|
|
|
id: typebotId,
|
2022-06-11 07:27:38 +02:00
|
|
|
...parseDefaultGroupWithBlock({
|
|
|
|
type: InputBlockType.TEXT,
|
2022-03-07 18:21:01 +01:00
|
|
|
options: defaultTextInputOptions,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
])
|
2023-02-21 15:25:14 +01:00
|
|
|
const [, response] = await Promise.all([
|
2022-03-21 17:05:51 +01:00
|
|
|
page.goto(`/${typebotId}-public`),
|
2023-02-21 15:25:14 +01:00
|
|
|
page.waitForResponse(/sendMessage/),
|
2022-03-21 17:05:51 +01:00
|
|
|
])
|
2023-02-21 15:25:14 +01:00
|
|
|
const { resultId } = await response.json()
|
|
|
|
expect(resultId).toBeDefined()
|
|
|
|
|
|
|
|
await expect(page.getByRole('textbox')).toBeVisible()
|
|
|
|
const [, secondResponse] = await Promise.all([
|
2022-03-21 17:05:51 +01:00
|
|
|
page.reload(),
|
2023-02-21 15:25:14 +01:00
|
|
|
page.waitForResponse(/sendMessage/),
|
2022-03-21 17:05:51 +01:00
|
|
|
])
|
2023-02-21 15:25:14 +01:00
|
|
|
const { resultId: secondResultId } = await secondResponse.json()
|
|
|
|
expect(secondResultId).not.toBe(resultId)
|
2022-03-07 18:21:01 +01:00
|
|
|
})
|
|
|
|
})
|
2022-05-14 11:53:59 -07:00
|
|
|
|
|
|
|
test('Hide query params', async ({ page }) => {
|
2023-02-10 15:06:02 +01:00
|
|
|
const typebotId = createId()
|
2022-05-14 11:53:59 -07:00
|
|
|
await createTypebots([
|
|
|
|
{
|
|
|
|
id: typebotId,
|
2022-06-11 07:27:38 +02:00
|
|
|
...parseDefaultGroupWithBlock({
|
|
|
|
type: InputBlockType.TEXT,
|
2022-05-14 11:53:59 -07:00
|
|
|
options: defaultTextInputOptions,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
])
|
|
|
|
await page.goto(`/${typebotId}-public?Name=John`)
|
|
|
|
await page.waitForTimeout(1000)
|
|
|
|
expect(page.url()).toEqual(`http://localhost:3001/${typebotId}-public`)
|
|
|
|
await updateTypebot({
|
|
|
|
id: typebotId,
|
|
|
|
settings: {
|
|
|
|
...defaultSettings,
|
|
|
|
general: { ...defaultSettings.general, isHideQueryParamsEnabled: false },
|
|
|
|
},
|
|
|
|
})
|
|
|
|
await page.goto(`/${typebotId}-public?Name=John`)
|
|
|
|
await page.waitForTimeout(1000)
|
|
|
|
expect(page.url()).toEqual(
|
|
|
|
`http://localhost:3001/${typebotId}-public?Name=John`
|
|
|
|
)
|
|
|
|
})
|
2022-10-06 08:33:46 +02:00
|
|
|
|
|
|
|
test('Show close message', async ({ page }) => {
|
2023-02-10 15:06:02 +01:00
|
|
|
const typebotId = createId()
|
2022-10-06 08:33:46 +02:00
|
|
|
await createTypebots([
|
|
|
|
{
|
|
|
|
id: typebotId,
|
|
|
|
...parseDefaultGroupWithBlock({
|
|
|
|
type: InputBlockType.TEXT,
|
|
|
|
options: defaultTextInputOptions,
|
|
|
|
}),
|
|
|
|
isClosed: true,
|
|
|
|
},
|
|
|
|
])
|
|
|
|
await page.goto(`/${typebotId}-public`)
|
|
|
|
await expect(page.locator('text=This bot is now closed')).toBeVisible()
|
|
|
|
})
|
2022-11-15 10:28:03 +01:00
|
|
|
|
|
|
|
test('Should correctly parse metadata', async ({ page }) => {
|
2023-02-10 15:06:02 +01:00
|
|
|
const typebotId = createId()
|
2022-11-15 10:28:03 +01:00
|
|
|
const customMetadata: Metadata = {
|
|
|
|
description: 'My custom description',
|
|
|
|
title: 'Custom title',
|
|
|
|
favIconUrl: 'https://www.baptistearno.com/favicon.png',
|
|
|
|
imageUrl: 'https://www.baptistearno.com/images/site-preview.png',
|
|
|
|
customHeadCode: '<meta name="author" content="John Doe">',
|
|
|
|
}
|
|
|
|
await createTypebots([
|
|
|
|
{
|
|
|
|
id: typebotId,
|
|
|
|
settings: {
|
|
|
|
...defaultSettings,
|
|
|
|
metadata: customMetadata,
|
|
|
|
},
|
|
|
|
...parseDefaultGroupWithBlock({
|
|
|
|
type: InputBlockType.TEXT,
|
|
|
|
options: defaultTextInputOptions,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
])
|
|
|
|
await page.goto(`/${typebotId}-public`)
|
|
|
|
expect(
|
|
|
|
await page.evaluate(`document.querySelector('title').textContent`)
|
|
|
|
).toBe(customMetadata.title)
|
|
|
|
expect(
|
|
|
|
await page.evaluate(
|
2022-11-21 11:12:43 +01:00
|
|
|
() =>
|
|
|
|
(document.querySelector('meta[name="description"]') as HTMLMetaElement)
|
|
|
|
.content
|
2022-11-15 10:28:03 +01:00
|
|
|
)
|
|
|
|
).toBe(customMetadata.description)
|
|
|
|
expect(
|
|
|
|
await page.evaluate(
|
2022-11-21 11:12:43 +01:00
|
|
|
() =>
|
|
|
|
(document.querySelector('meta[property="og:image"]') as HTMLMetaElement)
|
|
|
|
.content
|
2022-11-15 10:28:03 +01:00
|
|
|
)
|
|
|
|
).toBe(customMetadata.imageUrl)
|
|
|
|
expect(
|
|
|
|
await page.evaluate(() =>
|
2022-11-21 11:12:43 +01:00
|
|
|
(
|
|
|
|
document.querySelector('link[rel="icon"]') as HTMLLinkElement
|
|
|
|
).getAttribute('href')
|
2022-11-15 10:28:03 +01:00
|
|
|
)
|
|
|
|
).toBe(customMetadata.favIconUrl)
|
2023-02-21 15:25:14 +01:00
|
|
|
await expect(
|
|
|
|
page.locator(
|
|
|
|
`input[placeholder="${defaultTextInputOptions.labels.placeholder}"]`
|
|
|
|
)
|
|
|
|
).toBeVisible()
|
2022-11-15 10:28:03 +01:00
|
|
|
expect(
|
|
|
|
await page.evaluate(
|
2022-11-21 11:12:43 +01:00
|
|
|
() =>
|
|
|
|
(document.querySelector('meta[name="author"]') as HTMLMetaElement)
|
|
|
|
.content
|
2022-11-15 10:28:03 +01:00
|
|
|
)
|
|
|
|
).toBe('John Doe')
|
|
|
|
})
|