Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Silva committed Aug 7, 2018
1 parent 316cf01 commit 78f7fe2
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ProfileSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ProfileSummary.propTypes = {
/** Rules to be applied over the profile */
rules: RuleShape.isRequired,
/** Render prop that receives all display data */
children: PropTypes.func,
children: PropTypes.func.isRequired,
/** React-intl injected utility */
intl: intlShape.isRequired,
}
Expand Down
78 changes: 78 additions & 0 deletions src/ProfileSummary.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React from 'react'
import { shallowWithIntl, loadTranslation } from 'enzyme-react-intl'
import ProfileSummary from './ProfileSummary'
import mockRules from './__mocks__/rules'
import mockProfile from './__mocks__/profile'

loadTranslation('./src/locales/pt.json')

describe('ProfileSummary', () => {
let wrapper
beforeEach(() => {
// Arrange
wrapper = shallowWithIntl(
<ProfileSummary profile={mockProfile} rules={mockRules}>
{displayData => <span displayData={displayData}>It works!</span>}
</ProfileSummary>,
).dive()
})

it('should render its children', () => {
// Act
const result = wrapper.find('span')

// Assert
expect(result).toHaveLength(1)
})

it('should pass down the data in the correct structure', () => {
// Act
const result = wrapper.find('span').props().displayData

// Assert
expect(result.personalData).toBeTruthy()
expect(result.personalData.firstName).toBeTruthy()
expect(result.businessData).toBeTruthy()
})

it('should correctly signal hidden fields in the data', () => {
// Arrange
const hiddenRules = {
...mockRules,
businessFields: [
{
name: 'tradeName',
label: 'tradeName',
hidden: true,
},
],
}
const hiddenWrapper = shallowWithIntl(
<ProfileSummary profile={mockProfile} rules={hiddenRules}>
{displayData => <span displayData={displayData}>It works!</span>}
</ProfileSummary>,
).dive()

// Act
const result = hiddenWrapper.find('span').props().displayData

// Assert
expect(result.businessData.tradeName.hidden).toBe(true)
})

it('should translate the gender before serving', () => {
// Arrange
const panProfile = { ...mockProfile, gender: 'pangender' }
const panWrapper = shallowWithIntl(
<ProfileSummary profile={panProfile} rules={mockRules}>
{displayData => <span displayData={displayData}>It works!</span>}
</ProfileSummary>,
).dive()

// Act
const result = panWrapper.find('span').props().displayData

// Assert
expect(result.personalData.gender.value).toBe('Pangênero')
})
})

0 comments on commit 78f7fe2

Please sign in to comment.