diff --git a/change/@fluentui-react-native-button-4f7a77ca-3caa-43b1-a837-9c6b29b1e4ed.json b/change/@fluentui-react-native-button-4f7a77ca-3caa-43b1-a837-9c6b29b1e4ed.json new file mode 100644 index 0000000000..b609fb86f2 --- /dev/null +++ b/change/@fluentui-react-native-button-4f7a77ca-3caa-43b1-a837-9c6b29b1e4ed.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Multi-plat jest setup", + "packageName": "@fluentui-react-native/button", + "email": "ruaraki@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/components/Button/.npmignore b/packages/components/Button/.npmignore new file mode 100644 index 0000000000..3a62fb2977 --- /dev/null +++ b/packages/components/Button/.npmignore @@ -0,0 +1,2 @@ +# Don't include test files in package +__tests__/ \ No newline at end of file diff --git a/packages/components/Button/__tests__/ButtonLegacy.test.tsx b/packages/components/Button/__tests__/ButtonLegacy.test.tsx new file mode 100644 index 0000000000..e07d8212f0 --- /dev/null +++ b/packages/components/Button/__tests__/ButtonLegacy.test.tsx @@ -0,0 +1,10 @@ +import * as React from 'react'; +import { Button } from '../src/deprecated/Button'; +import * as renderer from 'react-test-renderer'; + +export const buttonLegacyTest = () => { + it('Button default', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button disabled', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button primary', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button subtle', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button circular', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button square', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button small', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button large', () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button customized', () => { + const CustomButton = Button.customize({ backgroundColor: 'pink' }); + const tree = renderer.create(Custom Button).toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button composed', () => { + const ComposedButton = Button.compose({ + slots: { + root: Pressable, + icon: Icon, + content: Text, + }, + }); + const tree = renderer.create(Composed Button with RNText).toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button simple rendering does not invalidate styling', () => { + checkRenderConsistency(() => , 2); + }); + + it('Button re-renders correctly', () => { + checkReRender(() => , 2); + }); + + it('Button shares produced styles across multiple renders', () => { + const style = { backgroundColor: 'black' }; + checkRenderConsistency(() => , 2); + }); + + it('Button re-renders correctly with style', () => { + const style = { borderColor: 'blue' }; + checkReRender(() => , 2); + }); + }); +}; diff --git a/packages/components/Button/__tests__/CompoundButton.test.tsx b/packages/components/Button/__tests__/CompoundButton.test.tsx new file mode 100644 index 0000000000..e4e600f99d --- /dev/null +++ b/packages/components/Button/__tests__/CompoundButton.test.tsx @@ -0,0 +1,29 @@ +import * as React from 'react'; +import { CompoundButton } from '../src/CompoundButton/CompoundButton'; +import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools'; +import * as renderer from 'react-test-renderer'; + +export const compountButtonTests = () => { + it('CompoundButton default', () => { + const tree = renderer.create(Default Button).toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button simple rendering does not invalidate styling', () => { + checkRenderConsistency(() => Default button, 2); + }); + + it('Button re-renders correctly', () => { + checkReRender(() => Render twice, 2); + }); + + it('Button shares produced styles across multiple renders', () => { + const style = { backgroundColor: 'black' }; + checkRenderConsistency(() => Shared styles, 2); + }); + + it('Button re-renders correctly with style', () => { + const style = { borderColor: 'blue' }; + checkReRender(() => Shared Style Render, 2); + }); +}; diff --git a/packages/components/Button/__tests__/FAB.test.tsx b/packages/components/Button/__tests__/FAB.test.tsx new file mode 100644 index 0000000000..9e77972174 --- /dev/null +++ b/packages/components/Button/__tests__/FAB.test.tsx @@ -0,0 +1,67 @@ +import * as React from 'react'; +import { FAB } from '../src/FAB/FAB'; +import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools'; +import * as renderer from 'react-test-renderer'; + +const fontBuiltInProps = { + fontFamily: 'Arial', + codepoint: 0x2663, + fontSize: 16, +}; +const iconProps = { fontSource: { ...fontBuiltInProps }, color: '#fff' }; + +export const fabTests = () => { + beforeAll(() => { + jest.mock('react-native/Libraries/Utilities/Platform', () => ({ + OS: 'ios', + select: () => null, + })); + }); + + it('Default FAB (iOS)', () => { + const tree = renderer.create(Default FAB (iOS)).toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Custom FAB with no shadow(iOS)', () => { + const CustomFABNoShadow = FAB.customize({ shadowToken: undefined }); + const tree = renderer.create(Custom FAB with no shadow(iOS)).toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button simple rendering does not invalidate styling', () => { + checkRenderConsistency(() => Default FAB, 2); + }); + + it('FAB re-renders correctly', () => { + checkReRender(() => Render twice, 2); + }); + + it('FAB shares produced styles across multiple renders', () => { + const style = { backgroundColor: 'black' }; + checkRenderConsistency( + () => ( + + Shared styles + + ), + 2, + ); + }); + + it('FAB re-renders correctly with style', () => { + const style = { borderColor: 'blue' }; + checkReRender( + () => ( + + Shared Style Render + + ), + 2, + ); + }); + + afterAll(() => { + jest.unmock('react-native/Libraries/Utilities/Platform'); + }); +}; diff --git a/packages/components/Button/__tests__/ToggleButton.test.tsx b/packages/components/Button/__tests__/ToggleButton.test.tsx new file mode 100644 index 0000000000..8a4e86b60a --- /dev/null +++ b/packages/components/Button/__tests__/ToggleButton.test.tsx @@ -0,0 +1,29 @@ +import * as React from 'react'; +import { ToggleButton } from '../src/ToggleButton/ToggleButton'; +import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools'; +import * as renderer from 'react-test-renderer'; + +export const toggleButtonTests = () => { + it('ToggleButton default', () => { + const tree = renderer.create(Default Button).toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('Button simple rendering does not invalidate styling', () => { + checkRenderConsistency(() => Default button, 2); + }); + + it('Button re-renders correctly', () => { + checkReRender(() => Render twice, 2); + }); + + it('Button shares produced styles across multiple renders', () => { + const style = { backgroundColor: 'black' }; + checkRenderConsistency(() => Shared styles, 2); + }); + + it('Button re-renders correctly with style', () => { + const style = { borderColor: 'blue' }; + checkReRender(() => Shared Style Render, 2); + }); +}; diff --git a/packages/components/Button/__tests__/iOS/Button.test.tsx b/packages/components/Button/__tests__/iOS/Button.test.tsx new file mode 100644 index 0000000000..d6f0d472fa --- /dev/null +++ b/packages/components/Button/__tests__/iOS/Button.test.tsx @@ -0,0 +1,9 @@ +import { buttonLegacyTest } from '../ButtonLegacy.test'; +import { buttonV1Tests } from '../ButtonV1.test'; +import { fabTests } from '../FAB.test'; +import { toggleButtonTests } from '../ToggleButton.test'; + +buttonLegacyTest(); +buttonV1Tests(); +fabTests(); +toggleButtonTests(); diff --git a/packages/components/Button/src/__snapshots__/Button.test.tsx.snap b/packages/components/Button/__tests__/iOS/__snapshots__/Button.test.tsx.snap similarity index 62% rename from packages/components/Button/src/__snapshots__/Button.test.tsx.snap rename to packages/components/Button/__tests__/iOS/__snapshots__/Button.test.tsx.snap index 5befa8e29b..9f46071040 100644 --- a/packages/components/Button/src/__snapshots__/Button.test.tsx.snap +++ b/packages/components/Button/__tests__/iOS/__snapshots__/Button.test.tsx.snap @@ -581,3 +581,346 @@ exports[`Button component tests Button subtle 1`] = ` `; + +exports[`Button default 1`] = ` + + + + + Default Button + + + + +`; + +exports[`Custom FAB with no shadow(iOS) 1`] = ` + + + ♣ + + + Custom FAB with no shadow(iOS) + + +`; + +exports[`Default FAB (iOS) 1`] = ` + + + + ♣ + + + Default FAB (iOS) + + + +`; + +exports[`ToggleButton default 1`] = ` + + + Default Button + + +`; diff --git a/packages/components/Button/__tests__/iOS/jest.config.ios.js b/packages/components/Button/__tests__/iOS/jest.config.ios.js new file mode 100644 index 0000000000..350a36f763 --- /dev/null +++ b/packages/components/Button/__tests__/iOS/jest.config.ios.js @@ -0,0 +1,5 @@ +const { configureReactNativeJest } = require('@fluentui-react-native/scripts'); +module.exports = configureReactNativeJest('ios', { + roots: ['.'], + testRegex: '(.*|\\.(test|spec))\\.(ts|tsx)$', +}); diff --git a/packages/components/Button/__tests__/win32/Button.test.tsx b/packages/components/Button/__tests__/win32/Button.test.tsx new file mode 100644 index 0000000000..5b8035dabe --- /dev/null +++ b/packages/components/Button/__tests__/win32/Button.test.tsx @@ -0,0 +1,9 @@ +import { buttonLegacyTest } from '../ButtonLegacy.test'; +import { buttonV1Tests } from '../ButtonV1.test'; +import { compountButtonTests } from '../CompoundButton.test'; +import { toggleButtonTests } from '../ToggleButton.test'; + +buttonLegacyTest(); +buttonV1Tests(); +compountButtonTests(); +toggleButtonTests(); diff --git a/packages/components/Button/__tests__/win32/__snapshots__/Button.test.tsx.snap b/packages/components/Button/__tests__/win32/__snapshots__/Button.test.tsx.snap new file mode 100644 index 0000000000..3654879bf3 --- /dev/null +++ b/packages/components/Button/__tests__/win32/__snapshots__/Button.test.tsx.snap @@ -0,0 +1,1010 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Button component tests Button circular 1`] = ` + + + Circular Button + + +`; + +exports[`Button component tests Button composed 1`] = ` + + + Composed Button with RNText + + +`; + +exports[`Button component tests Button customized 1`] = ` + + + Custom Button + + +`; + +exports[`Button component tests Button default 1`] = ` + + + Default Button + + +`; + +exports[`Button component tests Button disabled 1`] = ` + + + Disabled Button + + +`; + +exports[`Button component tests Button large 1`] = ` + + + Large Button + + +`; + +exports[`Button component tests Button primary 1`] = ` + + + Primary Button + + +`; + +exports[`Button component tests Button small 1`] = ` + + + Small Button + + +`; + +exports[`Button component tests Button square 1`] = ` + + + Square Button + + +`; + +exports[`Button component tests Button subtle 1`] = ` + + + Subtle Button + + +`; + +exports[`Button default 1`] = ` + + + + + Default Button + + + + +`; + +exports[`CompoundButton default 1`] = ` + + + + Default Button + + + sublabel + + + +`; + +exports[`ToggleButton default 1`] = ` + + + Default Button + + +`; diff --git a/packages/components/Button/__tests__/win32/jest.config.win32.js b/packages/components/Button/__tests__/win32/jest.config.win32.js new file mode 100644 index 0000000000..29326de927 --- /dev/null +++ b/packages/components/Button/__tests__/win32/jest.config.win32.js @@ -0,0 +1,5 @@ +const { configureReactNativeJest } = require('@fluentui-react-native/scripts'); +module.exports = configureReactNativeJest('win32', { + roots: ['.'], + testRegex: '(.*|\\.(test|spec))\\.(ts|tsx)$', +}); diff --git a/packages/components/Button/jest.config.js b/packages/components/Button/jest.config.js deleted file mode 100644 index a8bf7c4f87..0000000000 --- a/packages/components/Button/jest.config.js +++ /dev/null @@ -1,2 +0,0 @@ -const { configureReactNativeJest } = require('@fluentui-react-native/scripts'); -module.exports = configureReactNativeJest('ios'); diff --git a/packages/components/Button/package.json b/packages/components/Button/package.json index 4a353fb19c..240b2818f2 100644 --- a/packages/components/Button/package.json +++ b/packages/components/Button/package.json @@ -15,7 +15,9 @@ "just": "fluentui-scripts", "clean": "fluentui-scripts clean", "lint": "fluentui-scripts eslint", - "test": "fluentui-scripts jest", + "test": "yarn test-ios && yarn test-win32", + "test-ios": "fluentui-scripts jest -c __tests__/iOS/jest.config.ios.js", + "test-win32": "fluentui-scripts jest -c __tests__/win32/jest.config.win32.js", "update-snapshots": "fluentui-scripts jest -u", "prettier": "fluentui-scripts prettier", "prettier-fix": "fluentui-scripts prettier --fix true" diff --git a/packages/components/Button/src/Button.test.tsx b/packages/components/Button/src/Button.test.tsx deleted file mode 100644 index c459ae6179..0000000000 --- a/packages/components/Button/src/Button.test.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import * as React from 'react'; -import { Button } from './Button'; -import * as renderer from 'react-test-renderer'; -import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools'; -import { Pressable, Text } from 'react-native'; -import { Icon } from '@fluentui-react-native/icon'; - -describe('Button component tests', () => { - it('Button default', () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); - }); - - it('Button disabled', () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); - }); - - it('Button primary', () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); - }); - - it('Button subtle', () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); - }); - - it('Button circular', () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); - }); - - it('Button square', () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); - }); - - it('Button small', () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); - }); - - it('Button large', () => { - const tree = renderer.create().toJSON(); - expect(tree).toMatchSnapshot(); - }); - - it('Button customized', () => { - const CustomButton = Button.customize({ backgroundColor: 'pink' }); - const tree = renderer.create(Custom Button).toJSON(); - expect(tree).toMatchSnapshot(); - }); - - it('Button composed', () => { - const ComposedButton = Button.compose({ - slots: { - root: Pressable, - icon: Icon, - content: Text, - }, - }); - const tree = renderer.create(Composed Button with RNText).toJSON(); - expect(tree).toMatchSnapshot(); - }); - - it('Button simple rendering does not invalidate styling', () => { - checkRenderConsistency(() => , 2); - }); - - it('Button re-renders correctly', () => { - checkReRender(() => , 2); - }); - - it('Button shares produced styles across multiple renders', () => { - const style = { backgroundColor: 'black' }; - checkRenderConsistency(() => , 2); - }); - - it('Button re-renders correctly with style', () => { - const style = { borderColor: 'blue' }; - checkReRender(() => , 2); - }); -}); diff --git a/packages/components/Button/src/CompoundButton/CompoundButton.test.tsx b/packages/components/Button/src/CompoundButton/CompoundButton.test.tsx deleted file mode 100644 index 533b667731..0000000000 --- a/packages/components/Button/src/CompoundButton/CompoundButton.test.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import * as React from 'react'; -import { CompoundButton } from './CompoundButton'; -import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools'; -import * as renderer from 'react-test-renderer'; - -it('CompoundButton default', () => { - const tree = renderer.create(Default Button).toJSON(); - expect(tree).toMatchSnapshot(); -}); - -it('Button simple rendering does not invalidate styling', () => { - checkRenderConsistency(() => Default button, 2); -}); - -it('Button re-renders correctly', () => { - checkReRender(() => Render twice, 2); -}); - -it('Button shares produced styles across multiple renders', () => { - const style = { backgroundColor: 'black' }; - checkRenderConsistency(() => Shared styles, 2); -}); - -it('Button re-renders correctly with style', () => { - const style = { borderColor: 'blue' }; - checkReRender(() => Shared Style Render, 2); -}); diff --git a/packages/components/Button/src/CompoundButton/__snapshots__/CompoundButton.test.tsx.snap b/packages/components/Button/src/CompoundButton/__snapshots__/CompoundButton.test.tsx.snap deleted file mode 100644 index 77e82b1a02..0000000000 --- a/packages/components/Button/src/CompoundButton/__snapshots__/CompoundButton.test.tsx.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`CompoundButton default 1`] = `null`; diff --git a/packages/components/Button/src/FAB/FAB.test.tsx b/packages/components/Button/src/FAB/FAB.test.tsx deleted file mode 100644 index f4b9bb43b1..0000000000 --- a/packages/components/Button/src/FAB/FAB.test.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import * as React from 'react'; -import { FAB } from './FAB'; -import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools'; -import * as renderer from 'react-test-renderer'; - -const fontBuiltInProps = { - fontFamily: 'Arial', - codepoint: 0x2663, - fontSize: 16, -}; -const iconProps = { fontSource: { ...fontBuiltInProps }, color: '#fff' }; - -beforeAll(() => { - jest.mock('react-native/Libraries/Utilities/Platform', () => ({ - OS: 'ios', - select: () => null, - })); -}); - -it('Default FAB (iOS)', () => { - const tree = renderer.create(Default FAB (iOS)).toJSON(); - expect(tree).toMatchSnapshot(); -}); - -it('Custom FAB with no shadow(iOS)', () => { - const CustomFABNoShadow = FAB.customize({ shadowToken: undefined }); - const tree = renderer.create(Custom FAB with no shadow(iOS)).toJSON(); - expect(tree).toMatchSnapshot(); -}); - -it('Button simple rendering does not invalidate styling', () => { - checkRenderConsistency(() => Default FAB, 2); -}); - -it('FAB re-renders correctly', () => { - checkReRender(() => Render twice, 2); -}); - -it('FAB shares produced styles across multiple renders', () => { - const style = { backgroundColor: 'black' }; - checkRenderConsistency( - () => ( - - Shared styles - - ), - 2, - ); -}); - -it('FAB re-renders correctly with style', () => { - const style = { borderColor: 'blue' }; - checkReRender( - () => ( - - Shared Style Render - - ), - 2, - ); -}); - -afterAll(() => { - jest.unmock('react-native/Libraries/Utilities/Platform'); -}); diff --git a/packages/components/Button/src/FAB/__snapshots__/FAB.test.tsx.snap b/packages/components/Button/src/FAB/__snapshots__/FAB.test.tsx.snap deleted file mode 100644 index f5820b1a58..0000000000 --- a/packages/components/Button/src/FAB/__snapshots__/FAB.test.tsx.snap +++ /dev/null @@ -1,204 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Custom FAB with no shadow(iOS) 1`] = ` - - - ♣ - - - Custom FAB with no shadow(iOS) - - -`; - -exports[`Default FAB (iOS) 1`] = ` - - - - ♣ - - - Default FAB (iOS) - - - -`; diff --git a/packages/components/Button/src/ToggleButton/ToggleButton.test.tsx b/packages/components/Button/src/ToggleButton/ToggleButton.test.tsx deleted file mode 100644 index ef3c34c83d..0000000000 --- a/packages/components/Button/src/ToggleButton/ToggleButton.test.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import * as React from 'react'; -import { ToggleButton } from './ToggleButton'; -import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools'; -import * as renderer from 'react-test-renderer'; - -it('ToggleButton default', () => { - const tree = renderer.create(Default Button).toJSON(); - expect(tree).toMatchSnapshot(); -}); - -it('Button simple rendering does not invalidate styling', () => { - checkRenderConsistency(() => Default button, 2); -}); - -it('Button re-renders correctly', () => { - checkReRender(() => Render twice, 2); -}); - -it('Button shares produced styles across multiple renders', () => { - const style = { backgroundColor: 'black' }; - checkRenderConsistency(() => Shared styles, 2); -}); - -it('Button re-renders correctly with style', () => { - const style = { borderColor: 'blue' }; - checkReRender(() => Shared Style Render, 2); -}); diff --git a/packages/components/Button/src/ToggleButton/__snapshots__/ToggleButton.test.tsx.snap b/packages/components/Button/src/ToggleButton/__snapshots__/ToggleButton.test.tsx.snap deleted file mode 100644 index 2ba6c42753..0000000000 --- a/packages/components/Button/src/ToggleButton/__snapshots__/ToggleButton.test.tsx.snap +++ /dev/null @@ -1,71 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`ToggleButton default 1`] = ` - - - Default Button - - -`; diff --git a/packages/components/Button/src/deprecated/Button.test.tsx b/packages/components/Button/src/deprecated/Button.test.tsx deleted file mode 100644 index 19dc10d239..0000000000 --- a/packages/components/Button/src/deprecated/Button.test.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import * as React from 'react'; -import { Button } from './Button'; -import * as renderer from 'react-test-renderer'; - -it('Button default', () => { - const tree = renderer.create(