-
Notifications
You must be signed in to change notification settings - Fork 292
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
Fix clickable tests (add interaction tests for focus and few behaviour tests) #609
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b11d21f
fix dark mode issue and add categories story
afb8d9a
Merge branch 'master' of github.com:mondaycom/monday-ui-react-core
784893f
fix clickable tests and add interactions tests
a51fb96
fix
a5fce5a
fix tests
1fbf4c7
fix tests
e4e67a3
Merge branch 'master' of github.com:mondaycom/monday-ui-react-core in…
f0ea3b9
fix csslinter
deabb22
fix tests
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 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 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 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
18 changes: 14 additions & 4 deletions
18
src/components/Clickable/__stories__/clickable.stories.scss
This file contains 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 |
---|---|---|
@@ -1,9 +1,19 @@ | ||
@mixin clickable-element { | ||
padding: var(--spacing-small); | ||
border-radius: var(--border-radius-small); | ||
color: var(--primary-text-color); | ||
width: 40%; | ||
} | ||
|
||
.monday-story-clickable { | ||
&_first-element { | ||
padding: var(--spacing-small); | ||
border-radius: var(--border-radius-small); | ||
@include clickable-element; | ||
background-color: var(--primary-selected-color); | ||
color: var(--primary-text-color); | ||
width: 40%; | ||
} | ||
|
||
&_disabled-element { | ||
@include clickable-element; | ||
background-color: var(--disabled-background-color); | ||
|
||
} | ||
} |
This file contains 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
27 changes: 27 additions & 0 deletions
27
src/components/Clickable/__tests__/clickable-interactions-tests.js
This file contains 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,27 @@ | ||
import { expect } from "@storybook/jest"; | ||
import { | ||
getByLabelText, | ||
pressNavigationKey, | ||
interactionSuite, | ||
resetFocus | ||
} from "../../../__tests__/interactions-helper"; | ||
import { NAVIGATIONS_COMMANDS } from "utils/test-utils"; | ||
|
||
async function states_onClickTabFocusElementTest(canvas) { | ||
const CLICKABLE_LABEL = "clickable button"; | ||
const CLICKABLE_DISABLED_LABEL = "disabled clickable button"; | ||
const clickableElement = await getByLabelText(canvas, CLICKABLE_LABEL); | ||
const disabledClickableElement = await getByLabelText(canvas, CLICKABLE_DISABLED_LABEL); | ||
await pressNavigationKey(NAVIGATIONS_COMMANDS.TAB); | ||
expect(document.activeElement).toEqual(clickableElement); | ||
await pressNavigationKey(NAVIGATIONS_COMMANDS.TAB); | ||
expect(document.activeElement).not.toEqual(disabledClickableElement); | ||
expect(canvas).not.toContain(document.activeElement); | ||
} | ||
|
||
export const statesPlaySuite = interactionSuite({ | ||
tests: [states_onClickTabFocusElementTest], | ||
afterEach: async () => { | ||
await resetFocus(); | ||
} | ||
}); |
File renamed without changes.
50 changes: 50 additions & 0 deletions
50
src/components/Clickable/__tests__/clickable-tests.jest.js
This file contains 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,50 @@ | ||
import React from "react"; | ||
import { fireEvent, render, cleanup } from "@testing-library/react"; | ||
import { ELEMENT_TYPES } from "../../../__tests__/interactions-helper"; | ||
import Clickable from "../Clickable"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
const renderComponent = props => { | ||
return render(<Clickable {...props} />); | ||
}; | ||
|
||
describe("Clickable tests", () => { | ||
afterEach(() => { | ||
cleanup(); | ||
}); | ||
|
||
it("should call the onClick callback when clicked", () => { | ||
const onClick = jest.fn(); | ||
const { getByTestId } = renderComponent({ onClick }); | ||
const component = getByTestId(ELEMENT_TYPES.CLICKABLE); | ||
fireEvent.click(component); | ||
expect(onClick.mock.calls.length).toBe(1); | ||
}); | ||
|
||
it("should call the onClick callback when focused and enter pressed", () => { | ||
const onClick = jest.fn(); | ||
const { getByTestId } = renderComponent({ onClick }); | ||
const component = getByTestId(ELEMENT_TYPES.CLICKABLE); | ||
component.focus(); | ||
userEvent.keyboard("{enter}"); | ||
expect(onClick.mock.calls.length).toBe(1); | ||
}); | ||
|
||
it("should call the onClick callback when focused and space pressed", () => { | ||
const onClick = jest.fn(); | ||
const { getByTestId } = renderComponent({ onClick }); | ||
const component = getByTestId(ELEMENT_TYPES.CLICKABLE); | ||
component.focus(); | ||
userEvent.keyboard("{space}"); | ||
expect(onClick.mock.calls.length).toBe(1); | ||
}); | ||
|
||
describe("a11y", () => { | ||
it("should add the label", () => { | ||
const ariaLabel = "Lable Name"; | ||
const { getByLabelText } = renderComponent({ ariaLabel }); | ||
const element = getByLabelText(ariaLabel); | ||
expect(element).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix bug - we allowed focus on disabled clickable element