Skip to content

Commit d8c7970

Browse files
authored
simplifying logic for showing extend trial and adjusting tests (#20211)
* simplifying logic for showing extend trial and adjusting tests * PR feedback
1 parent 1803798 commit d8c7970

File tree

3 files changed

+50
-79
lines changed

3 files changed

+50
-79
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
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>"`;
3+
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>"`;
44

5-
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>"`;
5+
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>"`;
6+
7+
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>"`;

x-pack/plugins/license_management/__jest__/request_trial_extension.test.js

Lines changed: 37 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,122 +6,87 @@
66

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

1310
describe('RequestTrialExtension component', () => {
14-
test('should not display when trial expires in > 24 days', () => {
11+
test('should not display when license is active and trial has not been used', () => {
1512
const rendered = getComponent(
1613
{
17-
license: createMockLicense('trial', nonImminentExpirationTime)
14+
trialStatus: {
15+
canStartTrial: true
16+
},
17+
license: createMockLicense('trial')
1818
},
1919
RequestTrialExtension
2020
);
2121
const html = rendered.html();
2222
expect(html).toBeNull();
2323
});
24-
test('should display when trial license is expired', () => {
24+
test('should display when license is active and trial has been used', () => {
2525
const rendered = getComponent(
2626
{
27-
license: createMockLicense('trial', 0)
27+
trialStatus: {
28+
canStartTrial: false
29+
},
30+
license: createMockLicense('trial')
2831
},
2932
RequestTrialExtension
3033
);
3134
const html = rendered.html();
3235
expect(html).not.toBeNull();
3336
expect(html).toMatchSnapshot();
3437
});
35-
test('should display when trial license is about to expire', () => {
38+
test('should not display when license is not active and trial has not been used', () => {
3639
const rendered = getComponent(
3740
{
38-
license: createMockLicense('trial', imminentExpirationTime)
41+
trialStatus: {
42+
canStartTrial: true
43+
},
44+
license: createMockLicense('trial', 0)
3945
},
4046
RequestTrialExtension
4147
);
4248
const html = rendered.html();
43-
expect(html).not.toBeNull();
44-
expect(html).toMatchSnapshot();
45-
});
46-
test('should not display for about to expire basic license', () => {
47-
const rendered = getComponent(
48-
{
49-
license: createMockLicense('basic', imminentExpirationTime)
50-
},
51-
RequestTrialExtension
52-
);
53-
expect(rendered.html()).toBeNull();
54-
});
55-
test('should not display for expired basic license', () => {
56-
const rendered = getComponent(
57-
{
58-
license: createMockLicense('basic', 0)
59-
},
60-
RequestTrialExtension
61-
);
62-
expect(rendered.html()).toBeNull();
63-
});
64-
test('should not display for active basic license', () => {
65-
const rendered = getComponent(
66-
{
67-
license: createMockLicense('basic')
68-
},
69-
RequestTrialExtension
70-
);
71-
expect(rendered.html()).toBeNull();
72-
});
73-
test('should not display for about to expire gold license', () => {
74-
const rendered = getComponent(
75-
{
76-
license: createMockLicense('gold', imminentExpirationTime)
77-
},
78-
RequestTrialExtension
79-
);
80-
expect(rendered.html()).toBeNull();
81-
});
82-
test('should not display for expired gold license', () => {
83-
const rendered = getComponent(
84-
{
85-
license: createMockLicense('gold', 0)
86-
},
87-
RequestTrialExtension
88-
);
89-
expect(rendered.html()).toBeNull();
90-
});
91-
test('should not display for active gold license', () => {
92-
const rendered = getComponent(
93-
{
94-
license: createMockLicense('gold')
95-
},
96-
RequestTrialExtension
97-
);
98-
expect(rendered.html()).toBeNull();
49+
expect(html).toBeNull();
9950
});
100-
test('should not display for about to expire platinum license', () => {
51+
test('should display when license is not active and trial has been used', () => {
10152
const rendered = getComponent(
10253
{
103-
license: createMockLicense('platinum', imminentExpirationTime)
54+
trialStatus: {
55+
canStartTrial: false
56+
},
57+
license: createMockLicense('trial', 0)
10458
},
10559
RequestTrialExtension
10660
);
107-
expect(rendered.html()).toBeNull();
61+
const html = rendered.html();
62+
expect(html).not.toBeNull();
63+
expect(html).toMatchSnapshot();
10864
});
109-
test('should not display for expired platinum license', () => {
65+
test('should display when platinum license is not active and trial has been used', () => {
11066
const rendered = getComponent(
11167
{
68+
trialStatus: {
69+
canStartTrial: false
70+
},
11271
license: createMockLicense('platinum', 0)
11372
},
11473
RequestTrialExtension
11574
);
116-
expect(rendered.html()).toBeNull();
75+
const html = rendered.html();
76+
expect(html).not.toBeNull();
77+
expect(html).toMatchSnapshot();
11778
});
118-
test('should not display for active platinum license', () => {
79+
test('should not display when platinum license is active and trial has been used', () => {
11980
const rendered = getComponent(
12081
{
82+
trialStatus: {
83+
canStartTrial: false
84+
},
12185
license: createMockLicense('platinum')
12286
},
12387
RequestTrialExtension
12488
);
125-
expect(rendered.html()).toBeNull();
89+
const html = rendered.html();
90+
expect(html).toBeNull();
12691
});
12792
});

x-pack/plugins/license_management/public/store/reducers/licenseManagement.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ export const shouldShowRevertToBasicLicense = state => {
7171
return type === 'trial' || isImminentExpiration(state) || isExpired(state);
7272
};
7373

74-
export const shouldShowRequestTrialExtension = state => {
75-
const { type } = getLicense(state);
76-
return type === 'trial' && (isImminentExpiration(state) || isExpired(state));
77-
};
78-
7974
export const uploadNeedsAcknowledgement = state => {
8075
return !!state.uploadStatus.acknowledge;
8176
};
@@ -105,6 +100,15 @@ export const shouldShowStartTrial = state => {
105100
(licenseType !== 'platinum' || isExpired(state))
106101
);
107102
};
103+
104+
export const shouldShowRequestTrialExtension = state => {
105+
if (state.trialStatus.canStartTrial) {
106+
return false;
107+
}
108+
const { type } = getLicense(state);
109+
return type !== 'platinum' || isExpired(state);
110+
};
111+
108112
export const startTrialError = state => {
109113
return state.trialStatus.startTrialError;
110114
};

0 commit comments

Comments
 (0)