-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: adding test cases for code-coverage (#81)
* test: adding test cases for code-coverage * fix: addressinng review comments Co-authored-by: rachana <[email protected]>
- Loading branch information
1 parent
ce3eccd
commit 71fe4a6
Showing
11 changed files
with
147 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules/ | ||
build/ | ||
reports/ | ||
yarn-error.log | ||
.DS_Store |
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,16 @@ | ||
{ | ||
"setupFiles": ["<rootDir>/test/setupTests.js"], | ||
"testRegex": "/*.test.js$", | ||
"collectCoverage": true, | ||
"coverageReporters": ["lcov"], | ||
"coverageDirectory": "reports/jest", | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 0, | ||
"functions": 0, | ||
"lines": 0, | ||
"statements": 0 | ||
} | ||
}, | ||
"moduleDirectories": ["node_modules", "src"] | ||
} |
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
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
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
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,8 @@ | ||
import FormattedMessage from '../src/FormattedMessage'; | ||
|
||
describe('<FormattedMessage /> rendering', () => { | ||
it('should have default value and alt props', () => { | ||
expect(FormattedMessage.defaultProps.values).toBeDefined(); | ||
expect(FormattedMessage.defaultProps.alt).toBeDefined(); | ||
}); | ||
}); |
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,39 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import TextProvider from '../src/TextProvider'; | ||
import FormattedMessage from '../src/FormattedMessage'; | ||
|
||
describe('<TextProvider /> rendering', () => { | ||
const randomId = 'Random Id'; | ||
const values = { | ||
valueToBeInjected: 'Random Value', | ||
}; | ||
const sampleText = { | ||
'Random Id': '{valueToBeInjected}', | ||
}; | ||
|
||
it('should have default globalText prop', () => { | ||
expect(TextProvider.defaultProps.globalText).toBeDefined(); | ||
}); | ||
|
||
it('should render correctly', () => { | ||
let wrapper = renderer.create( | ||
<TextProvider | ||
globalText={sampleText} | ||
children={<FormattedMessage id={randomId} values={values} />} | ||
/>, | ||
); | ||
expect(wrapper.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should replace the id with value in the context message', () => { | ||
let wrapper = renderer.create( | ||
<TextProvider | ||
globalText={sampleText} | ||
children={<FormattedMessage id={randomId} values={values} />} | ||
/>, | ||
); | ||
expect(wrapper.toJSON().props.style.fontSize).toBe('inherit'); | ||
expect(wrapper.toJSON().props.dangerouslySetInnerHTML.__html).toBe(values['valueToBeInjected']); | ||
}); | ||
}); |
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,47 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import TextProvider from '../src/TextProvider'; | ||
import withTextProvider from '../src/TextProviderHOC'; | ||
|
||
describe('<TextProviderHOC /> rendering', () => { | ||
class SomeComponent extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
render() { | ||
return <div>{this.props.id ? this.props.id : 'id'}</div>; | ||
} | ||
} | ||
|
||
it('should render TextProviderHOC correctly', () => { | ||
const MockWithHOC = withTextProvider(SomeComponent); | ||
|
||
const wrapper = renderer.create(<MockWithHOC />); | ||
expect(wrapper.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should add getTextForKey as prop for component', () => { | ||
const MockWithHOC = withTextProvider(SomeComponent); | ||
|
||
const wrapper = renderer.create(<MockWithHOC />).root; | ||
expect(wrapper.findByType(SomeComponent).props.getTextForKey).toBeDefined(); | ||
|
||
// TextProviderHOC uses {} as default context | ||
expect(wrapper.findByType(SomeComponent).props.getTextForKey('test')).toEqual(''); | ||
}); | ||
|
||
it('should render the component provided along with props', () => { | ||
const MockWithHOC = withTextProvider(SomeComponent); | ||
const wrapper = renderer.create(<MockWithHOC id="id" />).root; | ||
expect(wrapper.findByType(SomeComponent).props.id).toEqual('id'); | ||
}); | ||
|
||
it('test getTextForKey with context', () => { | ||
let context = { id: 'test id' }; | ||
const MockWithHOC = withTextProvider(SomeComponent); | ||
let wrapper = renderer.create(<TextProvider globalText={context} children={<MockWithHOC />} />) | ||
.root; | ||
expect(wrapper.findByType(SomeComponent).props.getTextForKey('id')).toEqual(context.id); | ||
}); | ||
}); |
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,16 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<TextProvider /> rendering should render correctly 1`] = ` | ||
<span | ||
dangerouslySetInnerHTML={ | ||
Object { | ||
"__html": "Random Value", | ||
} | ||
} | ||
style={ | ||
Object { | ||
"fontSize": "inherit", | ||
} | ||
} | ||
/> | ||
`; |
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<TextProviderHOC /> rendering should render TextProviderHOC correctly 1`] = ` | ||
<div> | ||
id | ||
</div> | ||
`; |
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,4 @@ | ||
import Enzyme from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
// React 16 Enzyme adapter | ||
Enzyme.configure({ adapter: new Adapter() }); |