From 71bee881032f60e651a724c6264435eed7520e21 Mon Sep 17 00:00:00 2001 From: Grégoire Aubert Date: Mon, 29 Apr 2019 08:45:28 +0200 Subject: Rename icon mocks for easier auto import of icons --- .../__tests__/__snapshots__/AboutApp-test.tsx.snap | 26 +-- .../__snapshots__/EditMembers-test.tsx.snap | 8 +- .../system/components/info-items/SysInfoItem.tsx | 6 +- .../info-items/__tests__/SysInfoItem-test.tsx | 62 ++++-- .../__snapshots__/SysInfoItem-test.tsx.snap | 244 +++++---------------- .../__snapshots__/NewProjectForm-test.tsx.snap | 4 +- .../__mocks__/AlertSuccessIcon.tsx | 2 +- .../icons-components/__mocks__/BugIcon.tsx | 2 +- .../icons-components/__mocks__/BulletListIcon.tsx | 2 +- .../icons-components/__mocks__/ClearIcon.tsx | 2 +- .../icons-components/__mocks__/CodeSmellIcon.tsx | 2 +- .../icons-components/__mocks__/DeleteIcon.tsx | 2 +- .../icons-components/__mocks__/SearchIcon.tsx | 2 +- .../__mocks__/SecurityHotspotIcon.tsx | 2 +- .../icons-components/__mocks__/TagsIcon.tsx | 2 +- .../__mocks__/VulnerabilityIcon.tsx | 2 +- 16 files changed, 129 insertions(+), 241 deletions(-) (limited to 'server') diff --git a/server/sonar-web/src/main/js/apps/about/components/__tests__/__snapshots__/AboutApp-test.tsx.snap b/server/sonar-web/src/main/js/apps/about/components/__tests__/__snapshots__/AboutApp-test.tsx.snap index 0a365f46bfb..5a92273dc63 100644 --- a/server/sonar-web/src/main/js/apps/about/components/__tests__/__snapshots__/AboutApp-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/about/components/__tests__/__snapshots__/AboutApp-test.tsx.snap @@ -188,7 +188,7 @@ exports[`should render correctly 1`] = ` - + issue.type.BUG.plural @@ -225,7 +225,7 @@ exports[`should render correctly 1`] = ` - + issue.type.VULNERABILITY.plural @@ -262,7 +262,7 @@ exports[`should render correctly 1`] = ` - + issue.type.CODE_SMELL.plural @@ -299,7 +299,7 @@ exports[`should render correctly 1`] = ` - + issue.type.SECURITY_HOTSPOT.plural @@ -522,7 +522,7 @@ exports[`should render correctly 1`] = `
- +

- +

- +

- +

- + @@ -806,7 +806,7 @@ exports[`should render correctly 1`] = ` onClick={[Function]} style={Object {}} > - + @@ -834,7 +834,7 @@ exports[`should render correctly 1`] = ` onClick={[Function]} style={Object {}} > - + @@ -862,7 +862,7 @@ exports[`should render correctly 1`] = ` onClick={[Function]} style={Object {}} > - + @@ -890,7 +890,7 @@ exports[`should render correctly 1`] = ` onClick={[Function]} style={Object {}} > - + diff --git a/server/sonar-web/src/main/js/apps/groups/components/__tests__/__snapshots__/EditMembers-test.tsx.snap b/server/sonar-web/src/main/js/apps/groups/components/__tests__/__snapshots__/EditMembers-test.tsx.snap index daf6e70e72b..98241e10f0c 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/__tests__/__snapshots__/EditMembers-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/groups/components/__tests__/__snapshots__/EditMembers-test.tsx.snap @@ -36,7 +36,7 @@ exports[`should edit members 1`] = ` } type="button" > - + @@ -79,7 +79,7 @@ exports[`should edit members 2`] = ` } type="button" > - + @@ -441,7 +441,7 @@ exports[`should edit members 2`] = ` loading={false} timeout={100} > - @@ -553,7 +553,7 @@ exports[`should edit members 3`] = ` } type="button" > - + diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/SysInfoItem.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/SysInfoItem.tsx index 9631e25842a..3389df8bb61 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/SysInfoItem.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/SysInfoItem.tsx @@ -25,7 +25,7 @@ import AlertSuccessIcon from '../../../../components/icons-components/AlertSucce import { HealthType, SysValue, SysValueObject } from '../../../../api/system'; import { HEALTH_FIELD } from '../../utils'; -interface Props { +export interface Props { name: string; value: SysValue; } @@ -39,9 +39,9 @@ export default function SysInfoItem({ name, value }: Props): JSX.Element { } switch (typeof value) { case 'boolean': - return ; + return ; case 'object': - return ; + return ; default: return {value}; } diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/SysInfoItem-test.tsx b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/SysInfoItem-test.tsx index d2def0a2fb2..7d4db450fbe 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/SysInfoItem-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/SysInfoItem-test.tsx @@ -18,45 +18,61 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; -import { shallow, mount } from 'enzyme'; -import SysInfoItem from '../SysInfoItem'; - -jest.mock('../../../../../components/icons-components/AlertSuccessIcon'); +import { shallow } from 'enzyme'; +import SysInfoItem, { Props } from '../SysInfoItem'; it('should render string', () => { - const wrapper = shallow(); - expect(wrapper.find('code').text()).toBe('/some/path/as/an/example'); + expect( + shallowRender('/some/path/as/an/example') + .find('code') + .text() + ).toBe('/some/path/as/an/example'); }); it('should render object', () => { - const wrapper = shallow(); - expect(wrapper.find('ObjectItem').prop('value')).toEqual({ bar: 'baz' }); + expect( + shallowRender({ bar: 'baz' }) + .find('ObjectItem') + .prop('value') + ).toEqual({ bar: 'baz' }); }); it('should render boolean', () => { - const wrapper = shallow(); - expect(wrapper.find('BooleanItem').prop('value')).toBe(true); + expect( + shallowRender(true) + .find('BooleanItem') + .prop('value') + ).toBe(true); }); it('should render health item', () => { - const wrapper = shallow(); - expect(wrapper.find('HealthItem').prop('health')).toBe('GREEN'); -}); - -it('should render object correctly', () => { expect( - mount( - - ).find('ObjectItem') - ).toMatchSnapshot(); + shallowRender('GREEN', 'Health') + .find('HealthItem') + .prop('health') + ).toBe('GREEN'); }); it('should render `true`', () => { - const wrapper = mount(); - expect(wrapper.find('AlertSuccessIcon').exists()).toBeTruthy(); + const wrapper = shallowRender(true); + expect(wrapper.find('BooleanItem').exists()).toBe(true); + expect(wrapper.dive()).toMatchSnapshot(); }); it('should render `false`', () => { - const wrapper = mount(); - expect(wrapper.find('AlertErrorIcon').exists()).toBeTruthy(); + const wrapper = shallowRender(false); + expect(wrapper.find('BooleanItem').exists()).toBe(true); + expect(wrapper.dive()).toMatchSnapshot(); }); + +it('should render object correctly', () => { + expect( + shallowRender({ foo: 'Far', bar: { a: 1, b: 'b' }, baz: true }) + .find('ObjectItem') + .dive() + ).toMatchSnapshot(); +}); + +function shallowRender(value: Props['value'], name: Props['name'] = 'foo') { + return shallow(); +} diff --git a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/SysInfoItem-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/SysInfoItem-test.tsx.snap index 7c39d65bb9e..212e5d97aa1 100644 --- a/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/SysInfoItem-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/system/components/info-items/__tests__/__snapshots__/SysInfoItem-test.tsx.snap @@ -1,192 +1,64 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`should render \`false\` 1`] = ``; + +exports[`should render \`true\` 1`] = ``; + exports[`should render object correctly 1`] = ` -Array [ - - + + + + + + - - - - - - - - - - - - - - -
+ foo + + +
- foo - - - - Far - - -
- bar - - - - - - - - - - - - - - -
- a - - - - 1 - - -
- b - - - - b - - -
-
-
-
- baz - - - - - - -
-
, - - + bar + + + + - - - - - - - - - - -
+ +
- a - - - - 1 - - -
- b - - - - b - - -
-
, -] + + baz + + + + + + + `; diff --git a/server/sonar-web/src/main/js/apps/tutorials/components/__tests__/__snapshots__/NewProjectForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/tutorials/components/__tests__/__snapshots__/NewProjectForm-test.tsx.snap index 94a01466fdb..07ce9faa675 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/components/__tests__/__snapshots__/NewProjectForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/tutorials/components/__tests__/__snapshots__/NewProjectForm-test.tsx.snap @@ -157,7 +157,7 @@ exports[`creates new project 3`] = ` } type="button" > - + @@ -215,7 +215,7 @@ exports[`deletes project 1`] = ` } type="button" > - + diff --git a/server/sonar-web/src/main/js/components/icons-components/__mocks__/AlertSuccessIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/__mocks__/AlertSuccessIcon.tsx index 6f3c229e6e1..c597a641ba6 100644 --- a/server/sonar-web/src/main/js/components/icons-components/__mocks__/AlertSuccessIcon.tsx +++ b/server/sonar-web/src/main/js/components/icons-components/__mocks__/AlertSuccessIcon.tsx @@ -17,6 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -export default function AlertSuccessIcon() { +export default function MOCKAlertSuccessIcon() { return null; } diff --git a/server/sonar-web/src/main/js/components/icons-components/__mocks__/BugIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/__mocks__/BugIcon.tsx index 6500ff94ef3..987265294fc 100644 --- a/server/sonar-web/src/main/js/components/icons-components/__mocks__/BugIcon.tsx +++ b/server/sonar-web/src/main/js/components/icons-components/__mocks__/BugIcon.tsx @@ -17,6 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -export default function BugIcon() { +export default function MOCKBugIcon() { return null; } diff --git a/server/sonar-web/src/main/js/components/icons-components/__mocks__/BulletListIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/__mocks__/BulletListIcon.tsx index 76afa5e10e3..1ba3b49c79c 100644 --- a/server/sonar-web/src/main/js/components/icons-components/__mocks__/BulletListIcon.tsx +++ b/server/sonar-web/src/main/js/components/icons-components/__mocks__/BulletListIcon.tsx @@ -17,6 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -export default function BulletListIcon() { +export default function MOCKBulletListIcon() { return null; } diff --git a/server/sonar-web/src/main/js/components/icons-components/__mocks__/ClearIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/__mocks__/ClearIcon.tsx index be30a6ea7be..9565391375c 100644 --- a/server/sonar-web/src/main/js/components/icons-components/__mocks__/ClearIcon.tsx +++ b/server/sonar-web/src/main/js/components/icons-components/__mocks__/ClearIcon.tsx @@ -17,6 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -export default function ClearIcon() { +export default function MOCKClearIcon() { return null; } diff --git a/server/sonar-web/src/main/js/components/icons-components/__mocks__/CodeSmellIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/__mocks__/CodeSmellIcon.tsx index 2ac884d8b5f..8fb340f47c9 100644 --- a/server/sonar-web/src/main/js/components/icons-components/__mocks__/CodeSmellIcon.tsx +++ b/server/sonar-web/src/main/js/components/icons-components/__mocks__/CodeSmellIcon.tsx @@ -17,6 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -export default function CodeSmellIcon() { +export default function MOCKCodeSmellIcon() { return null; } diff --git a/server/sonar-web/src/main/js/components/icons-components/__mocks__/DeleteIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/__mocks__/DeleteIcon.tsx index 07f11e31f4f..8b347e92d5b 100644 --- a/server/sonar-web/src/main/js/components/icons-components/__mocks__/DeleteIcon.tsx +++ b/server/sonar-web/src/main/js/components/icons-components/__mocks__/DeleteIcon.tsx @@ -17,6 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -export default function DeleteIcon() { +export default function MOCKDeleteIcon() { return null; } diff --git a/server/sonar-web/src/main/js/components/icons-components/__mocks__/SearchIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/__mocks__/SearchIcon.tsx index fc75c18a3f1..323ea37cd8d 100644 --- a/server/sonar-web/src/main/js/components/icons-components/__mocks__/SearchIcon.tsx +++ b/server/sonar-web/src/main/js/components/icons-components/__mocks__/SearchIcon.tsx @@ -17,6 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -export default function SearchIcon() { +export default function MOCKSearchIcon() { return null; } diff --git a/server/sonar-web/src/main/js/components/icons-components/__mocks__/SecurityHotspotIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/__mocks__/SecurityHotspotIcon.tsx index bbac07e0e74..8b817c65826 100644 --- a/server/sonar-web/src/main/js/components/icons-components/__mocks__/SecurityHotspotIcon.tsx +++ b/server/sonar-web/src/main/js/components/icons-components/__mocks__/SecurityHotspotIcon.tsx @@ -17,6 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -export default function SecurityHotspotIcon() { +export default function MOCKSecurityHotspotIcon() { return null; } diff --git a/server/sonar-web/src/main/js/components/icons-components/__mocks__/TagsIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/__mocks__/TagsIcon.tsx index df33ee271b8..17223251155 100644 --- a/server/sonar-web/src/main/js/components/icons-components/__mocks__/TagsIcon.tsx +++ b/server/sonar-web/src/main/js/components/icons-components/__mocks__/TagsIcon.tsx @@ -17,6 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -export default function TagsIcon() { +export default function MOCKTagsIcon() { return null; } diff --git a/server/sonar-web/src/main/js/components/icons-components/__mocks__/VulnerabilityIcon.tsx b/server/sonar-web/src/main/js/components/icons-components/__mocks__/VulnerabilityIcon.tsx index fc4bc119626..77038c6540f 100644 --- a/server/sonar-web/src/main/js/components/icons-components/__mocks__/VulnerabilityIcon.tsx +++ b/server/sonar-web/src/main/js/components/icons-components/__mocks__/VulnerabilityIcon.tsx @@ -17,6 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -export default function VulnerabilityIcon() { +export default function MOCKVulnerabilityIcon() { return null; } -- cgit v1.2.3