-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Transform Action jest tests into playwright (#592)
- Loading branch information
1 parent
24b48f6
commit bb3ac8e
Showing
141 changed files
with
597 additions
and
207 deletions.
There are no files selected for viewing
151 changes: 151 additions & 0 deletions
151
src/components/CheckboxField/__tests__/CheckboxField.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import React from 'react'; | ||
import { | ||
expect, | ||
test, | ||
} from '@playwright/experimental-ct-react'; | ||
import { | ||
mixPropTests, | ||
propTests, | ||
} from '../../../../tests/playwright'; | ||
import { | ||
CheckboxFieldForTest, | ||
CheckboxFieldForRefTest, | ||
CheckboxWForFormLayoutTests, | ||
} from './CheckboxField.story'; | ||
import { checkedPropTest } from './_propTests/checkedPropTest'; | ||
|
||
test.describe('CheckboxField', () => { | ||
test.describe('base', () => { | ||
test.describe('visual', () => { | ||
[ | ||
...propTests.labelPropTest, | ||
...propTests.renderAsRequiredPropTest, | ||
...propTests.isLabelVisiblePropTest, | ||
...propTests.labelPositionPropTest(), | ||
...mixPropTests([ | ||
checkedPropTest, | ||
propTests.disabledPropTest, | ||
propTests.validationStatePropTest(true), | ||
]), | ||
...mixPropTests([ | ||
checkedPropTest, | ||
propTests.requiredPropTest, | ||
]), | ||
...mixPropTests([ | ||
checkedPropTest, | ||
propTests.validationTextPropTest(true), | ||
propTests.validationStatePropTest(true), | ||
]), | ||
...mixPropTests([ | ||
checkedPropTest, | ||
propTests.validationTextPropTest(true), | ||
propTests.helpTextPropTest(true), | ||
]), | ||
].forEach(({ | ||
name, | ||
onBeforeTest, | ||
props, | ||
}) => { | ||
test(name, async ({ | ||
mount, | ||
page, | ||
}) => { | ||
if (onBeforeTest) { | ||
await onBeforeTest(page); | ||
} | ||
|
||
const component = await mount( | ||
<CheckboxFieldForTest | ||
{...props} | ||
/>, | ||
); | ||
|
||
const screenshot = await component.screenshot(); | ||
expect(screenshot).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
|
||
test.describe('non-visual', () => { | ||
test('id', async ({ mount }) => { | ||
const idValue = 'checkbox-id'; | ||
const label = 'checkbox-label'; | ||
const helpText = 'checkbox-helpText'; | ||
const validationText = 'checkbox-validationText'; | ||
|
||
const component = await mount( | ||
<CheckboxFieldForTest | ||
helpText={helpText} | ||
id={idValue} | ||
label={label} | ||
validationText={validationText} | ||
/>, | ||
); | ||
|
||
await expect(component.getByRole('checkbox')).toHaveAttribute('id', idValue); | ||
await expect(component).toHaveAttribute('id', `${idValue}__label`); | ||
await expect(component.getByText(label)).toHaveAttribute('id', `${idValue}__labelText`); | ||
await expect(component.getByText(helpText)).toHaveAttribute('id', `${idValue}__helpText`); | ||
await expect(component.getByText(validationText)).toHaveAttribute('id', `${idValue}__validationText`); | ||
}); | ||
|
||
test('ref', async ({ mount }) => { | ||
const component = await mount( | ||
<CheckboxFieldForRefTest | ||
testRefAttrName="test-ref" | ||
testRefAttrValue="test-ref-value" | ||
/>, | ||
); | ||
|
||
await expect(component.getByRole('checkbox')).toHaveAttribute('test-ref', 'test-ref-value'); | ||
}); | ||
}); | ||
|
||
test.describe('functionality', () => { | ||
test('calls synthetic event onChange()', async ({ mount }) => { | ||
let changeCalled = false; | ||
|
||
const component = await mount( | ||
<CheckboxFieldForTest | ||
onChange={() => { | ||
changeCalled = true; | ||
}} | ||
/>, | ||
); | ||
|
||
await component.click({ force: true }); | ||
expect(changeCalled).toBeTruthy(); | ||
}); | ||
}); | ||
}); | ||
|
||
test.describe('formLayout', () => { | ||
test.describe('visual', () => { | ||
[ | ||
...propTests.layoutPropTest(true), | ||
].forEach(({ | ||
name, | ||
onBeforeTest, | ||
props, | ||
}) => { | ||
test(name, async ({ | ||
mount, | ||
page, | ||
}) => { | ||
if (onBeforeTest) { | ||
await onBeforeTest(page); | ||
} | ||
|
||
const component = await mount( | ||
<CheckboxWForFormLayoutTests | ||
{...props} | ||
/>, | ||
); | ||
|
||
const screenshot = await component.screenshot(); | ||
expect(screenshot).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Binary file added
BIN
+1.35 KB
...isual-checked-false-disabled-false-validationState-invalid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.18 KB
...ual-checked-false-disabled-false-validationState-undefined-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.39 KB
...-visual-checked-false-disabled-false-validationState-valid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.31 KB
...isual-checked-false-disabled-false-validationState-warning-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.3 KB
...visual-checked-false-disabled-true-validationState-invalid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.21 KB
...sual-checked-false-disabled-true-validationState-undefined-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.34 KB
...e-visual-checked-false-disabled-true-validationState-valid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.3 KB
...visual-checked-false-disabled-true-validationState-warning-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.18 KB
...ots/CheckboxField-base-visual-checked-false-required-false-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.34 KB
...hots/CheckboxField-base-visual-checked-false-required-true-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.7 KB
...ase-visual-checked-false-validationText-long-helpText-long-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.41 KB
...e-visual-checked-false-validationText-long-helpText-normal-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.59 KB
...isual-checked-false-validationText-long-helpText-undefined-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.73 KB
...-checked-false-validationText-long-validationState-invalid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.59 KB
...hecked-false-validationText-long-validationState-undefined-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.91 KB
...al-checked-false-validationText-long-validationState-valid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.88 KB
...-checked-false-validationText-long-validationState-warning-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.54 KB
...e-visual-checked-false-validationText-normal-helpText-long-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.37 KB
...visual-checked-false-validationText-normal-helpText-normal-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.93 KB
...ual-checked-false-validationText-normal-helpText-undefined-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.04 KB
...hecked-false-validationText-normal-validationState-invalid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.93 KB
...cked-false-validationText-normal-validationState-undefined-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.14 KB
...-checked-false-validationText-normal-validationState-valid-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.02 KB
...hecked-false-validationText-normal-validationState-warning-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.54 KB
...isual-checked-false-validationText-undefined-helpText-long-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.78 KB
...ual-checked-false-validationText-undefined-helpText-normal-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.18 KB
...-checked-false-validationText-undefined-helpText-undefined-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.35 KB
...ked-false-validationText-undefined-validationState-invalid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.18 KB
...d-false-validationText-undefined-validationState-undefined-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.39 KB
...ecked-false-validationText-undefined-validationState-valid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.31 KB
...ked-false-validationText-undefined-validationState-warning-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.49 KB
...visual-checked-true-disabled-false-validationState-invalid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.4 KB
...sual-checked-true-disabled-false-validationState-undefined-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.54 KB
...e-visual-checked-true-disabled-false-validationState-valid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.47 KB
...visual-checked-true-disabled-false-validationState-warning-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.44 KB
...-visual-checked-true-disabled-true-validationState-invalid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.38 KB
...isual-checked-true-disabled-true-validationState-undefined-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.48 KB
...se-visual-checked-true-disabled-true-validationState-valid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.43 KB
...-visual-checked-true-disabled-true-validationState-warning-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.4 KB
...hots/CheckboxField-base-visual-checked-true-required-false-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.52 KB
...shots/CheckboxField-base-visual-checked-true-required-true-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+8.93 KB
...base-visual-checked-true-validationText-long-helpText-long-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+6.63 KB
...se-visual-checked-true-validationText-long-helpText-normal-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+5.81 KB
...visual-checked-true-validationText-long-helpText-undefined-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+5.88 KB
...l-checked-true-validationText-long-validationState-invalid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+5.81 KB
...checked-true-validationText-long-validationState-undefined-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+6.08 KB
...ual-checked-true-validationText-long-validationState-valid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+6.05 KB
...l-checked-true-validationText-long-validationState-warning-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+6.76 KB
...se-visual-checked-true-validationText-normal-helpText-long-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+3.6 KB
...-visual-checked-true-validationText-normal-helpText-normal-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+3.14 KB
...sual-checked-true-validationText-normal-helpText-undefined-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+3.19 KB
...checked-true-validationText-normal-validationState-invalid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+3.14 KB
...ecked-true-validationText-normal-validationState-undefined-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+3.31 KB
...l-checked-true-validationText-normal-validationState-valid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+3.18 KB
...checked-true-validationText-normal-validationState-warning-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+5.76 KB
...visual-checked-true-validationText-undefined-helpText-long-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+2.99 KB
...sual-checked-true-validationText-undefined-helpText-normal-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.4 KB
...l-checked-true-validationText-undefined-helpText-undefined-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.49 KB
...cked-true-validationText-undefined-validationState-invalid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.4 KB
...ed-true-validationText-undefined-validationState-undefined-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.54 KB
...hecked-true-validationText-undefined-validationState-valid-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.47 KB
...cked-true-validationText-undefined-validationState-warning-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+248 Bytes
...x-snapshots/CheckboxField-base-visual-isLabelVisible-false-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.18 KB
...sx-snapshots/CheckboxField-base-visual-isLabelVisible-true-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+3.58 KB
...oxField.spec.tsx-snapshots/CheckboxField-base-visual-label-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.18 KB
...sx-snapshots/CheckboxField-base-visual-labelPosition-after-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.18 KB
...x-snapshots/CheckboxField-base-visual-labelPosition-before-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.18 KB
...snapshots/CheckboxField-base-visual-renderAsRequired-false-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+1.34 KB
...-snapshots/CheckboxField-base-visual-renderAsRequired-true-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+3.47 KB
...napshots/CheckboxField-formLayout-visual-layout-horizontal-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+2 KB
...snapshots/CheckboxField-formLayout-visual-layout-undefined-1-chromium-linux.png
Oops, something went wrong.
Binary file added
BIN
+2 KB
...-snapshots/CheckboxField-formLayout-visual-layout-vertical-1-chromium-linux.png
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
src/components/CheckboxField/__tests__/CheckboxField.story.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { | ||
useEffect, | ||
useMemo, | ||
useRef, | ||
} from 'react'; | ||
import type { LabelHTMLAttributes } from 'react'; | ||
import { FormLayoutContext } from '../../FormLayout'; | ||
import { CheckboxField } from '..'; | ||
|
||
// Types for story component will be improved when we have full TypeScript support | ||
type CheckboxFieldForTestProps = LabelHTMLAttributes<HTMLLabelElement>; | ||
type CheckboxFieldForRefTestProps = CheckboxFieldForTestProps & { | ||
testRefAttrName: string; | ||
testRefAttrValue: string; | ||
}; | ||
type CheckboxWForFormLayoutTestsProps = CheckboxFieldForTestProps & { | ||
layout: 'vertical' | 'horizontal' | undefined | ||
}; | ||
|
||
const defaultLabel = 'test-label'; | ||
|
||
export const CheckboxFieldForTest = ({ | ||
...props | ||
} : CheckboxFieldForTestProps) => ( | ||
<CheckboxField | ||
label={defaultLabel} | ||
{...props} | ||
/> | ||
); | ||
|
||
export const CheckboxFieldForRefTest = ({ | ||
testRefAttrName, | ||
testRefAttrValue, | ||
...props | ||
} : CheckboxFieldForRefTestProps) => { | ||
const ref = useRef<HTMLLabelElement>(undefined); | ||
|
||
useEffect(() => { | ||
ref.current?.setAttribute(testRefAttrName, testRefAttrValue); | ||
}, [testRefAttrName, testRefAttrValue]); | ||
|
||
return ( | ||
<CheckboxField | ||
label={defaultLabel} | ||
{...props} | ||
ref={ref} | ||
/> | ||
); | ||
}; | ||
|
||
export const CheckboxWForFormLayoutTests = ({ | ||
layout = undefined, | ||
...props | ||
} : CheckboxWForFormLayoutTestsProps) => { | ||
const values = useMemo(() => ({ layout }), [layout]); | ||
|
||
return ( | ||
<FormLayoutContext.Provider | ||
value={values} | ||
> | ||
<CheckboxField | ||
label={defaultLabel} | ||
{...props} | ||
/> | ||
<CheckboxField | ||
label="another-test-label" | ||
{...props} | ||
/> | ||
</FormLayoutContext.Provider> | ||
); | ||
}; |
77 changes: 0 additions & 77 deletions
77
src/components/CheckboxField/__tests__/CheckboxField.test.jsx
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
src/components/CheckboxField/__tests__/_propTests/checkedPropTest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { PropTests } from '../../../../../tests/playwright/types'; | ||
|
||
export const checkedPropTest: PropTests = [ | ||
{ | ||
name: 'checked=false', | ||
props: { checked: false }, | ||
}, | ||
{ | ||
name: 'checked=true', | ||
props: { checked: true }, | ||
}, | ||
]; |
Oops, something went wrong.