♻️ Simplify text bubble content shape

Remove html and plainText field because it was redundant

Closes #386
This commit is contained in:
Baptiste Arnaud
2023-04-13 17:04:21 +02:00
parent 2cbf8348c3
commit e0a9824913
70 changed files with 545 additions and 1030 deletions

View File

@@ -112,6 +112,5 @@ test.describe('Storage limit is reached', () => {
)
await page.goto(`${process.env.NEXTAUTH_URL}/typebots/${typebotId}/results`)
await expect(page.locator('text="150%"')).toBeVisible()
await expect(page.locator('text="api.json"')).toBeHidden()
})
})

View File

@@ -45,8 +45,12 @@ test('API chat execution should work on preview bot', async ({ request }) => {
).json()
expect(resultId).toBeUndefined()
expect(sessionId).toBeDefined()
expect(messages[0].content.plainText).toBe('Hi there! 👋')
expect(messages[1].content.plainText).toBe("Welcome. What's your name?")
expect(messages[0].content.richText).toStrictEqual([
{ children: [{ text: 'Hi there! 👋' }], type: 'p' },
])
expect(messages[1].content.richText).toStrictEqual([
{ children: [{ text: "Welcome. What's your name?" }], type: 'p' },
])
expect(input.type).toBe('text input')
})
})
@@ -88,8 +92,12 @@ test('API chat execution should work on published bot', async ({ request }) => {
})
expect(result).toBeDefined()
expect(sessionId).toBeDefined()
expect(messages[0].content.plainText).toBe('Hi there! 👋')
expect(messages[1].content.plainText).toBe("Welcome. What's your name?")
expect(messages[0].content.richText).toStrictEqual([
{ children: [{ text: 'Hi there! 👋' }], type: 'p' },
])
expect(messages[1].content.richText).toStrictEqual([
{ children: [{ text: "Welcome. What's your name?" }], type: 'p' },
])
expect(input.type).toBe('text input')
})
@@ -99,7 +107,9 @@ test('API chat execution should work on published bot', async ({ request }) => {
data: { message: 'John', sessionId: chatSessionId },
})
).json()
expect(messages[0].content.plainText).toBe('Nice to meet you John')
expect(messages[0].content.richText).toStrictEqual([
{ children: [{ text: 'Nice to meet you John' }], type: 'p' },
])
expect(messages[1].content.url).toMatch(new RegExp('giphy.com', 'gm'))
expect(input.type).toBe('number input')
})
@@ -110,11 +120,18 @@ test('API chat execution should work on published bot', async ({ request }) => {
data: { message: '24', sessionId: chatSessionId },
})
).json()
expect(messages[0].content.plainText).toBe('Ok, you are an adult then 😁')
expect(messages[1].content.plainText).toBe('My magic number is 42')
expect(messages[2].content.plainText).toBe(
'How would you rate the experience so far?'
)
expect(messages[0].content.richText).toStrictEqual([
{ children: [{ text: 'Ok, you are an adult then 😁' }], type: 'p' },
])
expect(messages[1].content.richText).toStrictEqual([
{ children: [{ text: 'My magic number is 42' }], type: 'p' },
])
expect(messages[2].content.richText).toStrictEqual([
{
children: [{ text: 'How would you rate the experience so far?' }],
type: 'p',
},
])
expect(input.type).toBe('rating input')
})
@@ -124,9 +141,12 @@ test('API chat execution should work on published bot', async ({ request }) => {
data: { message: '8', sessionId: chatSessionId },
})
).json()
expect(messages[0].content.plainText).toBe(
"I'm gonna shoot multiple inputs now..."
)
expect(messages[0].content.richText).toStrictEqual([
{
children: [{ text: "I'm gonna shoot multiple inputs now..." }],
type: 'p',
},
])
expect(input.type).toBe('email input')
})
@@ -136,9 +156,16 @@ test('API chat execution should work on published bot', async ({ request }) => {
data: { message: 'invalid email', sessionId: chatSessionId },
})
).json()
expect(messages[0].content.plainText).toBe(
"This email doesn't seem to be valid. Can you type it again?"
)
expect(messages[0].content.richText).toStrictEqual([
{
children: [
{
text: "This email doesn't seem to be valid. Can you type it again?",
},
],
type: 'p',
},
])
expect(input.type).toBe('email input')
})
@@ -168,8 +195,26 @@ test('API chat execution should work on published bot', async ({ request }) => {
data: { message: 'Yes', sessionId: chatSessionId },
})
).json()
expect(messages[0].content.plainText).toBe('Ok, you are solid 👏')
expect(messages[1].content.plainText).toBe("Let's trigger a webhook...")
expect(messages[2].content.plainText.length).toBeGreaterThan(0)
expect(messages[0].content.richText).toStrictEqual([
{
children: [
{
text: 'Ok, you are solid 👏',
},
],
type: 'p',
},
])
expect(messages[1].content.richText).toStrictEqual([
{
children: [
{
text: "Let's trigger a webhook...",
},
],
type: 'p',
},
])
expect(messages[2].content.richText.length).toBeGreaterThan(0)
})
})

View File

@@ -133,8 +133,7 @@ const parseRetryMessage = (
id: block.id,
type: BubbleBlockType.TEXT,
content: {
plainText: retryMessage,
html: `<div>${retryMessage}</div>`,
richText: [{ type: 'p', children: [{ text: retryMessage }] }],
},
},
],

View File

@@ -1,70 +0,0 @@
import { getTestAsset } from '@/test/utils/playwright'
import test, { expect } from '@playwright/test'
import { createId } from '@paralleldrive/cuid2'
import { Plan } from '@typebot.io/prisma'
import { defaultSettings } from '@typebot.io/schemas'
import {
createWorkspaces,
importTypebotInDatabase,
injectFakeResults,
} from '@typebot.io/lib/playwright/databaseActions'
test('should not start if chat limit is reached', async ({ page, context }) => {
await test.step('Free plan', async () => {
const workspaceId = createId()
const typebotId = createId()
await createWorkspaces([{ id: workspaceId, plan: Plan.FREE }])
await importTypebotInDatabase(getTestAsset('typebots/fileUpload.json'), {
id: typebotId,
publicId: `${typebotId}-public`,
workspaceId,
})
await injectFakeResults({ typebotId, count: 400 })
await page.goto(`/${typebotId}-public`)
await expect(page.locator('text="This bot is now closed."')).toBeVisible()
await page.goto(`${process.env.NEXTAUTH_URL}/typebots/${typebotId}/results`)
await expect(page.locator('text="133%"')).toBeVisible()
})
await test.step('Lifetime plan', async () => {
const workspaceId = createId()
const typebotId = createId()
await createWorkspaces([{ id: workspaceId, plan: Plan.LIFETIME }])
await importTypebotInDatabase(getTestAsset('typebots/fileUpload.json'), {
id: typebotId,
publicId: `${typebotId}-public`,
workspaceId,
})
await injectFakeResults({ typebotId, count: 3000 })
await page.goto(`/${typebotId}-public`)
await expect(page.locator('text="Hey there, upload please"')).toBeVisible()
})
await test.step('Custom plan', async () => {
const workspaceId = createId()
const typebotId = createId()
await createWorkspaces([
{ id: workspaceId, plan: Plan.CUSTOM, customChatsLimit: 1000 },
])
await importTypebotInDatabase(getTestAsset('typebots/fileUpload.json'), {
id: typebotId,
publicId: `${typebotId}-public`,
workspaceId,
settings: {
...defaultSettings,
general: {
...defaultSettings.general,
isNewResultOnRefreshEnabled: true,
},
},
})
const page = await context.newPage()
await page.goto(`/${typebotId}-public`)
await expect(page.locator('text="Hey there, upload please"')).toBeVisible()
await injectFakeResults({ typebotId, count: 2000 })
await page.goto(`/${typebotId}-public`)
await expect(page.locator('text="This bot is now closed."')).toBeVisible()
await page.goto(`${process.env.NEXTAUTH_URL}/typebots/${typebotId}/results`)
await expect(page.locator('text="200%"')).toBeVisible()
})
})