-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add some tests for TreeGrid. Update README to reflect latest functionality. #39302
Merged
+67
−18
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
adc6185
Start working on updating/implementing new tests.
alexstine 2c88e42
Update README docs.
alexstine 028be7a
Add tests for Home/End. Fix missing onFocus consumer for Home/End.
alexstine e194523
Merge branch 'trunk' of github.com:wordpress/gutenberg into update/tr…
alexstine 0381fe5
Add item to changelog.
alexstine 3a0e27d
A few more changelog details.
alexstine cf30d7a
Fix changelog formatting.
alexstine 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import { fireEvent, render, screen } from '@testing-library/react'; | |
/** | ||
* WordPress dependencies | ||
*/ | ||
import { LEFT, RIGHT, UP, DOWN } from '@wordpress/keycodes'; | ||
import { LEFT, RIGHT, UP, DOWN, HOME, END } from '@wordpress/keycodes'; | ||
import { forwardRef } from '@wordpress/element'; | ||
|
||
/** | ||
|
@@ -68,10 +68,10 @@ describe( 'TreeGrid', () => { | |
level={ 1 } | ||
positionInSet={ 1 } | ||
setSize={ 3 } | ||
isExpanded={ true } | ||
isExpanded={ false } | ||
> | ||
<TreeGridCell withoutGridItem> | ||
<TestButton>Row 1</TestButton> | ||
<TestButton aria-expanded="false">Row 1</TestButton> | ||
</TreeGridCell> | ||
</TreeGridRow> | ||
<TreeGridRow | ||
|
@@ -88,7 +88,7 @@ describe( 'TreeGrid', () => { | |
level={ 1 } | ||
positionInSet={ 3 } | ||
setSize={ 3 } | ||
isExpanded={ true } | ||
isExpanded={ false } | ||
> | ||
<TreeGridCell withoutGridItem> | ||
<TestButton>Row 3</TestButton> | ||
|
@@ -97,16 +97,16 @@ describe( 'TreeGrid', () => { | |
</TreeGrid> | ||
); | ||
|
||
screen.getByText( 'Row 2' ).focus(); | ||
const row2Element = screen.getByText( 'Row 2' ).closest( 'tr' ); | ||
screen.getByText( 'Row 1' ).focus(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was necessary as row 1 will do the collapsing/expanding now. |
||
const row1Element = screen.getByText( 'Row 1' ).closest( 'tr' ); | ||
|
||
fireEvent.keyDown( screen.getByText( 'Row 2' ), { | ||
fireEvent.keyDown( screen.getByText( 'Row 1' ), { | ||
key: 'ArrowRight', | ||
keyCode: RIGHT, | ||
currentTarget: row2Element, | ||
currentTarget: row1Element, | ||
} ); | ||
|
||
expect( onExpandRow ).toHaveBeenCalledWith( row2Element ); | ||
expect( onExpandRow ).toHaveBeenCalledWith( row1Element ); | ||
} ); | ||
} ); | ||
|
||
|
@@ -120,17 +120,17 @@ describe( 'TreeGrid', () => { | |
level={ 1 } | ||
positionInSet={ 1 } | ||
setSize={ 3 } | ||
isExpanded={ false } | ||
isExpanded={ true } | ||
> | ||
<TreeGridCell withoutGridItem> | ||
<TestButton>Row 1</TestButton> | ||
<TestButton aria-expanded="true">Row 1</TestButton> | ||
</TreeGridCell> | ||
</TreeGridRow> | ||
<TreeGridRow | ||
level={ 1 } | ||
positionInSet={ 2 } | ||
setSize={ 3 } | ||
isExpanded={ true } | ||
isExpanded={ false } | ||
> | ||
<TreeGridCell withoutGridItem> | ||
<TestButton>Row 2</TestButton> | ||
|
@@ -149,16 +149,16 @@ describe( 'TreeGrid', () => { | |
</TreeGrid> | ||
); | ||
|
||
screen.getByText( 'Row 2' ).focus(); | ||
const row2Element = screen.getByText( 'Row 2' ).closest( 'tr' ); | ||
screen.getByText( 'Row 1' ).focus(); | ||
const row1Element = screen.getByText( 'Row 1' ).closest( 'tr' ); | ||
|
||
fireEvent.keyDown( screen.getByText( 'Row 2' ), { | ||
fireEvent.keyDown( screen.getByText( 'Row 1' ), { | ||
key: 'ArrowLeft', | ||
keyCode: LEFT, | ||
currentTarget: row2Element, | ||
currentTarget: row1Element, | ||
} ); | ||
|
||
expect( onCollapseRow ).toHaveBeenCalledWith( row2Element ); | ||
expect( onCollapseRow ).toHaveBeenCalledWith( row1Element ); | ||
} ); | ||
} ); | ||
|
||
|
@@ -205,6 +205,28 @@ describe( 'TreeGrid', () => { | |
); | ||
} ); | ||
|
||
it( 'should call onFocusRow with event, start and end nodes when pressing End', () => { | ||
const onFocusRow = jest.fn(); | ||
render( <TestTree onFocusRow={ onFocusRow } /> ); | ||
|
||
screen.getByText( 'Row 1' ).focus(); | ||
|
||
const row1Element = screen.getByText( 'Row 1' ).closest( 'tr' ); | ||
const row3Element = screen.getByText( 'Row 3' ).closest( 'tr' ); | ||
|
||
fireEvent.keyDown( screen.getByText( 'Row 1' ), { | ||
key: 'End', | ||
keyCode: END, | ||
currentTarget: row1Element, | ||
} ); | ||
|
||
expect( onFocusRow ).toHaveBeenCalledWith( | ||
expect.objectContaining( { key: 'End', keyCode: END } ), | ||
row1Element, | ||
row3Element | ||
); | ||
} ); | ||
|
||
it( 'should call onFocusRow with event, start and end nodes when pressing Up Arrow', () => { | ||
const onFocusRow = jest.fn(); | ||
render( <TestTree onFocusRow={ onFocusRow } /> ); | ||
|
@@ -227,6 +249,28 @@ describe( 'TreeGrid', () => { | |
); | ||
} ); | ||
|
||
it( 'should call onFocusRow with event, start and end nodes when pressing Home', () => { | ||
const onFocusRow = jest.fn(); | ||
render( <TestTree onFocusRow={ onFocusRow } /> ); | ||
|
||
screen.getByText( 'Row 3' ).focus(); | ||
|
||
const row3Element = screen.getByText( 'Row 3' ).closest( 'tr' ); | ||
const row1Element = screen.getByText( 'Row 1' ).closest( 'tr' ); | ||
|
||
fireEvent.keyDown( screen.getByText( 'Row 3' ), { | ||
key: 'Home', | ||
keyCode: HOME, | ||
currentTarget: row3Element, | ||
} ); | ||
|
||
expect( onFocusRow ).toHaveBeenCalledWith( | ||
expect.objectContaining( { key: 'Home', keyCode: HOME } ), | ||
row3Element, | ||
row1Element | ||
); | ||
} ); | ||
|
||
it( 'should call onFocusRow when shift key is held', () => { | ||
const onFocusRow = jest.fn(); | ||
render( <TestTree onFocusRow={ onFocusRow } /> ); | ||
|
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.
I guess this was missed in the original PR review. My bad.