♻️ 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()
})
})

View File

@@ -27,7 +27,6 @@
"type": "text",
"groupId": "kinRXxYop2X4d7F9qt8WNB",
"content": {
"html": "<div>Welcome to <span class=\"slate-bold\">AA</span> (Awesome Agency)</div>",
"richText": [
{
"type": "p",
@@ -37,8 +36,7 @@
{ "text": " (Awesome Agency)" }
]
}
],
"plainText": "Welcome to AA (Awesome Agency)"
]
}
},
{
@@ -76,14 +74,12 @@
"type": "text",
"groupId": "o4SH1UtKANnW5N5D67oZUz",
"content": {
"html": "<div>Great! Nice to meet you {{Name}}</div>",
"richText": [
{
"type": "p",
"children": [{ "text": "Great! Nice to meet you {{Name}}" }]
}
],
"plainText": "Great! Nice to meet you {{Name}}"
]
}
},
{
@@ -91,7 +87,6 @@
"type": "text",
"groupId": "o4SH1UtKANnW5N5D67oZUz",
"content": {
"html": "<div>What&#x27;s the best email we can reach you at?</div>",
"richText": [
{
"type": "p",
@@ -99,8 +94,7 @@
{ "text": "What's the best email we can reach you at?" }
]
}
],
"plainText": "What's the best email we can reach you at?"
]
}
},
{
@@ -125,11 +119,9 @@
"type": "text",
"groupId": "q5dAhqSTCaNdiGSJm9B9Rw",
"content": {
"html": "<div>What&#x27;s your name?</div>",
"richText": [
{ "type": "p", "children": [{ "text": "What's your name?" }] }
],
"plainText": "What's your name?"
]
}
},
{
@@ -158,14 +150,12 @@
"type": "text",
"groupId": "fKqRz7iswk7ULaj5PJocZL",
"content": {
"html": "<div>What services are you interested in?</div>",
"richText": [
{
"type": "p",
"children": [{ "text": "What services are you interested in?" }]
}
],
"plainText": "What services are you interested in?"
]
}
},
{
@@ -213,7 +203,6 @@
"type": "text",
"groupId": "7qHBEyCMvKEJryBHzPmHjV",
"content": {
"html": "<div>Can you tell me a bit more about your needs?</div>",
"richText": [
{
"type": "p",
@@ -221,8 +210,7 @@
{ "text": "Can you tell me a bit more about your needs?" }
]
}
],
"plainText": "Can you tell me a bit more about your needs?"
]
}
},
{
@@ -247,9 +235,7 @@
"type": "text",
"groupId": "vF7AD7zSAj7SNvN3gr9N94",
"content": {
"html": "<div>Perfect!</div>",
"richText": [{ "type": "p", "children": [{ "text": "Perfect!" }] }],
"plainText": "Perfect!"
"richText": [{ "type": "p", "children": [{ "text": "Perfect!" }] }]
}
},
{
@@ -257,14 +243,12 @@
"type": "text",
"groupId": "vF7AD7zSAj7SNvN3gr9N94",
"content": {
"html": "<div>We&#x27;ll get back to you at {{Email}}</div>",
"richText": [
{
"type": "p",
"children": [{ "text": "We'll get back to you at {{Email}}" }]
}
],
"plainText": "We'll get back to you at {{Email}}"
]
},
"outgoingEdgeId": "fTVo43AG97eKcaTrZf9KyV"
}

View File

@@ -28,7 +28,6 @@
"id": "clauupd6q00193b6qhegmlnxj",
"type": "text",
"content": {
"html": "<div>How would you rate the experience so far?</div>",
"richText": [
{
"type": "p",
@@ -36,8 +35,7 @@
{ "text": "How would you rate the experience so far?" }
]
}
],
"plainText": "How would you rate the experience so far?"
]
},
"groupId": "clauupd6q00183b6qcm8qbz62"
},

View File

@@ -28,11 +28,9 @@
"id": "clauujxdd00073b6qpejnkzcy",
"type": "text",
"content": {
"html": "<div>Hi there! 👋</div>",
"richText": [
{ "type": "p", "children": [{ "text": "Hi there! 👋" }] }
],
"plainText": "Hi there! 👋"
]
},
"groupId": "clauujxdc00063b6q42ca20gj"
},
@@ -40,14 +38,12 @@
"id": "clauukaad00093b6q07av51yc",
"type": "text",
"content": {
"html": "<div>Welcome. What&apos;s your name?</div>",
"richText": [
{
"type": "p",
"children": [{ "text": "Welcome. What's your name?" }]
}
],
"plainText": "Welcome. What's your name?"
]
},
"groupId": "clauujxdc00063b6q42ca20gj"
},
@@ -76,14 +72,12 @@
"id": "clauukoka000d3b6qxqi38cmk",
"type": "text",
"content": {
"html": "<div>Nice to meet you {{Name}}</div>",
"richText": [
{
"type": "p",
"children": [{ "text": "Nice to meet you {{Name}}" }]
}
],
"plainText": "Nice to meet you {{Name}}"
]
},
"groupId": "clauukoka000c3b6qe6chawis"
},
@@ -99,11 +93,9 @@
"id": "clauul4vg000g3b6qr0q2h0uy",
"type": "text",
"content": {
"html": "<div>How old are you?</div>",
"richText": [
{ "type": "p", "children": [{ "text": "How old are you?" }] }
],
"plainText": "How old are you?"
]
},
"groupId": "clauukoka000c3b6qe6chawis"
},
@@ -160,14 +152,12 @@
"id": "clauum8x7000p3b6qxjud5hdc",
"type": "text",
"content": {
"html": "<div>Ok, you are an adult then 😁</div>",
"richText": [
{
"type": "p",
"children": [{ "text": "Ok, you are an adult then 😁" }]
}
],
"plainText": "Ok, you are an adult then 😁"
]
},
"groupId": "clauum8x7000o3b6qx8hqduf8",
"outgoingEdgeId": "clauuom2y000y3b6qkcjy2ri7"
@@ -183,11 +173,9 @@
"id": "clauumjq5000s3b6qqjhrklv4",
"type": "text",
"content": {
"html": "<div>Oh, you are a kid 😁</div>",
"richText": [
{ "type": "p", "children": [{ "text": "Oh, you are a kid 😁" }] }
],
"plainText": "Oh, you are a kid 😁"
]
},
"groupId": "clauumjq4000r3b6q8l6bi9ra",
"outgoingEdgeId": "clauuol8t000x3b6qcw1few70"
@@ -212,14 +200,12 @@
"id": "clauuontu000z3b6q3ydx6ao1",
"type": "text",
"content": {
"html": "<div>My magic number is {{Magic number}}</div>",
"richText": [
{
"type": "p",
"children": [{ "text": "My magic number is {{Magic number}}" }]
}
],
"plainText": "My magic number is {{Magic number}}"
]
},
"groupId": "clauuoekh000u3b6q6zmlx7f9",
"outgoingEdgeId": "clauuq8je001e3b6qksm4j11g"
@@ -254,7 +240,6 @@
"groupId": "clauur7od001f3b6qq140oe55",
"type": "text",
"content": {
"html": "<div>I&apos;m gonna shoot multiple inputs now...</div>",
"richText": [
{
"type": "p",
@@ -262,8 +247,7 @@
{ "text": "I'm gonna shoot multiple inputs now..." }
]
}
],
"plainText": "I'm gonna shoot multiple inputs now..."
]
}
},
{
@@ -317,11 +301,9 @@
"groupId": "clauusa9z001n3b6qys3xvz1l",
"type": "text",
"content": {
"html": "<div>Ok, you are solid 👏</div>",
"richText": [
{ "type": "p", "children": [{ "text": "Ok, you are solid 👏" }] }
],
"plainText": "Ok, you are solid 👏"
]
}
},
{
@@ -329,14 +311,12 @@
"groupId": "clauusa9z001n3b6qys3xvz1l",
"type": "text",
"content": {
"html": "<div>Let&apos;s trigger a webhook...</div>",
"richText": [
{
"type": "p",
"children": [{ "text": "Let's trigger a webhook..." }]
}
],
"plainText": "Let's trigger a webhook..."
]
}
},
{
@@ -370,9 +350,7 @@
"groupId": "clauuwhyl001v3b6qarbpiqbv",
"type": "text",
"content": {
"html": "<div>{{Joke}}</div>",
"richText": [{ "type": "p", "children": [{ "text": "{{Joke}}" }] }],
"plainText": "{{Joke}}"
"richText": [{ "type": "p", "children": [{ "text": "{{Joke}}" }] }]
}
}
]

View File

@@ -28,14 +28,12 @@
"type": "text",
"groupId": "cl45ojrrd00062e6g17tuu9t0",
"content": {
"html": "<div>Hey there, upload please</div>",
"richText": [
{
"type": "p",
"children": [{ "text": "Hey there, upload please" }]
}
],
"plainText": "Hey there, upload please"
]
}
},
{
@@ -64,11 +62,9 @@
"type": "text",
"groupId": "cl45ok963000b2e6g2ky0wkvx",
"content": {
"html": "<div>Thank you!</div>",
"richText": [
{ "type": "p", "children": [{ "text": "Thank you!" }] }
],
"plainText": "Thank you!"
]
}
}
],

View File

@@ -27,11 +27,9 @@
"type": "text",
"groupId": "2Vrpgk5VP9BUo3vKtM5kws",
"content": {
"html": "<div>Hi what&#x27;s your name?</div>",
"richText": [
{ "type": "p", "children": [{ "text": "Hi what's your name?" }] }
],
"plainText": "Hi what's your name?"
]
}
},
{
@@ -52,11 +50,9 @@
"type": "text",
"groupId": "2Vrpgk5VP9BUo3vKtM5kws",
"content": {
"html": "<div>How old are you?</div>",
"richText": [
{ "type": "p", "children": [{ "text": "How old are you?" }] }
],
"plainText": "How old are you?"
]
}
},
{
@@ -72,9 +68,7 @@
"type": "text",
"groupId": "2Vrpgk5VP9BUo3vKtM5kws",
"content": {
"html": "<div>Cool!</div>",
"richText": [{ "type": "p", "children": [{ "text": "Cool!" }] }],
"plainText": "Cool!"
"richText": [{ "type": "p", "children": [{ "text": "Cool!" }] }]
}
},
{
@@ -82,11 +76,9 @@
"type": "text",
"groupId": "2Vrpgk5VP9BUo3vKtM5kws",
"content": {
"html": "<div>Do you eat pizza?</div>",
"richText": [
{ "type": "p", "children": [{ "text": "Do you eat pizza?" }] }
],
"plainText": "Do you eat pizza?"
]
}
},
{

View File

@@ -47,9 +47,7 @@
"groupId": "clbovb3vu00103b6o1pjjuagi",
"type": "text",
"content": {
"html": "<div>Cheers!</div>",
"richText": [{ "type": "p", "children": [{ "text": "Cheers!" }] }],
"plainText": "Cheers!"
"richText": [{ "type": "p", "children": [{ "text": "Cheers!" }] }]
}
}
]

View File

@@ -29,11 +29,9 @@
"groupId": "cl13bgy1s00042e6dao1wyobm",
"type": "text",
"content": {
"html": "<div>Hey I know you!</div>",
"richText": [
{ "type": "p", "children": [{ "text": "Hey I know you!" }] }
],
"plainText": "Hey I know you!"
]
}
},
{
@@ -41,11 +39,9 @@
"groupId": "cl13bgy1s00042e6dao1wyobm",
"type": "text",
"content": {
"html": "<div>Your name is {{Name}}</div>",
"richText": [
{ "type": "p", "children": [{ "text": "Your name is {{Name}}" }] }
],
"plainText": "Your name is {{Name}}"
]
}
},
{
@@ -53,11 +49,9 @@
"groupId": "cl13bgy1s00042e6dao1wyobm",
"type": "text",
"content": {
"html": "<div>What&#x27;s your email?</div>",
"richText": [
{ "type": "p", "children": [{ "text": "What's your email?" }] }
],
"plainText": "What's your email?"
]
}
},
{

View File

@@ -74,11 +74,9 @@
"groupId": "clbnrp1kt000o3b6o2bh5ny0r",
"type": "text",
"content": {
"html": "<div>Email sent!</div>",
"richText": [
{ "type": "p", "children": [{ "text": "Email sent!" }] }
],
"plainText": "Email sent!"
]
}
}
]

View File

@@ -108,7 +108,6 @@
"groupId": "cl9ipbcjy000j3b6oqngo7luv",
"type": "text",
"content": {
"html": "<div>Data of first request:</div><div></div><div>{{Data}}</div>",
"richText": [
{
"type": "p",
@@ -116,8 +115,7 @@
},
{ "type": "p", "children": [{ "text": "" }] },
{ "type": "p", "children": [{ "text": "{{Data}}" }] }
],
"plainText": "Data of first request:{{Data}}"
]
},
"outgoingEdgeId": "cl9ipet83000z3b6of6zfqota"
}
@@ -151,7 +149,6 @@
"groupId": "cl9ipej6b000u3b6oeaz305l6",
"type": "text",
"content": {
"html": "<div>Data of second request:</div><div></div><div>{{Data}}</div>",
"richText": [
{
"type": "p",
@@ -159,8 +156,7 @@
},
{ "type": "p", "children": [{ "text": "" }] },
{ "type": "p", "children": [{ "text": "{{Data}}" }] }
],
"plainText": "Data of second request:{{Data}}"
]
}
}
]