2
0
Files
bot/apps/builder/cypress/plugins/utils.ts

85 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-01-06 09:40:56 +01:00
import {
Block,
Theme,
BackgroundType,
Settings,
Typebot,
Table,
Step,
2022-01-12 09:10:59 +01:00
ChoiceItem,
2022-01-06 09:40:56 +01:00
} from 'models'
export const parseTestTypebot = ({
id,
ownerId,
name,
blocks,
steps,
2022-01-12 09:10:59 +01:00
choiceItems,
2022-01-06 09:40:56 +01:00
}: {
id: string
ownerId: string
name: string
blocks: Table<Block>
steps: Table<Step>
2022-01-12 09:10:59 +01:00
choiceItems?: Table<ChoiceItem>
2022-01-06 09:40:56 +01:00
}): Typebot => {
const theme: Theme = {
general: {
font: 'Open Sans',
background: { type: BackgroundType.NONE, content: '#ffffff' },
},
}
const settings: Settings = {
typingEmulation: {
enabled: true,
speed: 300,
maxDelay: 1.5,
},
}
return {
id,
folderId: null,
name,
ownerId,
theme,
settings,
createdAt: new Date(),
blocks: {
byId: {
block0: {
id: 'block0',
title: 'Block #0',
stepIds: ['step0'],
graphCoordinates: { x: 0, y: 0 },
},
...blocks.byId,
},
allIds: ['block0', ...blocks.allIds],
},
steps: {
byId: {
step0: {
id: 'step0',
2022-01-08 07:40:55 +01:00
type: 'start',
2022-01-06 09:40:56 +01:00
blockId: 'block0',
label: 'Start',
target: { blockId: 'block1' },
},
...steps.byId,
},
allIds: ['step0', ...steps.allIds],
},
2022-01-12 09:10:59 +01:00
choiceItems: choiceItems ?? { byId: {}, allIds: [] },
2022-01-06 09:40:56 +01:00
publicId: null,
publishedTypebotId: null,
updatedAt: new Date(),
variables: { byId: {}, allIds: [] },
2022-01-06 09:40:56 +01:00
}
}
export const preventUserFromRefreshing = (e: BeforeUnloadEvent) => {
e.preventDefault()
e.returnValue = ''
}