2022-01-08 08:38:39 +01:00
|
|
|
import {
|
|
|
|
parseTestTypebot,
|
|
|
|
preventUserFromRefreshing,
|
|
|
|
} from 'cypress/plugins/utils'
|
2022-01-08 07:40:55 +01:00
|
|
|
import { InputStep, InputStepType } from 'models'
|
2022-01-06 16:54:23 +01:00
|
|
|
|
|
|
|
describe('Text input', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.task('seed')
|
2022-01-08 07:40:55 +01:00
|
|
|
createTypebotWithStep({ type: InputStepType.TEXT })
|
2022-01-06 16:54:23 +01:00
|
|
|
cy.signOut()
|
|
|
|
})
|
|
|
|
|
2022-01-08 08:38:39 +01:00
|
|
|
afterEach(() => {
|
|
|
|
cy.window().then((win) => {
|
|
|
|
win.removeEventListener('beforeunload', preventUserFromRefreshing)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-01-08 07:40:55 +01:00
|
|
|
it('options should work', () => {
|
2022-01-06 16:54:23 +01:00
|
|
|
cy.signIn('test2@gmail.com')
|
|
|
|
cy.visit('/typebots/typebot3/edit')
|
|
|
|
cy.findByRole('button', { name: 'Preview' }).click()
|
2022-01-09 07:36:29 +01:00
|
|
|
getIframeBody()
|
|
|
|
.findByPlaceholderText('Type your answer...')
|
|
|
|
.should('have.attr', 'type')
|
|
|
|
.should('equal', 'text')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Send' }).should('be.disabled')
|
2022-01-06 16:54:23 +01:00
|
|
|
cy.findByTestId('step-step1').click({ force: true })
|
|
|
|
cy.findByRole('textbox', { name: 'Placeholder:' })
|
|
|
|
.clear()
|
|
|
|
.type('Your name...')
|
|
|
|
cy.findByRole('textbox', { name: 'Button label:' }).clear().type('Go')
|
|
|
|
cy.findByRole('button', { name: 'Restart' }).click()
|
2022-01-08 07:40:55 +01:00
|
|
|
cy.findByTestId('step-step1').should('contain.text', 'Your name...')
|
2022-01-06 16:54:23 +01:00
|
|
|
getIframeBody().findByPlaceholderText('Your name...').should('exist')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Go' })
|
|
|
|
cy.findByTestId('step-step1').click({ force: true })
|
|
|
|
cy.findByRole('checkbox', { name: 'Long text?' }).check({ force: true })
|
|
|
|
cy.findByRole('button', { name: 'Restart' }).click()
|
|
|
|
getIframeBody().findByTestId('textarea').should('exist')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-01-08 07:40:55 +01:00
|
|
|
describe('Number input', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.task('seed')
|
|
|
|
createTypebotWithStep({ type: InputStepType.NUMBER })
|
|
|
|
cy.signOut()
|
|
|
|
})
|
|
|
|
|
2022-01-08 08:20:54 +01:00
|
|
|
it('options should work', () => {
|
2022-01-08 07:40:55 +01:00
|
|
|
cy.signIn('test2@gmail.com')
|
|
|
|
cy.visit('/typebots/typebot3/edit')
|
|
|
|
cy.findByRole('button', { name: 'Preview' }).click()
|
2022-01-09 07:36:29 +01:00
|
|
|
getIframeBody()
|
|
|
|
.findByPlaceholderText('Type your answer...')
|
|
|
|
.should('have.attr', 'type')
|
|
|
|
.should('equal', 'number')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Send' }).should('be.disabled')
|
2022-01-08 07:40:55 +01:00
|
|
|
cy.findByTestId('step-step1').click({ force: true })
|
|
|
|
cy.findByRole('textbox', { name: 'Placeholder:' })
|
|
|
|
.clear()
|
|
|
|
.type('Your name...')
|
|
|
|
cy.findByRole('textbox', { name: 'Button label:' }).clear().type('Go')
|
|
|
|
cy.findByRole('spinbutton', { name: 'Min:' }).type('0')
|
|
|
|
cy.findByRole('spinbutton', { name: 'Max:' }).type('100')
|
|
|
|
cy.findByRole('spinbutton', { name: 'Step:' }).type('10')
|
|
|
|
cy.findByRole('button', { name: 'Restart' }).click()
|
|
|
|
cy.findByTestId('step-step1').should('contain.text', 'Your name...')
|
|
|
|
getIframeBody()
|
|
|
|
.findByPlaceholderText('Your name...')
|
|
|
|
.should('exist')
|
|
|
|
.type('-1{enter}')
|
|
|
|
.clear()
|
|
|
|
.type('150{enter}')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Go' })
|
|
|
|
cy.findByTestId('step-step1').click({ force: true })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-01-08 08:20:54 +01:00
|
|
|
describe('Email input', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.task('seed')
|
|
|
|
createTypebotWithStep({ type: InputStepType.EMAIL })
|
|
|
|
cy.signOut()
|
|
|
|
})
|
|
|
|
|
2022-01-08 08:38:39 +01:00
|
|
|
it('options should work', () => {
|
2022-01-08 08:20:54 +01:00
|
|
|
cy.signIn('test2@gmail.com')
|
|
|
|
cy.visit('/typebots/typebot3/edit')
|
|
|
|
cy.findByRole('button', { name: 'Preview' }).click()
|
2022-01-09 07:36:29 +01:00
|
|
|
getIframeBody()
|
|
|
|
.findByPlaceholderText('Type your email...')
|
|
|
|
.should('have.attr', 'type')
|
|
|
|
.should('equal', 'email')
|
2022-01-08 08:20:54 +01:00
|
|
|
getIframeBody().findByRole('button', { name: 'Send' })
|
2022-01-09 07:36:29 +01:00
|
|
|
getIframeBody().findByPlaceholderText('Type your email...').should('exist')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Send' }).should('be.disabled')
|
2022-01-08 08:20:54 +01:00
|
|
|
cy.findByTestId('step-step1').click({ force: true })
|
|
|
|
cy.findByRole('textbox', { name: 'Placeholder:' })
|
|
|
|
.clear()
|
|
|
|
.type('Your email...')
|
|
|
|
cy.findByRole('textbox', { name: 'Button label:' }).clear().type('Go')
|
|
|
|
cy.findByTestId('step-step1').should('contain.text', 'Your email...')
|
|
|
|
cy.findByRole('button', { name: 'Restart' }).click()
|
|
|
|
getIframeBody().findByPlaceholderText('Your email...').should('exist')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Go' })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-01-09 07:36:29 +01:00
|
|
|
describe('URL input', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.task('seed')
|
|
|
|
createTypebotWithStep({ type: InputStepType.URL })
|
|
|
|
cy.signOut()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('options should work', () => {
|
|
|
|
cy.signIn('test2@gmail.com')
|
|
|
|
cy.visit('/typebots/typebot3/edit')
|
|
|
|
cy.findByRole('button', { name: 'Preview' }).click()
|
|
|
|
getIframeBody()
|
|
|
|
.findByPlaceholderText('Type your URL...')
|
|
|
|
.should('have.attr', 'type')
|
|
|
|
.should('eq', 'url')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Send' }).should('be.disabled')
|
|
|
|
cy.findByTestId('step-step1').click({ force: true })
|
|
|
|
cy.findByRole('textbox', { name: 'Placeholder:' })
|
|
|
|
.clear()
|
|
|
|
.type('Your URL...')
|
|
|
|
cy.findByRole('textbox', { name: 'Button label:' }).clear().type('Go')
|
|
|
|
cy.findByTestId('step-step1').should('contain.text', 'Your URL...')
|
|
|
|
cy.findByRole('button', { name: 'Restart' }).click()
|
|
|
|
getIframeBody().findByPlaceholderText('Your URL...').should('exist')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Go' })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-01-10 08:05:03 +01:00
|
|
|
describe('Date input', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.task('seed')
|
|
|
|
createTypebotWithStep({ type: InputStepType.DATE })
|
|
|
|
cy.signOut()
|
|
|
|
})
|
|
|
|
|
2022-01-10 10:43:27 +01:00
|
|
|
it('options should work', () => {
|
2022-01-10 08:05:03 +01:00
|
|
|
cy.signIn('test2@gmail.com')
|
|
|
|
cy.visit('/typebots/typebot3/edit')
|
|
|
|
cy.findByRole('button', { name: 'Preview' }).click()
|
|
|
|
getIframeBody()
|
|
|
|
.findByTestId('from-date')
|
|
|
|
.should('have.attr', 'type')
|
|
|
|
.should('eq', 'date')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Send' }).should('be.disabled')
|
|
|
|
cy.findByTestId('step-step1').click({ force: true })
|
|
|
|
cy.findByRole('checkbox', { name: 'Is range?' }).check({ force: true })
|
|
|
|
cy.findByRole('textbox', { name: 'From label:' }).clear().type('Previous:')
|
|
|
|
cy.findByRole('textbox', { name: 'To label:' }).clear().type('After:')
|
|
|
|
cy.findByRole('checkbox', { name: 'With time?' }).check({ force: true })
|
|
|
|
cy.findByRole('textbox', { name: 'Button label:' }).clear().type('Go')
|
|
|
|
cy.findByRole('button', { name: 'Restart' }).click()
|
|
|
|
getIframeBody()
|
|
|
|
.findByTestId('from-date')
|
|
|
|
.should('have.attr', 'type')
|
|
|
|
.should('eq', 'datetime-local')
|
|
|
|
getIframeBody()
|
|
|
|
.findByTestId('to-date')
|
|
|
|
.should('have.attr', 'type')
|
|
|
|
.should('eq', 'datetime-local')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Go' })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-01-10 10:43:27 +01:00
|
|
|
describe('Phone number input', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.task('seed')
|
|
|
|
cy.log(JSON.stringify({ type: InputStepType.PHONE }))
|
|
|
|
createTypebotWithStep({ type: InputStepType.PHONE })
|
|
|
|
cy.signOut()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('options should work', () => {
|
|
|
|
cy.signIn('test2@gmail.com')
|
|
|
|
cy.visit('/typebots/typebot3/edit')
|
|
|
|
cy.findByRole('button', { name: 'Preview' }).click()
|
|
|
|
getIframeBody()
|
|
|
|
.findByPlaceholderText('Your phone number...')
|
|
|
|
.should('have.attr', 'type')
|
|
|
|
.should('eq', 'tel')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Send' }).should('be.disabled')
|
|
|
|
cy.findByTestId('step-step1').click({ force: true })
|
|
|
|
cy.findByRole('textbox', { name: 'Placeholder:' })
|
|
|
|
.clear()
|
|
|
|
.type('+33 XX XX XX XX')
|
|
|
|
cy.findByRole('textbox', { name: 'Button label:' }).clear().type('Go')
|
|
|
|
cy.findByRole('button', { name: 'Restart' }).click()
|
|
|
|
getIframeBody()
|
|
|
|
.findByPlaceholderText('+33 XX XX XX XX')
|
|
|
|
.type('+33 6 73 18 45 36')
|
|
|
|
getIframeBody()
|
|
|
|
.findByRole('img')
|
|
|
|
.should('have.attr', 'alt')
|
|
|
|
.should('eq', 'France')
|
|
|
|
getIframeBody().findByRole('button', { name: 'Go' }).click()
|
|
|
|
getIframeBody().findByText('+33673184536').should('exist')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-01-08 07:40:55 +01:00
|
|
|
const createTypebotWithStep = (step: Omit<InputStep, 'id' | 'blockId'>) => {
|
|
|
|
cy.task(
|
|
|
|
'createTypebot',
|
|
|
|
parseTestTypebot({
|
|
|
|
id: 'typebot3',
|
|
|
|
name: 'Typebot #3',
|
|
|
|
ownerId: 'test2',
|
|
|
|
steps: {
|
|
|
|
byId: {
|
|
|
|
step1: { ...step, id: 'step1', blockId: 'block1' },
|
|
|
|
},
|
|
|
|
allIds: ['step1'],
|
|
|
|
},
|
|
|
|
blocks: {
|
|
|
|
byId: {
|
|
|
|
block1: {
|
|
|
|
id: 'block1',
|
|
|
|
graphCoordinates: { x: 400, y: 200 },
|
|
|
|
title: 'Block #1',
|
|
|
|
stepIds: ['step1'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
allIds: ['block1'],
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-06 16:54:23 +01:00
|
|
|
const getIframeBody = () => {
|
|
|
|
return cy
|
|
|
|
.get('#typebot-iframe')
|
|
|
|
.its('0.contentDocument.body')
|
|
|
|
.should('not.be.empty')
|
|
|
|
.then(cy.wrap)
|
|
|
|
}
|