diff options
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
3 files changed, 42 insertions, 77 deletions
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 fb20e074f63..126d912c9b5 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 @@ -19,8 +19,7 @@ */ import { map } from 'lodash'; import * as React from 'react'; -import AlertErrorIcon from 'sonar-ui-common/components/icons/AlertErrorIcon'; -import AlertSuccessIcon from 'sonar-ui-common/components/icons/AlertSuccessIcon'; +import { translate } from 'sonar-ui-common/helpers/l10n'; import { HEALTH_FIELD, STATE_FIELD } from '../../utils'; import HealthItem from './HealthItem'; @@ -29,7 +28,7 @@ export interface Props { value: T.SysInfoValue; } -export default function SysInfoItem({ name, value }: Props): JSX.Element { +export default function SysInfoItem({ name, value }: Props) { if (name === HEALTH_FIELD || name === STATE_FIELD) { return <HealthItem className="no-margin" health={value as T.HealthType} />; } @@ -38,35 +37,23 @@ export default function SysInfoItem({ name, value }: Props): JSX.Element { } switch (typeof value) { case 'boolean': - return <BooleanItem value={value} />; + return <>{translate(value ? 'yes' : 'no')}</>; case 'object': - return <ObjectItem value={value} />; + return ( + <table className="data"> + <tbody> + {map(value, (v, n) => ( + <tr key={n}> + <td className="thin nowrap">{n}</td> + <td> + <SysInfoItem name={n} value={v} /> + </td> + </tr> + ))} + </tbody> + </table> + ); default: return <code>{value}</code>; } } - -function BooleanItem({ value }: { value: boolean }) { - if (value) { - return <AlertSuccessIcon />; - } else { - return <AlertErrorIcon />; - } -} - -function ObjectItem({ value }: { value: T.SysInfoValueObject }) { - return ( - <table className="data"> - <tbody> - {map(value, (value, name) => ( - <tr key={name}> - <td className="thin nowrap">{name}</td> - <td> - <SysInfoItem name={name} value={value} /> - </td> - </tr> - ))} - </tbody> - </table> - ); -} 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 a640c7b0a57..ca0e85fdce1 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 @@ -19,60 +19,24 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; +import HealthItem from '../HealthItem'; import SysInfoItem, { Props } from '../SysInfoItem'; -it('should render string', () => { - expect( - shallowRender('/some/path/as/an/example') - .find('code') - .text() - ).toBe('/some/path/as/an/example'); -}); - -it('should render object', () => { - expect( - shallowRender({ bar: 'baz' }) - .find('ObjectItem') - .prop('value') - ).toEqual({ bar: 'baz' }); -}); - -it('should render boolean', () => { - expect( - shallowRender(true) - .find('BooleanItem') - .prop('value') - ).toBe(true); +it('should render correctly', () => { + expect(shallowRender('/some/path/as/an/example')).toMatchSnapshot('string'); + expect(shallowRender({ foo: 'Far', bar: { a: 1, b: 'b' }, baz: true })).toMatchSnapshot('object'); + expect(shallowRender(true)).toMatchSnapshot('true'); + expect(shallowRender(false)).toMatchSnapshot('false'); }); it('should render health item', () => { expect( shallowRender('GREEN', 'Health') - .find('HealthItem') + .find(HealthItem) .prop('health') ).toBe('GREEN'); }); -it('should render `true`', () => { - const wrapper = shallowRender(true); - expect(wrapper.find('BooleanItem').exists()).toBe(true); - expect(wrapper.dive()).toMatchSnapshot(); -}); - -it('should render `false`', () => { - 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(<SysInfoItem name={name} value={value} />); } 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 212e5d97aa1..7b2c54af4c1 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,10 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`should render \`false\` 1`] = `<AlertErrorIcon />`; - -exports[`should render \`true\` 1`] = `<AlertSuccessIcon />`; +exports[`should render correctly: false 1`] = ` +<Fragment> + no +</Fragment> +`; -exports[`should render object correctly 1`] = ` +exports[`should render correctly: object 1`] = ` <table className="data" > @@ -62,3 +64,15 @@ exports[`should render object correctly 1`] = ` </tbody> </table> `; + +exports[`should render correctly: string 1`] = ` +<code> + /some/path/as/an/example +</code> +`; + +exports[`should render correctly: true 1`] = ` +<Fragment> + yes +</Fragment> +`; |