ci: ✅ Fix e2e tests
This commit is contained in:
@ -26,7 +26,7 @@ export const Edges = ({
|
||||
left="0"
|
||||
top="0"
|
||||
pointerEvents="none"
|
||||
shape-rendering="geometricPrecision"
|
||||
shapeRendering="geometricPrecision"
|
||||
>
|
||||
<DrawingEdge />
|
||||
{edges.map((edge) => (
|
||||
|
@ -162,7 +162,7 @@ export const TypebotContext = ({
|
||||
useEffect(() => {
|
||||
if (!typebot || !currentTypebotRef.current) return
|
||||
if (typebotId !== currentTypebotRef.current.id) {
|
||||
setLocalTypebot({ ...typebot })
|
||||
setLocalTypebot({ ...typebot }, { updateDate: false })
|
||||
flush()
|
||||
} else if (
|
||||
new Date(typebot.updatedAt) >
|
||||
|
@ -84,7 +84,7 @@ test.describe.parallel('Image bubble step', () => {
|
||||
force: true,
|
||||
position: { x: 0, y: 0 },
|
||||
})
|
||||
await expect(page.locator('img[alt="Step image"]')).toHaveAttribute(
|
||||
await expect(page.locator('img[alt="Block image"]')).toHaveAttribute(
|
||||
'src',
|
||||
new RegExp('giphy.com/media', 'gm')
|
||||
)
|
||||
|
@ -12,7 +12,10 @@ enum ActionType {
|
||||
}
|
||||
|
||||
export interface Actions<T> {
|
||||
set: (newPresent: T | ((current: T) => T)) => void
|
||||
set: (
|
||||
newPresent: T | ((current: T) => T),
|
||||
options?: { updateDate: boolean }
|
||||
) => void
|
||||
undo: () => void
|
||||
redo: () => void
|
||||
flush: () => void
|
||||
@ -24,6 +27,7 @@ export interface Actions<T> {
|
||||
interface Action<T> {
|
||||
type: ActionType
|
||||
newPresent?: T
|
||||
updateDate?: boolean
|
||||
}
|
||||
|
||||
export interface State<T> {
|
||||
@ -72,7 +76,7 @@ const reducer = <T>(state: State<T>, action: Action<T>) => {
|
||||
}
|
||||
|
||||
case ActionType.Set: {
|
||||
const { newPresent } = action
|
||||
const { newPresent, updateDate } = action
|
||||
if (
|
||||
isNotDefined(newPresent) ||
|
||||
(present &&
|
||||
@ -92,7 +96,12 @@ const reducer = <T>(state: State<T>, action: Action<T>) => {
|
||||
// )
|
||||
return {
|
||||
past: [...past, present].filter(isDefined),
|
||||
present: { ...newPresent, updatedAt: new Date() },
|
||||
present: {
|
||||
...newPresent,
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
updatedAt: updateDate ? new Date() : newPresent.updatedAt,
|
||||
},
|
||||
future: [],
|
||||
}
|
||||
}
|
||||
@ -124,14 +133,21 @@ const useUndo = <T>(initialPresent: T): [State<T>, Actions<T>] => {
|
||||
}
|
||||
}, [canRedo])
|
||||
|
||||
const set = useCallback((newPresent: T | ((current: T) => T)) => {
|
||||
const updatedTypebot =
|
||||
'id' in newPresent
|
||||
? newPresent
|
||||
: (newPresent as (current: T) => T)(presentRef.current)
|
||||
presentRef.current = updatedTypebot
|
||||
dispatch({ type: ActionType.Set, newPresent: updatedTypebot })
|
||||
}, [])
|
||||
const set = useCallback(
|
||||
(newPresent: T | ((current: T) => T), options = { updateDate: true }) => {
|
||||
const updatedTypebot =
|
||||
'id' in newPresent
|
||||
? newPresent
|
||||
: (newPresent as (current: T) => T)(presentRef.current)
|
||||
presentRef.current = updatedTypebot
|
||||
dispatch({
|
||||
type: ActionType.Set,
|
||||
newPresent: updatedTypebot,
|
||||
updateDate: options.updateDate,
|
||||
})
|
||||
},
|
||||
[]
|
||||
)
|
||||
|
||||
const flush = useCallback(() => {
|
||||
dispatch({ type: ActionType.Flush })
|
||||
|
15
apps/viewer/pages/api/mock/fail.ts
Normal file
15
apps/viewer/pages/api/mock/fail.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { withSentry } from '@sentry/nextjs'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { methodNotAllowed } from 'utils'
|
||||
|
||||
const handler = (req: NextApiRequest, res: NextApiResponse) => {
|
||||
if (req.method === 'POST') {
|
||||
return res.status(500).json({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Fail',
|
||||
})
|
||||
}
|
||||
methodNotAllowed(res)
|
||||
}
|
||||
|
||||
export default withSentry(handler)
|
15
apps/viewer/pages/api/mock/success.ts
Normal file
15
apps/viewer/pages/api/mock/success.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { withSentry } from '@sentry/nextjs'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { methodNotAllowed } from 'utils'
|
||||
|
||||
const handler = (req: NextApiRequest, res: NextApiResponse) => {
|
||||
if (req.method === 'POST') {
|
||||
return res.status(200).json({
|
||||
statusCode: 200,
|
||||
statusMessage: 'OK',
|
||||
})
|
||||
}
|
||||
methodNotAllowed(res)
|
||||
}
|
||||
|
||||
export default withSentry(handler)
|
@ -13,21 +13,22 @@ test('should execute webhooks properly', async ({ page }) => {
|
||||
)
|
||||
await createWebhook(typebotId, {
|
||||
id: 'success-webhook',
|
||||
url: 'https://webhook.site/912bafb0-b92f-4be8-ae6a-186b5879a17a',
|
||||
url: 'http://localhost:3001/api/mock/success',
|
||||
method: HttpMethod.POST,
|
||||
})
|
||||
await createWebhook(typebotId, {
|
||||
id: 'failed-webhook',
|
||||
url: 'https://webhook.site/8be94c01-141e-4792-b3c6-cf45137481d6',
|
||||
url: 'http://localhost:3001/api/mock/fail',
|
||||
method: HttpMethod.POST,
|
||||
})
|
||||
|
||||
await page.goto(`/${typebotId}-public`)
|
||||
await typebotViewer(page).locator('text=Send success webhook').click()
|
||||
await page.waitForResponse(
|
||||
(resp) =>
|
||||
async (resp) =>
|
||||
resp.request().url().includes(`/api/typebots/${typebotId}/blocks`) &&
|
||||
resp.status() === 200
|
||||
resp.status() === 200 &&
|
||||
(await resp.json()).statusCode === 200
|
||||
)
|
||||
await typebotViewer(page).locator('text=Send failed webhook').click()
|
||||
await page.waitForResponse(
|
||||
|
Reference in New Issue
Block a user