|
| 1 | +/// <reference types="cypress" /> |
| 2 | + |
| 3 | +import { FC } from 'react' |
| 4 | +import { useForm } from 'react-hook-form' |
| 5 | + |
| 6 | +import { Bridge } from '@/api/__generated__' |
| 7 | +import { mockBridge } from '@/api/hooks/useGetBridges/__handlers__' |
| 8 | +import OptionsPanel from '@/modules/Bridges/components/panels/OptionsPanel.tsx' |
| 9 | +import { Button } from '@chakra-ui/react' |
| 10 | + |
| 11 | +interface TestingComponentProps { |
| 12 | + onSubmit: (data: Bridge) => void |
| 13 | + defaultValues: Bridge |
| 14 | +} |
| 15 | + |
| 16 | +const TestingComponent: FC<TestingComponentProps> = ({ onSubmit, defaultValues }) => { |
| 17 | + const form = useForm<Bridge>({ |
| 18 | + mode: 'all', |
| 19 | + criteriaMode: 'all', |
| 20 | + defaultValues: defaultValues, |
| 21 | + }) |
| 22 | + |
| 23 | + return ( |
| 24 | + <div> |
| 25 | + <form id="bridge-form" onSubmit={form.handleSubmit(onSubmit)}> |
| 26 | + <OptionsPanel form={form} /> |
| 27 | + </form> |
| 28 | + <Button variant="primary" type="submit" form="bridge-form" data-testid="form-submit" mt={8}> |
| 29 | + Submit |
| 30 | + </Button> |
| 31 | + </div> |
| 32 | + ) |
| 33 | +} |
| 34 | + |
| 35 | +describe('OptionsPanel', () => { |
| 36 | + beforeEach(() => { |
| 37 | + cy.viewport(800, 800) |
| 38 | + }) |
| 39 | + |
| 40 | + it('should be accessible', () => { |
| 41 | + cy.injectAxe() |
| 42 | + cy.mountWithProviders(<TestingComponent onSubmit={cy.stub().as('submit')} defaultValues={mockBridge} />) |
| 43 | + |
| 44 | + cy.get('#cleanStart').should('be.checked') |
| 45 | + cy.get('#keepAlive').should('have.value', 0) |
| 46 | + cy.get('#sessionExpiry').should('have.value', 0) |
| 47 | + cy.get('#loopPreventionEnabled').should('not.be.checked') |
| 48 | + cy.get('#loopPreventionHopCount').should('have.value', '') |
| 49 | + cy.get('#clientId').should('have.value', 'my-client-id') |
| 50 | + |
| 51 | + cy.get('#clientId').type('-test123') |
| 52 | + |
| 53 | + cy.getByTestId('form-submit').click() |
| 54 | + cy.get('@submit').should('have.been.calledWithMatch', { clientId: 'my-client-id-test123' }) |
| 55 | + |
| 56 | + cy.checkAccessibility() |
| 57 | + cy.percySnapshot('Component: OptionsPanel') |
| 58 | + }) |
| 59 | +}) |
0 commit comments