-
Notifications
You must be signed in to change notification settings - Fork 3
Extend activity control widget to include other interactions beside actions and context menu (CMEM-6724) #311
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
71ccfd7
Remove errors in explore (CMEM-6724)
fiorsaoirse 3580f3f
Revert "Remove errors in explore (CMEM-6724)"
fiorsaoirse 9e7f048
Added additional actions to ActivityControlWidget
fiorsaoirse d2f7033
Added a story, added tests
fiorsaoirse 86ea778
Check data-test-id before usage
fiorsaoirse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/cmem/ActivityControl/tests/ActivityControlWidget.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import React from "react"; | ||
|
haschek marked this conversation as resolved.
|
||
| import { fireEvent, render, screen } from "@testing-library/react"; | ||
|
|
||
| import "@testing-library/jest-dom"; | ||
|
|
||
| import { IconButton, Tag, TagList } from "../../../index"; | ||
| import { ActivityControlWidget, ActivityControlWidgetAction } from "../ActivityControlWidget"; | ||
|
|
||
| describe("ActivityControlWidget", () => { | ||
| it("Renders basic widget with actions and handles clicks", () => { | ||
| const mockAction1 = jest.fn(); | ||
| const mockAction2 = jest.fn(); | ||
| const actions: ActivityControlWidgetAction[] = [ | ||
| { | ||
| "data-testid": "action-1", | ||
| icon: "item-reload", | ||
| action: mockAction1, | ||
| tooltip: "Action 1", | ||
| }, | ||
| { | ||
| "data-testid": "action-2", | ||
| icon: "item-start", | ||
| action: mockAction2, | ||
| tooltip: "Action 2", | ||
| }, | ||
| ]; | ||
|
|
||
| render( | ||
| <ActivityControlWidget | ||
| label="Basic widget" | ||
| data-testid="basic-widget" | ||
| activityActions={actions} | ||
| statusMessage="Status message" | ||
| /> | ||
| ); | ||
|
|
||
| const button1 = screen.getByTestId("action-1"); | ||
| const button2 = screen.getByTestId("action-2"); | ||
|
|
||
| const label = screen.getByTestId("basic-widget-label"); | ||
| const statusMessage = screen.getByTestId("basic-widget-status-message"); | ||
| const actionsContainer = screen.getByTestId("basic-widget-actions"); | ||
|
|
||
| expect(label).toBeInTheDocument(); | ||
| expect(statusMessage).toBeInTheDocument(); | ||
| expect(actionsContainer).toBeInTheDocument(); | ||
|
|
||
| expect(label).toHaveTextContent("Basic widget"); | ||
| expect(statusMessage).toHaveTextContent("Status message"); | ||
|
|
||
| expect(button1).toBeInTheDocument(); | ||
| expect(button2).toBeInTheDocument(); | ||
|
|
||
| fireEvent.click(button1); | ||
| expect(mockAction1).toHaveBeenCalledTimes(1); | ||
|
|
||
| fireEvent.click(button2); | ||
| expect(mockAction2).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("Renders widget with tags", () => { | ||
| const tags = ( | ||
| <TagList> | ||
| <Tag>Tag one</Tag> | ||
| <Tag>Other tag</Tag> | ||
| </TagList> | ||
| ); | ||
| render(<ActivityControlWidget label="Widget with tags" tags={tags} data-testid="widget-with-tags" />); | ||
|
|
||
| const label = screen.getByTestId("widget-with-tags-label"); | ||
| const statusMessage = screen.getByTestId("widget-with-tags-status-message"); | ||
|
|
||
| expect(label).toBeInTheDocument(); | ||
| expect(statusMessage).toBeInTheDocument(); | ||
|
|
||
| expect(label).toHaveTextContent("Widget with tags"); | ||
| expect(statusMessage).toHaveTextContent("Tag one"); | ||
| expect(statusMessage).toHaveTextContent("Other tag"); | ||
| }); | ||
|
|
||
| it("Renders widget with additional actions and handles click", () => { | ||
| const mockAction = jest.fn(); | ||
| const additionalActions = [ | ||
| <IconButton | ||
| key="add-btn" | ||
| name="application-explore" | ||
| onClick={mockAction} | ||
| data-testid="additional-action" | ||
| />, | ||
| ]; | ||
| render(<ActivityControlWidget additionalActions={additionalActions} />); | ||
|
|
||
| const customButton = screen.getByTestId("additional-action"); | ||
| expect(customButton).toBeInTheDocument(); | ||
|
|
||
| fireEvent.click(customButton); | ||
| expect(mockAction).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.