Skip to content

Commit

Permalink
test: add visual tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sashuk committed Aug 3, 2023
1 parent 448cdec commit b0aae44
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cypress/component/DatePicker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
Button,
} from '@toptal/picasso'
import React, { useState } from 'react'
import { HAPPO_TARGETS } from '@toptal/picasso/test-utils'
import { PicassoBreakpoints } from '@toptal/picasso-provider'

const TestDatePicker = (props: Partial<DatePickerProps>) => {
const [value, setValue] = useState<DatePickerProps['value']>(
Expand Down Expand Up @@ -168,4 +170,40 @@ describe('DatePicker', () => {

cy.getByTestId('date-picker-input').should('have.value', '')
})

describe('when number of displayed months is more than one', () => {
Cypress._.each(HAPPO_TARGETS, happoTarget => {
const { width } = happoTarget

describe(`when screen has ${width}px width`, () => {
const isNarrowScreen = width < PicassoBreakpoints.breakpoints.values.md

it(
isNarrowScreen ? 'displays one month' : 'displays two months',
() => {
cy.viewport(width, 1000)

cy.mount(
<TestDatePicker
numberOfMonths={2}
testIds={{
input: 'date-picker-input',
calendar: 'date-picker-calendar',
}}
/>
)

cy.getByTestId('date-picker-input').focus()
cy.get('.rdp-month').should('have.length', isNarrowScreen ? 1 : 2)

cy.get('body').happoScreenshot({
component,
variant: `date-picker/${width}-default`,
targets: [happoTarget],
})
}
)
})
})
})
})
23 changes: 23 additions & 0 deletions cypress/component/Modal.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect } from 'react'
import type { ModalProps } from '@toptal/picasso'
import { Modal, Form, Input, Select, Checkbox, Button } from '@toptal/picasso'
import { HAPPO_TARGETS } from '@toptal/picasso/test-utils'

const TestModalForm = (props: Partial<Omit<ModalProps, 'open'>>) => {
const [isOpen, setOpen] = React.useState(false)
Expand Down Expand Up @@ -211,4 +212,26 @@ describe('Modal', () => {
variant: 'overflown',
})
})

Cypress._.each(HAPPO_TARGETS, happoTarget => {
const { width } = happoTarget

describe(`when screen has ${width}px width`, () => {
Cypress._.each(['small', 'medium', 'large', 'full-screen'], modalSize => {
it(`renders ${modalSize} size modal`, () => {
cy.viewport(width, 1000)

cy.mount(
<TestModalOverflown size={modalSize as ModalProps['size']} />
)

cy.get('body').happoScreenshot({
component,
variant: `modal-${modalSize}-size/${width}-default`,
targets: [happoTarget],
})
})
})
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { getCheckpoints } from './get-checkpoints'

jest.mock('@toptal/picasso-provider', () => ({
PicassoBreakpoints: {
breakpoints: {
values: {
first: 0,
second: 100,
third: 200,
},
},
},
}))

describe('getCheckpoints', () => {
it('returns correct checkpoints (skips first breakpoint and generates two checkpoints for the last breakpoint)', () => {
expect(getCheckpoints()).toEqual([99, 199, 201])
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getHappoTargets } from './get-happo-targets'

describe('getHappoTargets', () => {
it('returns correct Happo responsive testing targets', () => {
expect(getHappoTargets([1000])).toEqual([
{
browser: 'chrome',
name: 'chrome-desktop-width-1000',
viewport: '1000x1024',
width: 1000,
},
])
})
})

0 comments on commit b0aae44

Please sign in to comment.