From: Stas Vilchik Date: Tue, 15 May 2018 09:19:51 +0000 (+0200) Subject: SONAR-10682 Impossible to create new metric domain X-Git-Tag: 7.5~1174 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c26ae42214c23da0ced318d2a8bb9ce6589c72ff;p=sonarqube.git SONAR-10682 Impossible to create new metric domain --- diff --git a/server/sonar-web/src/main/js/apps/custom-metrics/components/Form.tsx b/server/sonar-web/src/main/js/apps/custom-metrics/components/Form.tsx index 89c4fc9ba20..c6d4e5ee4c3 100644 --- a/server/sonar-web/src/main/js/apps/custom-metrics/components/Form.tsx +++ b/server/sonar-web/src/main/js/apps/custom-metrics/components/Form.tsx @@ -90,6 +90,11 @@ export default class Form extends React.PureComponent { }; render() { + const domains = [...this.props.domains]; + if (this.state.domain) { + domains.push(this.state.domain); + } + return ( { ({ label: domain, value: domain }))} + options={domains.map(domain => ({ label: domain, value: domain }))} value={this.state.domain} /> diff --git a/server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/Form-test.tsx b/server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/Form-test.tsx index 1e828bc139e..c3ed8823066 100644 --- a/server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/Form-test.tsx +++ b/server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/Form-test.tsx @@ -57,3 +57,34 @@ it('should render form', async () => { click(wrapper.find('ResetButtonLink')); expect(onClose).toBeCalled(); }); + +it('should create new domain', () => { + const wrapper = shallow( +
+ ); + + const optionsBefore = [ + { label: 'Coverage', value: 'Coverage' }, + { label: 'Issues', value: 'Issues' } + ]; + expect(getSelect().prop('options')).toEqual(optionsBefore); + + getSelect().prop('onChange')({ value: 'Another' }); + wrapper.update(); + + expect(getSelect().prop('options')).toEqual([ + ...optionsBefore, + { label: 'Another', value: 'Another' } + ]); + + function getSelect() { + return wrapper.dive().find('Creatable'); + } +});