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

Added data-test-subj to EuiFormControlLayout component in super_date_picker file #5085

Merged
merged 9 commits into from
Aug 31, 2021

Conversation

Vivek-Kamboj
Copy link
Contributor

@Vivek-Kamboj Vivek-Kamboj commented Aug 25, 2021

Closes #5040

Updates EuiSuperDatePicker to pass a data-test-subj prop.

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

  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

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?

@@ -549,6 +549,7 @@ export class EuiSuperDatePicker extends Component<
className="euiSuperDatePicker"
isDisabled={isDisabled}
prepend={quickSelect}
data-test-subj="superDatePickerRange"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion usually this is just a string like:

Suggested change
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@cee-chen cee-chen Aug 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @constancecchen,
I have made changes as per review comments.

Please review.

Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there isn't specific reason to use render() here instead of just shallow(), I'd suggest using shallow for simplicity/performance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read about shallow() rendering, learned a new way to render. Thank you for sharing @constancecchen

const component = render(
<EuiSuperDatePicker
onTimeChange={noop}
dataTestSubj={dataTestSubj}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplicity I would suggest just passing it a raw string (like an end-user would) rather than defining a const up above

Suggested change
dataTestSubj={dataTestSubj}
dataTestSubj="mySuperDatePicker"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I made the changes, please review.

Comment on lines 126 to 128
/**
* Props passed to tag element for testing
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
/**
* Props passed to tag element for testing
*/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the variable name is self-explanatory.
I removed this comment.

@@ -549,6 +556,7 @@ export class EuiSuperDatePicker extends Component<
className="euiSuperDatePicker"
isDisabled={isDisabled}
prepend={quickSelect}
data-test-subj={dataTestSubj}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 I like this choice for the data-test-subj location (the same wrapper as .euiSuperDatePicker) over the parent flex-group a lot. Nice work!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@@ -476,7 +481,8 @@ export class EuiSuperDatePicker extends Component<
};

renderUpdateButton = () => {
if (!this.props.showUpdateButton || this.props.isAutoRefreshOnly) {
const { showUpdateButton, isAutoRefreshOnly, isLoading, isDisabled, updateButtonProps } = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 Nice, I like the destructuring refactor here!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@cee-chen
Copy link
Contributor

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 CHANGELOG.md with a 1-sentence summary of the changes? Something like

Updated `EuiSuperDatePicker` to pass a `data-test-subj` prop

would be fine!

@Vivek-Kamboj
Copy link
Contributor Author

Update CHANGELOG.md as per review comment.

CHANGELOG.md Outdated Show resolved Hide resolved
@cee-chen
Copy link
Contributor

jenkins test this

@cee-chen cee-chen requested a review from cchaos August 30, 2021 19:45
@cee-chen
Copy link
Contributor

@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 cchaos changed the title Issue-#5040 || Added data-test-subj to EuiFormControlLayout component in super_date_picker file Added data-test-subj to EuiFormControlLayout component in super_date_picker file Aug 30, 2021
Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -134,4 +134,14 @@ describe('EuiSuperDatePicker', () => {
);
expect(component.find(EuiButton).props()).toMatchObject(updateButtonProps);
});

test('EuiFormControlLayout contain data-test-subj as prop', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test('EuiFormControlLayout contain data-test-subj as prop', () => {
test('accepts data-test-subj and passes to EuiFormControlLayout', () => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the test description and updated the snapshot.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5085/

@cchaos
Copy link
Contributor

cchaos commented Aug 30, 2021

Looks like there's a linter/prettier issue as well that needs fixing:

15:52:18 /app/src/components/date_picker/super_date_picker/super_date_picker.tsx
15:52:18   481:12  error  Replace `·showUpdateButton,·isAutoRefreshOnly,·isLoading,·isDisabled,·updateButtonProps` with `⏎······showUpdateButton,⏎······isAutoRefreshOnly,⏎······isLoading,⏎······isDisabled,⏎······updateButtonProps,⏎···`  prettier/prettier
15:52:18   518:19  error  Insert `,`                                                                                                                                                                                                         prettier/prettier
15:52:18 
15:52:18 ✖ 2 problems (2 errors, 0 warnings)
15:52:18   2 errors and 0 warnings potentially fixable with the `--fix` option.

@Vivek-Kamboj
Copy link
Contributor Author

I have fixed the prettier issues. Please review.

@cchaos
Copy link
Contributor

cchaos commented Aug 31, 2021

Jenkins, test this

@cchaos cchaos enabled auto-merge (squash) August 31, 2021 13:43
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5085/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[EuiSuperDatePicker] data-test-subj doesn't show up as an attribute in rendered DOM
4 participants