Skip to content

Commit 9cc7cbb

Browse files
authored
fix(19238): Fix the default cleanStart checkbox (#359)
* fix(19238): remove the faulty defaultChecked on checkboxes * test(19238): fix ida * test(19238): add tests
1 parent 6df91f1 commit 9cc7cbb

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
})

hivemq-edge/src/frontend/src/modules/Bridges/components/panels/OptionsPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const OptionsPanel: FC<BridgePanelType> = ({ form }) => {
2828
return (
2929
<FormControl variant="hivemq" flexGrow={1} display="flex" flexDirection="column" gap={4} as="fieldset">
3030
<FormControl isInvalid={!!errors.cleanStart}>
31-
<Checkbox defaultChecked {...register('cleanStart')}>
31+
<Checkbox id="cleanStart" {...register('cleanStart')}>
3232
{t('bridge.options.cleanStart.label')}
3333
</Checkbox>
3434
<FormHelperText> {t('bridge.options.cleanStart.helper')}</FormHelperText>
@@ -70,7 +70,7 @@ const OptionsPanel: FC<BridgePanelType> = ({ form }) => {
7070

7171
<FormControl isInvalid={!!errors.loopPreventionEnabled} mt={3}>
7272
<Checkbox
73-
defaultChecked
73+
id="loopPreventionEnabled"
7474
{...register('loopPreventionEnabled', {
7575
...getRulesForProperty($Bridge.properties.loopPreventionEnabled),
7676
})}

0 commit comments

Comments
 (0)