aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2018-05-15 11:19:51 +0200
committerSonarTech <sonartech@sonarsource.com>2018-05-17 20:20:44 +0200
commitc26ae42214c23da0ced318d2a8bb9ce6589c72ff (patch)
tree0e2dc8bfa52808ff9835be27b37a04a021e049ec /server/sonar-web/src
parent965717195e58808778753edd0daa0e3d9e831cdd (diff)
downloadsonarqube-c26ae42214c23da0ced318d2a8bb9ce6589c72ff.tar.gz
sonarqube-c26ae42214c23da0ced318d2a8bb9ce6589c72ff.zip
SONAR-10682 Impossible to create new metric domain
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r--server/sonar-web/src/main/js/apps/custom-metrics/components/Form.tsx7
-rw-r--r--server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/Form-test.tsx31
2 files changed, 37 insertions, 1 deletions
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<Props, State> {
};
render() {
+ const domains = [...this.props.domains];
+ if (this.state.domain) {
+ domains.push(this.state.domain);
+ }
+
return (
<SimpleModal
header={this.props.header}
@@ -146,7 +151,7 @@ export default class Form extends React.PureComponent<Props, State> {
<label htmlFor="create-metric-domain">{translate('custom_metrics.domain')}</label>
<Creatable
onChange={this.handleDomainChange}
- options={this.props.domains.map(domain => ({ label: domain, value: domain }))}
+ options={domains.map(domain => ({ label: domain, value: domain }))}
value={this.state.domain}
/>
</div>
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(
+ <Form
+ confirmButtonText="confirmButtonText"
+ domains={['Coverage', 'Issues']}
+ header="header"
+ onClose={jest.fn()}
+ onSubmit={jest.fn()}
+ types={['INT', 'STRING']}
+ />
+ );
+
+ const optionsBefore = [
+ { label: 'Coverage', value: 'Coverage' },
+ { label: 'Issues', value: 'Issues' }
+ ];
+ expect(getSelect().prop('options')).toEqual(optionsBefore);
+
+ getSelect().prop<Function>('onChange')({ value: 'Another' });
+ wrapper.update();
+
+ expect(getSelect().prop('options')).toEqual([
+ ...optionsBefore,
+ { label: 'Another', value: 'Another' }
+ ]);
+
+ function getSelect() {
+ return wrapper.dive().find('Creatable');
+ }
+});