Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove DefaultProps from the StatusBar Component (#31631)
Summary: Issue #31607. defaultProps makes it difficult to migrate components to functional. ## Changelog [General] [Changed] - Remove defaultProps from the StatusBar Component. Pull Request resolved: #31631 Test Plan: Verified the behaviour of the existing functionality after the removal on the RN Tester app. https://user-images.githubusercontent.com/11355609/120085709-a2b35f80-c0da-11eb-94f2-2649270155ef.mov Reviewed By: sota000 Differential Revision: D30259324 Pulled By: lunaleaps fbshipit-source-id: 0c8841691198761589fdd029cab36629f7dfa757
- Loading branch information
1 parent
c18a492
commit 5923ee5
Showing
2 changed files
with
68 additions
and
14 deletions.
There are no files selected for viewing
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
62 changes: 62 additions & 0 deletions
62
Libraries/Components/StatusBar/__tests__/StatusBar-test.js
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,62 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @emails oncall+react_native | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const React = require('react'); | ||
const ReactTestRenderer = require('react-test-renderer'); | ||
|
||
const StatusBar = require('../StatusBar'); | ||
|
||
describe('StatusBar', () => { | ||
it('renders the statusbar', () => { | ||
const component = ReactTestRenderer.create(<StatusBar />); | ||
expect(component).not.toBeNull(); | ||
}); | ||
it('renders the statusbar animated enabled', () => { | ||
const component = ReactTestRenderer.create(<StatusBar animated={true} />); | ||
expect(component.toTree().props.animated).toBe(true); | ||
}); | ||
it('renders the statusbar with fade transition on hide', () => { | ||
const component = ReactTestRenderer.create(<StatusBar hidden={true} />); | ||
expect(component.toTree().props.hidden).toBe(true); | ||
}); | ||
it('renders the statusbar with a background color', () => { | ||
const component = ReactTestRenderer.create( | ||
<StatusBar backgroundColor={'#fff'} />, | ||
); | ||
expect(component.toTree().props.backgroundColor).toBe('#fff'); | ||
expect(component.toTree().type._defaultProps.backgroundColor.animated).toBe( | ||
false, | ||
); | ||
}); | ||
it('renders the statusbar with default barStyle', () => { | ||
const component = ReactTestRenderer.create(<StatusBar />); | ||
StatusBar.setBarStyle('default'); | ||
expect(component.toTree().type._defaultProps.barStyle.value).toBe( | ||
'default', | ||
); | ||
expect(component.toTree().type._defaultProps.barStyle.animated).toBe(false); | ||
}); | ||
it('renders the statusbar but should not be visible', () => { | ||
const component = ReactTestRenderer.create(<StatusBar hidden={true} />); | ||
expect(component.toTree().props.hidden).toBe(true); | ||
expect(component.toTree().type._defaultProps.hidden.animated).toBe(false); | ||
expect(component.toTree().type._defaultProps.hidden.transition).toBe( | ||
'fade', | ||
); | ||
}); | ||
it('renders the statusbar with networkActivityIndicatorVisible true', () => { | ||
const component = ReactTestRenderer.create( | ||
<StatusBar networkActivityIndicatorVisible={true} />, | ||
); | ||
expect(component.toTree().props.networkActivityIndicatorVisible).toBe(true); | ||
}); | ||
}); |