import { stringify } from 'querystring';
import * as React from 'react';
import * as classNames from 'classnames';
-import Checkbox from '../../../components/controls/Checkbox';
import { FormattedMessage } from 'react-intl';
import { debounce } from 'lodash';
++import Checkbox from '../../../components/controls/Checkbox';
import DeferredSpinner from '../../../components/common/DeferredSpinner';
import { omitNil } from '../../../helpers/request';
import { Edition, getFormData, getLicensePreview } from '../../../api/marketplace';
const { licenseEdition, previewStatus } = this.state;
if (!previewStatus) {
const { edition } = this.props;
- if (edition && licenseEdition && edition.key !== licenseEdition.key) {
- return (
- <p className="alert alert-danger spacer-top">
- {translateWithParameters('marketplace.wrong_license_type_x', edition.name)}
- </p>
- );
+ if (!edition) {
+ return undefined;
}
- return undefined;
+ return (
+ <div className="spacer-top">
+ {licenseEdition !== undefined &&
- edition.key !== licenseEdition.key && (
- <p className="alert alert-danger">
- {translateWithParameters('marketplace.wrong_license_type_x', edition.name)}
- </p>
- )}
++ edition.key !== licenseEdition.key && (
++ <p className="alert alert-danger">
++ {translateWithParameters('marketplace.wrong_license_type_x', edition.name)}
++ </p>
++ )}
+ <a href={this.getLicenseFormUrl(edition)} target="_blank">
+ {translate('marketplace.i_need_a_license')}
+ </a>
+ </div>
+ );
}
return (
- <p
- className={classNames('alert spacer-top', {
- 'alert-warning': previewStatus === 'AUTOMATIC_INSTALL',
- 'alert-success': previewStatus === 'NO_INSTALL',
- 'alert-danger': previewStatus === 'MANUAL_INSTALL'
- })}>
- {translateWithParameters(
- 'marketplace.license_preview_status.' + previewStatus,
- licenseEdition ? licenseEdition.name : translate('marketplace.commercial_edition')
- )}
- {licenseEdition &&
- licenseEdition.key === 'datacenter' &&
- previewStatus !== 'NO_INSTALL' && (
- <span className="little-spacer-left">
- <FormattedMessage
- defaultMessage={translate('marketplace.how_to_setup_cluster_url')}
- id="marketplace.how_to_setup_cluster_url"
- values={{
- url: (
- <a
- href="https://redirect.sonarsource.com/doc/data-center-edition.html"
- target="_blank">
- {licenseEdition.name}
- </a>
- )
- }}
- />
- </span>
+ <div className="spacer-top">
+ <p
+ className={classNames('alert', {
+ 'alert-warning': previewStatus === 'AUTOMATIC_INSTALL',
+ 'alert-success': previewStatus === 'NO_INSTALL',
+ 'alert-danger': previewStatus === 'MANUAL_INSTALL'
+ })}>
+ {translateWithParameters(
+ 'marketplace.license_preview_status.' + previewStatus,
+ licenseEdition ? licenseEdition.name : translate('marketplace.commercial_edition')
)}
- </p>
+ {licenseEdition &&
- licenseEdition.key === 'datacenter' &&
- previewStatus !== 'NO_INSTALL' && (
- <span className="little-spacer-left">
- <FormattedMessage
- defaultMessage={translate('marketplace.how_to_setup_cluster_url')}
- id="marketplace.how_to_setup_cluster_url"
- values={{
- url: (
- <a
- href="https://redirect.sonarsource.com/doc/data-center-edition.html"
- target="_blank">
- {licenseEdition.name}
- </a>
- )
- }}
- />
- </span>
- )}
++ licenseEdition.key === 'datacenter' &&
++ previewStatus !== 'NO_INSTALL' && (
++ <span className="little-spacer-left">
++ <FormattedMessage
++ defaultMessage={translate('marketplace.how_to_setup_cluster_url')}
++ id="marketplace.how_to_setup_cluster_url"
++ values={{
++ url: (
++ <a
++ href="https://redirect.sonarsource.com/doc/data-center-edition.html"
++ target="_blank">
++ {licenseEdition.name}
++ </a>
++ )
++ }}
++ />
++ </span>
++ )}
+ </p>
+ {previewStatus !== 'NO_INSTALL' && (
+ <span className="js-edition-tos">
+ <Checkbox
+ checked={this.state.acceptTerms}
+ id="edition-terms"
+ onCheck={this.handleTermsCheck}>
+ <label className="little-spacer-left" htmlFor="edition-terms">
+ {translate('marketplace.i_accept_the')}
+ </label>
+ </Checkbox>
+ <a
+ className="nowrap little-spacer-left"
+ href="http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf"
+ target="_blank">
+ {translate('marketplace.terms_and_conditions')}
+ </a>
+ </span>
+ )}
+ </div>
);
}
expect(getWrapper()).toMatchSnapshot();
});
+it('should display the get license link with parameters', async () => {
+ const wrapper = getWrapper();
+ await new Promise(setImmediate);
+ wrapper.update();
+ expect(wrapper.find('a')).toMatchSnapshot();
+});
+
it('should correctly display status message after checking license', async () => {
- await testLicenseStatus('NO_INSTALL');
- await testLicenseStatus('AUTOMATIC_INSTALL');
- await testLicenseStatus('MANUAL_INSTALL');
+ let wrapper = await testLicenseStatus('NO_INSTALL', jest.fn());
+ expect(wrapper.find('p.alert')).toMatchSnapshot();
+ wrapper = await testLicenseStatus('AUTOMATIC_INSTALL', jest.fn());
+ expect(wrapper.find('p.alert')).toMatchSnapshot();
+ wrapper = await testLicenseStatus('MANUAL_INSTALL', jest.fn());
+ expect(wrapper.find('p.alert')).toMatchSnapshot();
+ });
+
+ it('should display terms of license checkbox', async () => {
+ let updateLicense = jest.fn();
+ let wrapper = await testLicenseStatus('NO_INSTALL', updateLicense);
+ expect(wrapper.find('.js-edition-tos').exists()).toBeFalsy();
+ expect(updateLicense).toHaveBeenCalledWith('mylicense', 'NO_INSTALL');
+
+ updateLicense = jest.fn();
+ wrapper = await testLicenseStatus('AUTOMATIC_INSTALL', updateLicense);
- let tosCheckbox = wrapper.find('.js-edition-tos');
++ const tosCheckbox = wrapper.find('.js-edition-tos');
+ expect(tosCheckbox.find('a').exists()).toBeTruthy();
+ expect(updateLicense).toHaveBeenLastCalledWith(undefined, 'AUTOMATIC_INSTALL');
+ (tosCheckbox.find('Checkbox').prop('onCheck') as Function)(true);
+ expect(updateLicense).toHaveBeenLastCalledWith('mylicense', 'AUTOMATIC_INSTALL');
+
+ updateLicense = jest.fn();
+ wrapper = await testLicenseStatus('MANUAL_INSTALL', updateLicense);
+ expect(wrapper.find('.js-edition-tos').exists()).toBeTruthy();
+ expect(updateLicense).toHaveBeenLastCalledWith(undefined, 'MANUAL_INSTALL');
});
function getWrapper(props = {}) {
getLicensePreview.mockImplementation(() =>
Promise.resolve({ nextEditionKey: 'foo', previewStatus: status })
);
- const updateLicense = jest.fn();
const wrapper = getWrapper({ updateLicense });
- (wrapper.instance() as LicenseEditionSet).mounted = true;
change(wrapper.find('textarea'), 'mylicense');
expect(getLicensePreview).toHaveBeenCalled();
await new Promise(setImmediate);
expect(updateLicense).toHaveBeenCalled();
- expect(wrapper.find('p.alert')).toMatchSnapshot();
+ wrapper.update();
+ return wrapper;
}