]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10682 Impossible to create new metric domain
authorStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 15 May 2018 09:19:51 +0000 (11:19 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 17 May 2018 18:20:44 +0000 (20:20 +0200)
server/sonar-web/src/main/js/apps/custom-metrics/components/Form.tsx
server/sonar-web/src/main/js/apps/custom-metrics/components/__tests__/Form-test.tsx

index 89c4fc9ba209d7b147fec96d7bee49b0ed042b47..c6d4e5ee4c3a21ceecbe57ea7f506e226637a55c 100644 (file)
@@ -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>
index 1e828bc139ead35bab2bdc7b1261578720a80bd7..c3ed88230667a193383b73e9b972c8fa6230598b 100644 (file)
@@ -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');
+  }
+});