2
0

🛠️ Adapt Cypress to Turbo Repo

This commit is contained in:
Baptiste Arnaud
2021-12-17 07:54:12 +01:00
parent 772b16c6ce
commit a54e42f255
13 changed files with 57 additions and 128 deletions

2
apps/builder/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
cypress/videos
cypress/screenshots

View File

@ -1,13 +1,13 @@
import { Flex } from '@chakra-ui/react' import { Flex } from '@chakra-ui/react'
import React from 'react' import React from 'react'
import StepsList from './StepTypesList'
import Graph from './graph/Graph' import Graph from './graph/Graph'
import { DndContext } from 'contexts/DndContext' import { DndContext } from 'contexts/DndContext'
import StepTypesList from './StepTypesList'
export const Board = () => ( export const Board = () => (
<Flex flex="1" pos="relative" bgColor="gray.50"> <Flex flex="1" pos="relative" bgColor="gray.50">
<DndContext> <DndContext>
<StepsList /> <StepTypesList />
<Graph /> <Graph />
</DndContext> </DndContext>
</Flex> </Flex>

View File

@ -10,7 +10,6 @@ import { StartBlockNode } from './BlockNode/StartBlockNode'
const Graph = () => { const Graph = () => {
const { draggedStepType, setDraggedStepType, draggedStep, setDraggedStep } = const { draggedStepType, setDraggedStepType, draggedStep, setDraggedStep } =
useDnd() useDnd()
const graphRef = useRef<HTMLDivElement | null>(null)
const graphContainerRef = useRef<HTMLDivElement | null>(null) const graphContainerRef = useRef<HTMLDivElement | null>(null)
const { typebot } = useTypebot() const { typebot } = useTypebot()
const { const {
@ -59,8 +58,8 @@ const Graph = () => {
addNewBlock({ addNewBlock({
step: draggedStep, step: draggedStep,
type: draggedStepType, type: draggedStepType,
x: e.x - graphPosition.x - blockWidth / 3, x: e.clientX - graphPosition.x - blockWidth / 3,
y: e.y - graphPosition.y - 20, y: e.clientY - graphPosition.y - 20,
}) })
setDraggedStep(undefined) setDraggedStep(undefined)
setDraggedStepType(undefined) setDraggedStepType(undefined)
@ -69,11 +68,10 @@ const Graph = () => {
if (!typebot) return <></> if (!typebot) return <></>
return ( return (
<Flex ref={graphContainerRef} pos="relative" flex="1" h="full"> <Flex ref={graphContainerRef} flex="1" h="full">
<Flex <Flex
ref={graphRef}
flex="1" flex="1"
h="full" boxSize={'200px'}
style={{ style={{
transform, transform,
}} }}

View File

@ -85,7 +85,7 @@ export const TypebotButton = ({
mb={6} mb={6}
rounded="lg" rounded="lg"
whiteSpace="normal" whiteSpace="normal"
data-testid="typebot-button" data-testid={`typebot-button-${typebot.id}`}
opacity={isDragging ? 0.2 : 1} opacity={isDragging ? 0.2 : 1}
ref={setNodeRef} ref={setNodeRef}
{...listeners} {...listeners}

View File

@ -3,5 +3,6 @@
"chromeWebSecurity": false, "chromeWebSecurity": false,
"integrationFolder": "cypress/tests", "integrationFolder": "cypress/tests",
"viewportWidth": 1400, "viewportWidth": 1400,
"viewportHeight": 800 "viewportHeight": 800,
"video": false
} }

View File

@ -1,5 +1,5 @@
import { PrismaClient } from '.prisma/client' import { PrismaClient } from '.prisma/client'
import { StartBlock, StepType } from 'bot-engine' import { Block, StartBlock, StepType } from 'bot-engine'
const prisma = new PrismaClient() const prisma = new PrismaClient()
@ -37,11 +37,42 @@ const createTypebots = () => {
label: 'Start', label: 'Start',
}, },
], ],
title: 'Start', title: 'Home',
} }
prisma.typebot.createMany({ const blocks: Block[] = [
{
id: 'block1',
title: 'Block1',
graphCoordinates: { x: 150, y: 150 },
steps: [
{ id: 'step1', blockId: 'block1', type: StepType.TEXT, content: '' },
{
id: 'step2',
blockId: 'block1',
type: StepType.DATE_PICKER,
content: '',
},
],
},
{
id: 'block2',
title: 'Block2',
graphCoordinates: { x: 300, y: 300 },
steps: [
{ id: 'step1', blockId: 'block2', type: StepType.TEXT, content: '' },
],
},
]
return prisma.typebot.createMany({
data: [ data: [
{ id: 'typebot1', name: 'Typebot #1', ownerId: 'test2', startBlock }, { id: 'typebot1', name: 'Typebot #1', ownerId: 'test2', startBlock },
{
id: 'typebot2',
name: 'Typebot #2',
ownerId: 'test2',
startBlock,
blocks,
},
], ],
}) })
} }

View File

@ -1,104 +0,0 @@
describe('SignIn page', () => {
beforeEach(() => {
cy.signOut()
})
it('can continue with Google', () => {
cy.visit('/signin')
const username = Cypress.env('GOOGLE_USER')
const password = Cypress.env('GOOGLE_PW')
const loginUrl = Cypress.env('SITE_NAME')
const cookieName = Cypress.env('COOKIE_NAME')
exectueSocialLogin(
'GoogleSocialLogin',
username,
password,
loginUrl,
cookieName
)
})
it('can continue with GitHub', () => {
cy.visit('/signin')
const username = Cypress.env('GITHUB_USER')
const password = Cypress.env('GITHUB_PW')
const loginUrl = Cypress.env('SITE_NAME')
const cookieName = Cypress.env('COOKIE_NAME')
exectueSocialLogin(
'GitHubSocialLogin',
username,
password,
loginUrl,
cookieName
)
})
it('can continue with Facebook', () => {
cy.visit('/signin')
const username = Cypress.env('FACEBOOK_USER')
const password = Cypress.env('FACEBOOK_PW')
const loginUrl = Cypress.env('SITE_NAME')
const cookieName = Cypress.env('COOKIE_NAME')
exectueSocialLogin(
'FacebookSocialLogin',
username,
password,
loginUrl,
cookieName,
[
'button[data-testid="cookie-policy-dialog-manage-button"]',
'button[data-testid="cookie-policy-manage-dialog-accept-button"]',
]
)
})
// We don't test email sign in because disabling email sending is not straightforward
})
const exectueSocialLogin = (
task: 'FacebookSocialLogin' | 'GoogleSocialLogin' | 'GitHubSocialLogin',
username: string,
password: string,
loginUrl: string,
cookieName: string,
trackingConsentSelectors?: string[]
) => {
const selectorId =
task === 'FacebookSocialLogin'
? 'facebook'
: task === 'GoogleSocialLogin'
? 'google'
: 'github'
const socialLoginOptions = {
username,
password,
loginUrl,
headless: true,
logs: true,
isPopup: false,
loginSelector: `[data-testid="${selectorId}"]`,
postLoginSelector: `[data-testid="authenticated"]`,
trackingConsentSelectors,
}
cy.task(task, socialLoginOptions).then(({ cookies }: any) => {
const cookie = cookies
.filter((cookie: any) => cookie.name === cookieName)
.pop()
if (cookie) {
cy.setCookie(cookie.name, cookie.value, {
domain: cookie.domain,
expiry: cookie.expires,
httpOnly: cookie.httpOnly,
path: cookie.path,
secure: cookie.secure,
})
Cypress.Cookies.defaults({
preserve: cookieName,
})
}
cy.visit('/typebots')
cy.findByRole('button', { name: 'Create a folder' }).should('exist')
})
}

View File

@ -3,8 +3,10 @@ describe('BoardPage', () => {
cy.task('seed') cy.task('seed')
cy.signOut() cy.signOut()
}) })
it('steps should be droppable', () => { it('steps should be droppable', () => {
cy.signIn('test2@gmail.com') cy.signIn('test2@gmail.com')
cy.visit('/typebots/typebot1') cy.visit('/typebots/typebot1')
// Can't find an easy way to implement this
}) })
}) })

View File

@ -29,11 +29,11 @@ describe('Dashboard page', () => {
it('should be droppable', () => { it('should be droppable', () => {
cy.signIn('test2@gmail.com') cy.signIn('test2@gmail.com')
cy.visit('/typebots') cy.visit('/typebots')
cy.findByTestId('typebot-button').mouseMoveBy(-100, 0, { cy.findByTestId('typebot-button-typebot1').mouseMoveBy(-100, 0, {
delay: 120, delay: 120,
}) })
cy.visit('/typebots/folders/folder1') cy.visit('/typebots/folders/folder1')
cy.findByTestId('typebot-button').mouseMoveBy(-300, -100, { cy.findByTestId('typebot-button-typebot1').mouseMoveBy(-300, -100, {
delay: 120, delay: 120,
}) })
cy.visit('/typebots') cy.visit('/typebots')

View File

@ -9,6 +9,7 @@
"isolatedModules": false, "isolatedModules": false,
"allowJs": true, "allowJs": true,
"noEmit": true, "noEmit": true,
"downlevelIteration": true "downlevelIteration": true,
"jsx": "react"
} }
} }

View File

@ -2,7 +2,7 @@
"name": "builder", "name": "builder",
"version": "0.1.0", "version": "0.1.0",
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev -p 3000",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
"lint": "next lint", "lint": "next lint",

View File

@ -6,14 +6,11 @@
"apps/*" "apps/*"
], ],
"scripts": { "scripts": {
"builder": "yarn workspace builder", "docker:up": "docker-compose up -d",
"viewer": "yarn workspace viewer",
"db": "yarn workspace db",
"bot-engine": "yarn workspace bot-engine",
"db:up": "docker-compose up -d && yarn db prisma db push",
"db:nuke": "docker-compose down --volumes --remove-orphans", "db:nuke": "docker-compose down --volumes --remove-orphans",
"dev": "dotenv -e .env yarn docker:up && dotenv -e .env turbo run dev --parallel",
"build": "dotenv -e .env turbo run build", "build": "dotenv -e .env turbo run build",
"dev": "dotenv -e .env yarn db:up && turbo run dev --parallel", "test": "dotenv -e .env turbo run dev test",
"lint": "turbo run lint" "lint": "turbo run lint"
}, },
"devDependencies": { "devDependencies": {
@ -33,7 +30,7 @@
}, },
"test": { "test": {
"dependsOn": [ "dependsOn": [
"^build" "^dev"
], ],
"outputs": [] "outputs": []
}, },

View File

@ -12,6 +12,7 @@
"@prisma/client": "latest" "@prisma/client": "latest"
}, },
"scripts": { "scripts": {
"dev": "yarn prisma db push",
"build": "prisma generate && prisma migrate deploy" "build": "prisma generate && prisma migrate deploy"
} }
} }