Skip to content

test(storybook): ActionIcon click DEV-98 #5669

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

Merged
merged 9 commits into from
Apr 14, 2025

Conversation

magicznyleszek
Copy link
Member

@magicznyleszek magicznyleszek commented Apr 14, 2025

🗒️ Checklist

  1. run linter locally
  2. update all related docs (API, README, inline, etc.), if any
  3. draft PR with a title <type>(<scope>)<!>: <title> TASK-1234
  4. tag PR: at least frontend or backend unless it's global
  5. fill in the template below and delete template comments
  6. review thyself: read the diff and repro the preview as written
  7. open PR & confirm that CI passes
  8. request reviewers, if needed
  9. delete this section before merging

💭 Notes

I was trying to come up with some "proper" way of having types in args, but searching Storybook docs and thier GH gave me nothing useful. I made an issue to kindly point this out to Storybook team: storybookjs/storybook#31106.

Other than that, it's just a simple test to show how it's done ;)

👀 Preview steps

Testing:

  1. ℹ️ run storybook
  2. go to Design System → ActionIcon → Test Click story
  3. open "Interactions" tab
  4. 🟢 notice that test PASS

@magicznyleszek magicznyleszek requested a review from Copilot April 14, 2025 11:17
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

jsapp/js/components/common/actionIcon.stories.tsx:97

  • [nitpick] For a more robust test, consider asserting the exact number of times the onClick handler is expected to be called (e.g., using toHaveBeenCalledTimes(1)) rather than simply checking if it was called.
await expect((args as StoryArgs).onClick).toHaveBeenCalled()

@magicznyleszek magicznyleszek changed the title test(ActionIcon): storybook test DEV-98 test(storybook): ActionIcon test DEV-98 Apr 14, 2025
@magicznyleszek magicznyleszek changed the title test(storybook): ActionIcon test DEV-98 test(storybook): ActionIcon click DEV-98 Apr 14, 2025
@magicznyleszek magicznyleszek self-assigned this Apr 14, 2025
@magicznyleszek magicznyleszek marked this pull request as ready for review April 14, 2025 11:31
@magicznyleszek magicznyleszek requested a review from Akuukis April 14, 2025 11:34
magicznyleszek and others added 3 commits April 14, 2025 13:40
Co-authored-by: Akuukis <Akuukis@users.noreply.github.com>
Co-authored-by: Akuukis <Akuukis@users.noreply.github.com>
@magicznyleszek magicznyleszek requested a review from Copilot April 14, 2025 12:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

jsapp/js/components/common/actionIcon.stories.tsx:90

  • [nitpick] Consider using 'data-testid' instead of 'id' for test elements to align with the StoryArgs type and common testing conventions.
id: 'ActionIcon-click-test',

@magicznyleszek magicznyleszek requested a review from Copilot April 14, 2025 13:04
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

jsapp/js/components/common/actionIcon.stories.tsx:99

  • [nitpick] Consider refining the Story type definitions to avoid the need for casting args. This can help maintain strong type safety throughout your tests.
await expect((args as StoryArgs).onClick).toHaveBeenCalledTimes(1)

jsapp/js/components/common/ActionIcon.tsx:22

  • [nitpick] Setting displayName on the component before wrapping it with createPolymorphicComponent may not propagate as expected. Verify that the intended displayName appears correctly in React DevTools.
ActionIcon.displayName = 'ActionIcon'

Copy link
Contributor

@Akuukis Akuukis left a comment

Choose a reason for hiding this comment

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

LGTM, tested, one nitpick

// TODO: I made an issue to point this out to Storybook team: https://github.com/storybookjs/storybook/issues/31106
// let's fix this when they fix it.
const canvas = within(canvasElement)
await userEvent.click(canvas.getByTestId(testId))
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks more scalable to me in case of more than single test case.

Suggested change
await userEvent.click(canvas.getByTestId(testId))
await userEvent.click(canvas.getByTestId((args as StoryArgs)['data-testid']!))

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure :)

@magicznyleszek magicznyleszek merged commit 23e3619 into main Apr 14, 2025
5 checks passed
@magicznyleszek magicznyleszek deleted the leszek/dev-98-poc-storybook-test branch April 14, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants