-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] Jest multi plat testing #2506
Draft
rurikoaraki
wants to merge
12
commits into
microsoft:main
Choose a base branch
from
rurikoaraki:jest_multi_plat_test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
24eb18a
Move all tests and snapshots under one folder, edit config
rurikoaraki 8903763
Move all iOS tests into one folder
rurikoaraki b250ffd
Move files out of src, add win32 test files
rurikoaraki 0d347ed
Add snapshots for win32
rurikoaraki 704edfd
Merge branch 'main' into jest_multi_plat_test
rurikoaraki 0d58d7e
Ignore test files in publishing
rurikoaraki 54c520e
Ignore test files in publishing
rurikoaraki 4133912
Move around files
rurikoaraki 2e44846
Fix build error
rurikoaraki 1a8ac8e
Fix some tests
rurikoaraki f8cff2a
Move around structure again...
rurikoaraki 8e3cf01
Change files
rurikoaraki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-native-button-4f7a77ca-3caa-43b1-a837-9c6b29b1e4ed.json
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,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Multi-plat jest setup", | ||
"packageName": "@fluentui-react-native/button", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
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,2 @@ | ||
# Don't include test files in package | ||
__tests__/ | ||
10 changes: 10 additions & 0 deletions
10
packages/components/Button/__tests__/ButtonLegacy.test.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,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(<Button content="Default Button" />).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}; |
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,86 @@ | ||
import * as React from 'react'; | ||
import { Button } from '../src/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'; | ||
|
||
export const buttonV1Tests = () => { | ||
describe('Button component tests', () => { | ||
it('Button default', () => { | ||
const tree = renderer.create(<Button>Default Button</Button>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button disabled', () => { | ||
const tree = renderer.create(<Button disabled>Disabled Button</Button>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button primary', () => { | ||
const tree = renderer.create(<Button appearance="primary">Primary Button</Button>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button subtle', () => { | ||
const tree = renderer.create(<Button appearance="subtle">Subtle Button</Button>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button circular', () => { | ||
const tree = renderer.create(<Button shape="circular">Circular Button</Button>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button square', () => { | ||
const tree = renderer.create(<Button shape="square">Square Button</Button>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button small', () => { | ||
const tree = renderer.create(<Button size="small">Small Button</Button>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button large', () => { | ||
const tree = renderer.create(<Button size="large">Large Button</Button>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button customized', () => { | ||
const CustomButton = Button.customize({ backgroundColor: 'pink' }); | ||
const tree = renderer.create(<CustomButton>Custom Button</CustomButton>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button composed', () => { | ||
const ComposedButton = Button.compose({ | ||
slots: { | ||
root: Pressable, | ||
icon: Icon, | ||
content: Text, | ||
}, | ||
}); | ||
const tree = renderer.create(<ComposedButton>Composed Button with RNText</ComposedButton>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button simple rendering does not invalidate styling', () => { | ||
checkRenderConsistency(() => <Button>Default button</Button>, 2); | ||
}); | ||
|
||
it('Button re-renders correctly', () => { | ||
checkReRender(() => <Button>Render twice</Button>, 2); | ||
}); | ||
|
||
it('Button shares produced styles across multiple renders', () => { | ||
const style = { backgroundColor: 'black' }; | ||
checkRenderConsistency(() => <Button style={style}>Shared styles</Button>, 2); | ||
}); | ||
|
||
it('Button re-renders correctly with style', () => { | ||
const style = { borderColor: 'blue' }; | ||
checkReRender(() => <Button style={style}>Shared Style Render</Button>, 2); | ||
}); | ||
}); | ||
}; |
29 changes: 29 additions & 0 deletions
29
packages/components/Button/__tests__/CompoundButton.test.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,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(<CompoundButton secondaryContent="sublabel">Default Button</CompoundButton>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button simple rendering does not invalidate styling', () => { | ||
checkRenderConsistency(() => <CompoundButton>Default button</CompoundButton>, 2); | ||
}); | ||
|
||
it('Button re-renders correctly', () => { | ||
checkReRender(() => <CompoundButton>Render twice</CompoundButton>, 2); | ||
}); | ||
|
||
it('Button shares produced styles across multiple renders', () => { | ||
const style = { backgroundColor: 'black' }; | ||
checkRenderConsistency(() => <CompoundButton style={style}>Shared styles</CompoundButton>, 2); | ||
}); | ||
|
||
it('Button re-renders correctly with style', () => { | ||
const style = { borderColor: 'blue' }; | ||
checkReRender(() => <CompoundButton style={style}>Shared Style Render</CompoundButton>, 2); | ||
}); | ||
}; |
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,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(<FAB icon={iconProps}>Default FAB (iOS)</FAB>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Custom FAB with no shadow(iOS)', () => { | ||
const CustomFABNoShadow = FAB.customize({ shadowToken: undefined }); | ||
const tree = renderer.create(<CustomFABNoShadow icon={iconProps}>Custom FAB with no shadow(iOS)</CustomFABNoShadow>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button simple rendering does not invalidate styling', () => { | ||
checkRenderConsistency(() => <FAB icon={iconProps}>Default FAB</FAB>, 2); | ||
}); | ||
|
||
it('FAB re-renders correctly', () => { | ||
checkReRender(() => <FAB icon={iconProps}>Render twice</FAB>, 2); | ||
}); | ||
|
||
it('FAB shares produced styles across multiple renders', () => { | ||
const style = { backgroundColor: 'black' }; | ||
checkRenderConsistency( | ||
() => ( | ||
<FAB icon={iconProps} style={style}> | ||
Shared styles | ||
</FAB> | ||
), | ||
2, | ||
); | ||
}); | ||
|
||
it('FAB re-renders correctly with style', () => { | ||
const style = { borderColor: 'blue' }; | ||
checkReRender( | ||
() => ( | ||
<FAB icon={iconProps} style={style}> | ||
Shared Style Render | ||
</FAB> | ||
), | ||
2, | ||
); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.unmock('react-native/Libraries/Utilities/Platform'); | ||
}); | ||
}; |
29 changes: 29 additions & 0 deletions
29
packages/components/Button/__tests__/ToggleButton.test.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,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(<ToggleButton>Default Button</ToggleButton>).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Button simple rendering does not invalidate styling', () => { | ||
checkRenderConsistency(() => <ToggleButton>Default button</ToggleButton>, 2); | ||
}); | ||
|
||
it('Button re-renders correctly', () => { | ||
checkReRender(() => <ToggleButton>Render twice</ToggleButton>, 2); | ||
}); | ||
|
||
it('Button shares produced styles across multiple renders', () => { | ||
const style = { backgroundColor: 'black' }; | ||
checkRenderConsistency(() => <ToggleButton style={style}>Shared styles</ToggleButton>, 2); | ||
}); | ||
|
||
it('Button re-renders correctly with style', () => { | ||
const style = { borderColor: 'blue' }; | ||
checkReRender(() => <ToggleButton style={style}>Shared Style Render</ToggleButton>, 2); | ||
}); | ||
}; |
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,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(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need this in every package, can we also update the component-generator later, if not in this PR? I know that isn't heavily used but I think some people may still try to use that as their "first new package" template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that makes sense. I can also add it top level instead.