-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
simplifying logic for showing extend trial and adjusting tests #20211
simplifying logic for showing extend trial and adjusting tests #20211
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few suggestions. If we can address my feedback about the snapshots then I think I would be able to verify the logic we're testing more easily.
|
||
export const shouldShowRequestTrialExtension = state => { | ||
const { type } = getLicense(state); | ||
return (type !== 'platinum' || isExpired(state)) && !state.trialStatus.canStartTrial; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use early exiting here to untangle these conditions?
export const shouldShowRequestTrialExtension = state => {
if (state.trialStatus.canStartTrial) {
return false;
}
const { type } = getLicense(state);
return type !== 'platinum' || isExpired(state);
}
}); | ||
test('should not display for expired platinum license', () => { | ||
test('should display when platinum license is expired and trial has been used', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rephrase this to "is not active" to keep the terminology consistent?
}); | ||
test('should not display for active platinum license', () => { | ||
test('should not display when platinum license is not expired and trial has been used', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise can we change this to "is active"?
|
||
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>"`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These snapshot are tough to compare against one another and to see the changes in a diff because they're on one line each. Can we either a) switch to using Enzyme to generate the snapshot or b) use data-test-subj
selectors to assert the presence of this component? I'm strongly in favor of the latter if we don't expect the UI to meaningfully change from snapshot to snapshot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using enzyme to generate the snapshot. I'm using .html to strip out a lot of junk from the snapshot and that is what is squashing down to a single line.
Someone opened an issue about this but it got closed: enzymejs/enzyme#649
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this seems like something outside of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. BTW there's a helper in EUI which you can use to create a snapshot from a mounted component (example, corresponding snapshot). The snapshot will have whitespace preserved.
@@ -105,6 +100,12 @@ export const shouldShowStartTrial = state => { | |||
(licenseType !== 'platinum' || isExpired(state)) | |||
); | |||
}; | |||
|
|||
export const shouldShowRequestTrialExtension = state => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably outside the scope of this PR, but I was having a hard time tracing the relationships between these functions and seeing what kind of data they're interested in because they all accept a state
object. I think we could make this code more transparent by changing them to accept more granular arguments, e.g. license
, licenseType
, uploadStatus
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are all selectors and thus operate on entire state object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, though I still think there's plenty of room for improving the readability of this code while preserving its identify as a collection of selectors. For example, getExpirationDate
and isImminentExpiration
are only used internally, so they don't need to be coupled to the state
object:
export const getExpirationDate = license => {
const { type, expiryDateInMillis } = license;
//basic licenses do not expire
if (type === 'basic') {
return null;
}
if (expirationMillis) {
return moment.tz(expirationMillis, moment.tz.guess());
} else {
return null;
}
};
export const isImminentExpiration = license => {
const now = new Date();
const expirationDate = getExpirationDate(license);
return (
expirationDate &&
expirationDate.isAfter(now) &&
expirationDate.diff(now, 'days') <= WARNING_THRESHOLD_IN_DAYS
);
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeScript will also help a lot here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the same effect could be achieved with decomposition in those methods:
export const isImminentExpiration = ({ license }) => {
...
At any rate, this is all beyond the scope of this simple logic shift PR I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
💚 Build Succeeded |
💚 Build Succeeded |
…ic#20211) * simplifying logic for showing extend trial and adjusting tests * PR feedback
… (#20216) * simplifying logic for showing extend trial and adjusting tests * PR feedback
* simplifying logic for showing extend trial and adjusting tests * PR feedback
Closes #19741
This change modifies the logic for showing the extend trial pane in license management to the following:
License is not platinum or is expired AND trial has already been used.