From 78f7fe293923a7ea4c3033a753ed39a2dc28e965 Mon Sep 17 00:00:00 2001 From: Gustavo Silva Date: Tue, 7 Aug 2018 17:41:57 -0300 Subject: [PATCH] Add tests --- src/ProfileSummary.js | 2 +- src/ProfileSummary.test.js | 78 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/ProfileSummary.test.js diff --git a/src/ProfileSummary.js b/src/ProfileSummary.js index 5dedabf8..55227b97 100644 --- a/src/ProfileSummary.js +++ b/src/ProfileSummary.js @@ -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, } diff --git a/src/ProfileSummary.test.js b/src/ProfileSummary.test.js new file mode 100644 index 00000000..23ba81c7 --- /dev/null +++ b/src/ProfileSummary.test.js @@ -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( + + {displayData => It works!} + , + ).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( + + {displayData => It works!} + , + ).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( + + {displayData => It works!} + , + ).dive() + + // Act + const result = panWrapper.find('span').props().displayData + + // Assert + expect(result.personalData.gender.value).toBe('PangĂȘnero') + }) +})