Skip to content

Commit

Permalink
ci: βœ… Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 13, 2022
1 parent 7507a1a commit e268638
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 18 deletions.
2 changes: 1 addition & 1 deletion apps/builder/components/shared/Graph/Edges/Edges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Edges = ({
left="0"
top="0"
pointerEvents="none"
shape-rendering="geometricPrecision"
shapeRendering="geometricPrecision"
>
<DrawingEdge />
{edges.map((edge) => (
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/contexts/TypebotContext/TypebotContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) >
Expand Down
2 changes: 1 addition & 1 deletion apps/builder/playwright/tests/bubbles/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)
Expand Down
38 changes: 27 additions & 11 deletions apps/builder/services/utils/useUndo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +27,7 @@ export interface Actions<T> {
interface Action<T> {
type: ActionType
newPresent?: T
updateDate?: boolean
}

export interface State<T> {
Expand Down Expand Up @@ -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 &&
Expand All @@ -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: [],
}
}
Expand Down Expand Up @@ -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 })
Expand Down
15 changes: 15 additions & 0 deletions apps/viewer/pages/api/mock/fail.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions apps/viewer/pages/api/mock/success.ts
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 5 additions & 4 deletions apps/viewer/playwright/tests/webhook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

4 comments on commit e268638

@vercel
Copy link

@vercel vercel bot commented on e268638 May 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

landing-page-v2 – ./apps/landing-page

landing-page-v2-git-main-typebot-io.vercel.app
typebot.io
www.typebot.io
www.get-typebot.com
landing-page-v2-typebot-io.vercel.app
get-typebot.com

@vercel
Copy link

@vercel vercel bot commented on e268638 May 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on e268638 May 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.