From e6fc681383233ca23b5804257307389f2208c145 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Mon, 7 Nov 2022 11:51:23 +0100 Subject: [PATCH] test(react): clean up persona-coin test and use isConformant without side-effects --- ...-da22778f-cbbf-4200-b03c-752627517a9c.json | 7 + .../src/components/Persona/Persona.test.tsx | 20 +- .../Persona/PersonaCoin/PersonaCoin.test.tsx | 2 +- .../__snapshots__/PersonaCoin.test.tsx.snap | 1832 ----------------- .../src/components/Persona/test-utils.tsx | 19 + 5 files changed, 29 insertions(+), 1851 deletions(-) create mode 100644 change/@fluentui-react-da22778f-cbbf-4200-b03c-752627517a9c.json create mode 100644 packages/react/src/components/Persona/test-utils.tsx diff --git a/change/@fluentui-react-da22778f-cbbf-4200-b03c-752627517a9c.json b/change/@fluentui-react-da22778f-cbbf-4200-b03c-752627517a9c.json new file mode 100644 index 0000000000000..6c5b52d657952 --- /dev/null +++ b/change/@fluentui-react-da22778f-cbbf-4200-b03c-752627517a9c.json @@ -0,0 +1,7 @@ +{ + "type": "none", + "comment": "test(react): clean up persona-coin test and use isConformant without side-effects", + "packageName": "@fluentui/react", + "email": "martinhochel@microsoft.com", + "dependentChangeType": "none" +} diff --git a/packages/react/src/components/Persona/Persona.test.tsx b/packages/react/src/components/Persona/Persona.test.tsx index 425b1fd0f4897..b4c9656fdfcaa 100644 --- a/packages/react/src/components/Persona/Persona.test.tsx +++ b/packages/react/src/components/Persona/Persona.test.tsx @@ -8,8 +8,8 @@ import { mount, ReactWrapper } from 'enzyme'; import { getIcon } from '../../Styling'; import { PersonaPresence, PersonaSize } from './index'; import { isConformant } from '../../common/isConformant'; -import type { IRenderFunction } from '../../Utilities'; -import type { IPersonaSharedProps, IPersonaProps, IPersonaCoinProps } from './index'; +import type { IPersonaSharedProps, IPersonaCoinProps } from './index'; +import { wrapPersona } from './test-utils'; const testImage1x1 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQImWP4DwQACfsD/eNV8pwAAAAASUVORK5CYII='; @@ -21,22 +21,6 @@ const STYLES = { red: '.ms-Persona-initials--red', }; -/** - * function to override the default onRender callbacks - */ -export const wrapPersona = ( - example: IPersonaSharedProps, - shouldWrapPersonaCoin: boolean = false, -): ((coinProps: IPersonaProps, defaultRenderer: IRenderFunction) => JSX.Element | null) => { - return (coinProps, defaultCoinRenderer): JSX.Element | null => { - return shouldWrapPersonaCoin ? ( - {defaultCoinRenderer(coinProps)} - ) : ( - defaultCoinRenderer(coinProps) - ); - }; -}; - const customOnRenderPersonaFunction = (props: IPersonaCoinProps): JSX.Element | null => { return ; }; diff --git a/packages/react/src/components/Persona/PersonaCoin/PersonaCoin.test.tsx b/packages/react/src/components/Persona/PersonaCoin/PersonaCoin.test.tsx index 91db75a87a013..03db02d65eca2 100644 --- a/packages/react/src/components/Persona/PersonaCoin/PersonaCoin.test.tsx +++ b/packages/react/src/components/Persona/PersonaCoin/PersonaCoin.test.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { create } from '@fluentui/utilities/lib/test'; import { setRTL } from '../../../Utilities'; import { PersonaCoin } from './PersonaCoin'; -import { wrapPersona } from '../Persona.test'; +import { wrapPersona } from '../test-utils'; const testImage1x1 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQImWP4DwQACfsD/eNV8pwAAAAASUVORK5CYII='; diff --git a/packages/react/src/components/Persona/PersonaCoin/__snapshots__/PersonaCoin.test.tsx.snap b/packages/react/src/components/Persona/PersonaCoin/__snapshots__/PersonaCoin.test.tsx.snap index 587956ce7219a..346afa0cbf416 100644 --- a/packages/react/src/components/Persona/PersonaCoin/__snapshots__/PersonaCoin.test.tsx.snap +++ b/packages/react/src/components/Persona/PersonaCoin/__snapshots__/PersonaCoin.test.tsx.snap @@ -1,1837 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Persona renders Persona children correctly 1`] = ` -
-
-
- -
-
-
-
-
- Kat Larrson - -
-
- - Persona Children - -
-
-`; - -exports[`Persona renders Persona correctly with UnknownPersona coin 1`] = ` -
-
-
- -
-
-
-
-
- Kat Larrson - -
-
-
-
-`; - -exports[`Persona renders Persona correctly with image 1`] = ` -
-
-
-
- -
-
-
-
-
-
- Kat Larrson - -
-
-
-
-`; - -exports[`Persona renders Persona correctly with initials 1`] = ` -
-
-
- -
-
-
-
-
- Kat Larrson - -
-
-
-
-`; - -exports[`Persona renders Persona correctly with no props 1`] = ` -
-
-
- -
-
-
-
-`; - -exports[`Persona renders Persona which calls onRenderCoin callback without imageUrl 1`] = ` -
-
-
- - -
- -
-
-
-
-
-
- Swapnil Vaibhav - -
-
-
-
- Software Engineer - -
-
-
-
- In a meeting - -
-
-
-
- Available at 4:00pm - -
-
-
-
-`; - -exports[`Persona renders Persona which calls onRenderPersonaCoin callback with custom render 1`] = ` -
- -  - -
-
-
- Swapnil Vaibhav - -
-
-
-
- Software Engineer - -
-
-
-
- In a meeting - -
-
-
-
- Available at 4:00pm - -
-
-
-
-`; - -exports[`Persona renders correctly with onRender callback 1`] = ` -
-
-
-
- -
-
- -
-
-
-
-
-
- Swapnil Vaibhav - -
-
-
-
- Software Engineer - -
-
-
-
- In a meeting - -
-
-
-
- Available at 4:00pm - -
-
-
-
-`; - exports[`PersonaCoin does not render the initials when showInitialsUntilImageLoads is false 1`] = `
) => JSX.Element | null) => { + return (coinProps, defaultCoinRenderer): JSX.Element | null => { + return shouldWrapPersonaCoin ? ( + {defaultCoinRenderer(coinProps)} + ) : ( + defaultCoinRenderer(coinProps) + ); + }; +};