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

feat(core): add data-testid to components #536

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

LiliumCandidum
Copy link
Contributor

Description

This PR aims to add the dataTestId prop to almost every component.
I didn't add the prop to the components that I thought it was not necessary but it can be discussed and I'm not quite sure about the Icon component.

The components with the new prop are:

  • Button
  • Breadcrumb
  • Drawer
  • Menu
  • SegmentedControl
  • Modal
  • Table
  • FeedbackMessage

The components without the prop are:

  • Divider
  • Icon
  • ThemeProvider
  • Typography

Addressed issue

Closes #372

Checklist

  • commit message and branch name follow conventions
  • tests are included
  • changes are accessible and documented from components stories
  • typings are updated or integrated accordingly with your changes
  • all added components are exported from index file (if necessary)
  • all added files include Apache 2.0 license
  • you are not committing extraneous files or sensitive data
  • the browser console does not have any logged errors
  • necessary labels have been applied to this pull request (enhancement, bug, ecc.)

@LiliumCandidum LiliumCandidum added the enhancement New feature or request label Jul 12, 2024
@LiliumCandidum LiliumCandidum requested a review from a team as a code owner July 12, 2024 13:42
@LiliumCandidum LiliumCandidum linked an issue Jul 12, 2024 that may be closed by this pull request
@@ -43,6 +44,7 @@ export const Drawer = ({
<AntdDrawer
className={styles.drawer}
closeIcon={closeIcon}
data-testid={dataTestId}
Copy link
Member

@Danielecina Danielecina Jul 12, 2024

Choose a reason for hiding this comment

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

This prop does not exist in antd, so it does not work in theory.
I suggest not using props if they are documented

Copy link
Member

Choose a reason for hiding this comment

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

There are some tests, so if test passes it should work (and we can be notified if antd break this behaviour). We could trust on it?

Copy link
Member

@Danielecina Danielecina Jul 12, 2024

Choose a reason for hiding this comment

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

yes is as you answer, but why risk to do a DS breaking change if Antd change the behaviour?
I suggest to use a custom node or not use for this component the "data-testid" and use the traditional getByX to getting the node inside your test. Traditionally we use "data-testid" in small cases

@@ -149,4 +149,12 @@ describe('Modal Component', () => {

expect(baseElement).toMatchSnapshot()
})

test('should get modal by test id', async() => {
render(<Modal {...props} dataTestId="modal-test" />)
Copy link
Member

@Danielecina Danielecina Jul 12, 2024

Choose a reason for hiding this comment

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

We cannot trust it to go if it is not documented by antd, because it could quietly break compatibility even if it works

Copy link
Member

Choose a reason for hiding this comment

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

Same for every component that use data-testid directly on antd

@@ -82,6 +83,7 @@ export const Menu = ({
>
<AntMenu
className={menuClassNames}
data-testid={dataTestId}
Copy link
Member

Choose a reason for hiding this comment

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

idem here

})

test('should get segment control by test id', () => {
render(<SegmentedControl {...props} dataTestId="segment-control-test" />)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need all of this data-testid.
Is there a specific component that has some problems with testing?

I imagine that most components permit getting them easily with "getByRole" {name}.

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

Successfully merging this pull request may close these issues.

data-testid not available in Design System components
3 participants