Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] simplifying logic for showing extend trial and adjusting tests (#20211) #20216

Merged
merged 1 commit into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RequestTrialExtension component should display when trial license is about to expire 1`] = `"<div class=\\"euiFlexItem\\"><div class=\\"euiCard euiCard--centerAligned\\"><span class=\\"euiCard__content\\"><span class=\\"euiTitle euiTitle--medium euiCard__title\\">Extend your trial</span><div class=\\"euiText euiText--small euiCard__description\\"><p><span>If you’d like to continuing using Security, Machine Learning, and our other awesome <a class=\\"euiLink euiLink--primary\\" href=\\"https://www.elastic.co/subscriptions/xpack\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\">platinum features</a>, request an extension now.</span></p></div></span><span class=\\"euiCard__footer\\"><a class=\\"euiButton euiButton--primary\\" href=\\"https://www.elastic.co/trialextension\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\" data-test-subj=\\"extendTrialButton\\" style=\\"margin-top: auto;\\"><span class=\\"euiButton__content\\"><span class=\\"euiButton__text\\">Extend trial</span></span></a></span></div></div>"`;
exports[`RequestTrialExtension component should display when license is active and trial has been used 1`] = `"<div class=\\"euiFlexItem\\"><div class=\\"euiCard euiCard--centerAligned\\"><span class=\\"euiCard__content\\"><span class=\\"euiTitle euiTitle--medium euiCard__title\\">Extend your trial</span><div class=\\"euiText euiText--small euiCard__description\\"><p><span>If you’d like to continuing using Security, Machine Learning, and our other awesome <a class=\\"euiLink euiLink--primary\\" href=\\"https://www.elastic.co/subscriptions/xpack\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\">platinum features</a>, request an extension now.</span></p></div></span><span class=\\"euiCard__footer\\"><a class=\\"euiButton euiButton--primary\\" href=\\"https://www.elastic.co/trialextension\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\" data-test-subj=\\"extendTrialButton\\" style=\\"margin-top: auto;\\"><span class=\\"euiButton__content\\"><span class=\\"euiButton__text\\">Extend trial</span></span></a></span></div></div>"`;

exports[`RequestTrialExtension component should display when trial license is expired 1`] = `"<div class=\\"euiFlexItem\\"><div class=\\"euiCard euiCard--centerAligned\\"><span class=\\"euiCard__content\\"><span class=\\"euiTitle euiTitle--medium euiCard__title\\">Extend your trial</span><div class=\\"euiText euiText--small euiCard__description\\"><p><span>If you’d like to continuing using Security, Machine Learning, and our other awesome <a class=\\"euiLink euiLink--primary\\" href=\\"https://www.elastic.co/subscriptions/xpack\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\">platinum features</a>, request an extension now.</span></p></div></span><span class=\\"euiCard__footer\\"><a class=\\"euiButton euiButton--primary\\" href=\\"https://www.elastic.co/trialextension\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\" data-test-subj=\\"extendTrialButton\\" style=\\"margin-top: auto;\\"><span class=\\"euiButton__content\\"><span class=\\"euiButton__text\\">Extend trial</span></span></a></span></div></div>"`;
exports[`RequestTrialExtension component should display when license is not active and trial has been used 1`] = `"<div class=\\"euiFlexItem\\"><div class=\\"euiCard euiCard--centerAligned\\"><span class=\\"euiCard__content\\"><span class=\\"euiTitle euiTitle--medium euiCard__title\\">Extend your trial</span><div class=\\"euiText euiText--small euiCard__description\\"><p><span>If you’d like to continuing using Security, Machine Learning, and our other awesome <a class=\\"euiLink euiLink--primary\\" href=\\"https://www.elastic.co/subscriptions/xpack\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\">platinum features</a>, request an extension now.</span></p></div></span><span class=\\"euiCard__footer\\"><a class=\\"euiButton euiButton--primary\\" href=\\"https://www.elastic.co/trialextension\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\" data-test-subj=\\"extendTrialButton\\" style=\\"margin-top: auto;\\"><span class=\\"euiButton__content\\"><span class=\\"euiButton__text\\">Extend trial</span></span></a></span></div></div>"`;

exports[`RequestTrialExtension component should display when platinum license is not active and trial has been used 1`] = `"<div class=\\"euiFlexItem\\"><div class=\\"euiCard euiCard--centerAligned\\"><span class=\\"euiCard__content\\"><span class=\\"euiTitle euiTitle--medium euiCard__title\\">Extend your trial</span><div class=\\"euiText euiText--small euiCard__description\\"><p><span>If you’d like to continuing using Security, Machine Learning, and our other awesome <a class=\\"euiLink euiLink--primary\\" href=\\"https://www.elastic.co/subscriptions/xpack\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\">platinum features</a>, request an extension now.</span></p></div></span><span class=\\"euiCard__footer\\"><a class=\\"euiButton euiButton--primary\\" href=\\"https://www.elastic.co/trialextension\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\" data-test-subj=\\"extendTrialButton\\" style=\\"margin-top: auto;\\"><span class=\\"euiButton__content\\"><span class=\\"euiButton__text\\">Extend trial</span></span></a></span></div></div>"`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,122 +6,87 @@

import { RequestTrialExtension } from '../public/sections/license_dashboard/request_trial_extension';
import { createMockLicense, getComponent } from './util';
const nonImminentExpirationTime = new Date().getTime() + (30 * 24 * 60 * 60 * 1000);
// ten days from now
const imminentExpirationTime = new Date().getTime() + (10 * 24 * 60 * 60 * 1000);

describe('RequestTrialExtension component', () => {
test('should not display when trial expires in > 24 days', () => {
test('should not display when license is active and trial has not been used', () => {
const rendered = getComponent(
{
license: createMockLicense('trial', nonImminentExpirationTime)
trialStatus: {
canStartTrial: true
},
license: createMockLicense('trial')
},
RequestTrialExtension
);
const html = rendered.html();
expect(html).toBeNull();
});
test('should display when trial license is expired', () => {
test('should display when license is active and trial has been used', () => {
const rendered = getComponent(
{
license: createMockLicense('trial', 0)
trialStatus: {
canStartTrial: false
},
license: createMockLicense('trial')
},
RequestTrialExtension
);
const html = rendered.html();
expect(html).not.toBeNull();
expect(html).toMatchSnapshot();
});
test('should display when trial license is about to expire', () => {
test('should not display when license is not active and trial has not been used', () => {
const rendered = getComponent(
{
license: createMockLicense('trial', imminentExpirationTime)
trialStatus: {
canStartTrial: true
},
license: createMockLicense('trial', 0)
},
RequestTrialExtension
);
const html = rendered.html();
expect(html).not.toBeNull();
expect(html).toMatchSnapshot();
});
test('should not display for about to expire basic license', () => {
const rendered = getComponent(
{
license: createMockLicense('basic', imminentExpirationTime)
},
RequestTrialExtension
);
expect(rendered.html()).toBeNull();
});
test('should not display for expired basic license', () => {
const rendered = getComponent(
{
license: createMockLicense('basic', 0)
},
RequestTrialExtension
);
expect(rendered.html()).toBeNull();
});
test('should not display for active basic license', () => {
const rendered = getComponent(
{
license: createMockLicense('basic')
},
RequestTrialExtension
);
expect(rendered.html()).toBeNull();
});
test('should not display for about to expire gold license', () => {
const rendered = getComponent(
{
license: createMockLicense('gold', imminentExpirationTime)
},
RequestTrialExtension
);
expect(rendered.html()).toBeNull();
});
test('should not display for expired gold license', () => {
const rendered = getComponent(
{
license: createMockLicense('gold', 0)
},
RequestTrialExtension
);
expect(rendered.html()).toBeNull();
});
test('should not display for active gold license', () => {
const rendered = getComponent(
{
license: createMockLicense('gold')
},
RequestTrialExtension
);
expect(rendered.html()).toBeNull();
expect(html).toBeNull();
});
test('should not display for about to expire platinum license', () => {
test('should display when license is not active and trial has been used', () => {
const rendered = getComponent(
{
license: createMockLicense('platinum', imminentExpirationTime)
trialStatus: {
canStartTrial: false
},
license: createMockLicense('trial', 0)
},
RequestTrialExtension
);
expect(rendered.html()).toBeNull();
const html = rendered.html();
expect(html).not.toBeNull();
expect(html).toMatchSnapshot();
});
test('should not display for expired platinum license', () => {
test('should display when platinum license is not active and trial has been used', () => {
const rendered = getComponent(
{
trialStatus: {
canStartTrial: false
},
license: createMockLicense('platinum', 0)
},
RequestTrialExtension
);
expect(rendered.html()).toBeNull();
const html = rendered.html();
expect(html).not.toBeNull();
expect(html).toMatchSnapshot();
});
test('should not display for active platinum license', () => {
test('should not display when platinum license is active and trial has been used', () => {
const rendered = getComponent(
{
trialStatus: {
canStartTrial: false
},
license: createMockLicense('platinum')
},
RequestTrialExtension
);
expect(rendered.html()).toBeNull();
const html = rendered.html();
expect(html).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ export const shouldShowRevertToBasicLicense = state => {
return type === 'trial' || isImminentExpiration(state) || isExpired(state);
};

export const shouldShowRequestTrialExtension = state => {
const { type } = getLicense(state);
return type === 'trial' && (isImminentExpiration(state) || isExpired(state));
};

export const uploadNeedsAcknowledgement = state => {
return !!state.uploadStatus.acknowledge;
};
Expand Down Expand Up @@ -105,6 +100,15 @@ export const shouldShowStartTrial = state => {
(licenseType !== 'platinum' || isExpired(state))
);
};

export const shouldShowRequestTrialExtension = state => {
if (state.trialStatus.canStartTrial) {
return false;
}
const { type } = getLicense(state);
return type !== 'platinum' || isExpired(state);
};

export const startTrialError = state => {
return state.trialStatus.startTrialError;
};
Expand Down