};
render() {
+ const domains = [...this.props.domains];
+ if (this.state.domain) {
+ domains.push(this.state.domain);
+ }
+
return (
<SimpleModal
header={this.props.header}
<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>
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');
+ }
+});