Added data-test-subj to EuiFormControlLayout component in super_date_picker file#5085
Added data-test-subj to EuiFormControlLayout component in super_date_picker file#5085cchaos merged 9 commits intoelastic:masterfrom
Conversation
|
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
| className="euiSuperDatePicker" | ||
| isDisabled={isDisabled} | ||
| prepend={quickSelect} | ||
| data-test-subj="superDatePickerRange" |
There was a problem hiding this comment.
Hi @Vivek-Kamboj. Thanks for this addition, but it actually needs to be customizable by the user. We'll need to pass through data-test-subj as a prop on the component.
Then you can also follow these testing guidelines to add a test for this specific prop as part of the PR checklist.
There was a problem hiding this comment.
@cchaos, I have customized the data-test-subj and added a test case for that.
Please review.
| /** | ||
| * Props passed to tag element for testing | ||
| */ | ||
| dataTestSubj?: SuperDatePickerDataTestSubj; |
There was a problem hiding this comment.
Sorry for the confusion usually this is just a string like:
| dataTestSubj?: SuperDatePickerDataTestSubj; | |
| 'data-test-subj'?: string; |
Can you explain your thought process with SuperDatePickerDataTestSubj?
Also, please update the PR summary with your solution and mark the checklist items you were able to perform.
There was a problem hiding this comment.
Hi @cchaos,
In the previous comment, you have said that the data-test-subj should be customizable by the user.
And this key is used 2 more times in the file(i.e., for showDates and applyTime). So I have made an object dataTestSubj with interface SuperDatePickerDataTestSubj (declared in src/components/date_picker/types.ts file.)
Now user can pass dataTestSubj object as a prop, and then it is used for the data-test-subj key at different places.
There was a problem hiding this comment.
I'd push against this new object-based dataTestSubj structure, as it's one that hasn't been used in EUI before and doesn't match our current patterns.
@Vivek-Kamboj - the main data-test-subj prop that gets passed to the top level <EuiSuperDatePicker /> should be customizable and passed as a string. This usually gets passed to the most applicable DOM element (either a top-level wrapping parent, or the most relevant input, if there it's a form component). Sub-components or child elements such as the Show Dates button typically do not get dynamic/custom data-test-subj strings, instead they get static strings (as exists in the current code). If users want to hook into those, what they would do is something like this:
<EuiSuperDatePicker data-test-subj="mySuperDatePicker" />
cy
.find('[data-test-subj="mySuperDatePicker"]')
.find(['data-test-subj="superDatePickerShowDatesButton"]')
.click();Hope that makes sense and sheds more light into the implementation we're looking for!
There was a problem hiding this comment.
Hello @constancecchen,
I have made changes as per review comments.
Please review.
cee-chen
left a comment
There was a problem hiding this comment.
I have a couple small change requests around tests and docs - once those are addressed, this LGTM. Thanks @Vivek-Kamboj!
| test('EuiFormControlLayout contain data-test-subj as prop', () => { | ||
| const dataTestSubj: EuiSuperDatePickerProps['dataTestSubj'] = "mySuperDatePicker"; | ||
|
|
||
| const component = render( |
There was a problem hiding this comment.
If there isn't specific reason to use render() here instead of just shallow(), I'd suggest using shallow for simplicity/performance
There was a problem hiding this comment.
I read about shallow() rendering, learned a new way to render. Thank you for sharing @constancecchen
| const component = render( | ||
| <EuiSuperDatePicker | ||
| onTimeChange={noop} | ||
| dataTestSubj={dataTestSubj} |
There was a problem hiding this comment.
For simplicity I would suggest just passing it a raw string (like an end-user would) rather than defining a const up above
| dataTestSubj={dataTestSubj} | |
| dataTestSubj="mySuperDatePicker" |
There was a problem hiding this comment.
Okay, I made the changes, please review.
| /** | ||
| * Props passed to tag element for testing | ||
| */ |
There was a problem hiding this comment.
I'm looking at our current documentation site and the data-test-subj prop, and it looks like we don't include a specific explanation/comment for the prop across any other components. I think we can probably lose this as well here:
| /** | |
| * Props passed to tag element for testing | |
| */ |
There was a problem hiding this comment.
Yes, the variable name is self-explanatory.
I removed this comment.
| className="euiSuperDatePicker" | ||
| isDisabled={isDisabled} | ||
| prepend={quickSelect} | ||
| data-test-subj={dataTestSubj} |
There was a problem hiding this comment.
💯 I like this choice for the data-test-subj location (the same wrapper as .euiSuperDatePicker) over the parent flex-group a lot. Nice work!
|
|
||
| renderUpdateButton = () => { | ||
| if (!this.props.showUpdateButton || this.props.isAutoRefreshOnly) { | ||
| const { showUpdateButton, isAutoRefreshOnly, isLoading, isDisabled, updateButtonProps } = this.props; |
There was a problem hiding this comment.
💯 Nice, I like the destructuring refactor here!
cee-chen
left a comment
There was a problem hiding this comment.
Changes look great - thanks a million @Vivek-Kamboj!
@cchaos do we normally push up CHANGELOG.md entries on behalf of community PRs? If so, I can do that here and merge
|
Just heard back from Caroline, it sounds like we encourage contributors to write their own changelog if they're comfortable - @Vivek-Kamboj do you mind updating your PR description and adding an entry to would be fine! |
|
Update |
|
jenkins test this |
|
@cchaos This LGTM! Do you mind re-reviewing to lose the change requested PR status? Or can we merge in (after CI) despite that? |
cchaos
left a comment
There was a problem hiding this comment.
LGTM, thanks for the changes. I just had one more small change to the test itself so that it reads more like a sentence in the snapshot. You'll need to re-update the snapshot too.
| expect(component.find(EuiButton).props()).toMatchObject(updateButtonProps); | ||
| }); | ||
|
|
||
| test('EuiFormControlLayout contain data-test-subj as prop', () => { |
There was a problem hiding this comment.
| test('EuiFormControlLayout contain data-test-subj as prop', () => { | |
| test('accepts data-test-subj and passes to EuiFormControlLayout', () => { |
There was a problem hiding this comment.
I have changed the test description and updated the snapshot.
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5085/ |
|
Looks like there's a linter/prettier issue as well that needs fixing: |
|
I have fixed the prettier issues. Please review. |
|
Jenkins, test this |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5085/ |
Closes #5040
Updates
EuiSuperDatePickerto pass adata-test-subjprop.Checklist
- [ ] Check against all themes for compatibility in both light and dark modes- [ ] Checked in mobile- [ ] Checked in Chrome, Safari, Edge, and Firefox- [ ] Props have proper autodocs and playground toggles- [ ] Added documentation- [ ] Checked Code Sandbox works for the any docs examples- [ ] Checked for breaking changes and labeled appropriately- [ ] Checked for accessibility including keyboard-only and screenreader modes