-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(devtools): add types to Explorer (#2949)
* refactor(devtools): add types to Explorer Add types to Explorer component with as minimal functional changes as possible while still getting type safety 2742 * remove unused set param from explorer toggle * Wrap Explorer toggle with useCallback * Rename Explorer toggle to toggleExpanded * Remove unused path * Move subEntryPages definition next to usage * Set type to be a string instead of string union * Remove unused depth prop * Move chunkArrays to own tested function * set handleEntry as required * Add LabelButton for accesibility * fix test * Remove shadowing * Set subEntries as empty array by default * Add type for property * Convert handleEntry function to react component with entry props * Use unknown for value * Set RenderProps to required where possible * Add required attributes to Explorer tests
- Loading branch information
Showing
2 changed files
with
156 additions
and
54 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react' | ||
import { fireEvent, render, screen } from '@testing-library/react' | ||
|
||
import { chunkArray, DefaultRenderer } from '../Explorer' | ||
|
||
describe('Explorer', () => { | ||
describe('chunkArray', () => { | ||
it('when the size is less than one return an empty array', () => { | ||
expect(chunkArray([1, 2, 3], 0)).toStrictEqual([]) | ||
}) | ||
|
||
it('when the array is empty return an empty array', () => { | ||
expect(chunkArray([], 2)).toStrictEqual([]) | ||
}) | ||
|
||
it('when the array is evenly chunked return full chunks ', () => { | ||
expect(chunkArray([1, 2, 3, 4], 2)).toStrictEqual([ | ||
[1, 2], | ||
[3, 4], | ||
]) | ||
}) | ||
|
||
it('when the array is not evenly chunkable by size the last item is the remaining elements ', () => { | ||
const chunks = chunkArray([1, 2, 3, 4, 5], 2) | ||
const lastChunk = chunks[chunks.length - 1] | ||
expect(lastChunk).toStrictEqual([5]) | ||
}) | ||
}) | ||
|
||
describe('DefaultRenderer', () => { | ||
it('when the entry label is clicked, toggle expanded', async () => { | ||
const toggleExpanded = jest.fn() | ||
|
||
render( | ||
<DefaultRenderer | ||
label="the top level label" | ||
toggleExpanded={toggleExpanded} | ||
pageSize={10} | ||
expanded={false} | ||
subEntryPages={[[{ label: 'A lovely label' }]]} | ||
HandleEntry={() => <></>} | ||
value={undefined} | ||
subEntries={[]} | ||
type="string" | ||
/> | ||
) | ||
|
||
const expandButton = screen.getByRole('button', { | ||
name: /▶ the top level label 0 item/i, | ||
}) | ||
|
||
fireEvent.click(expandButton) | ||
|
||
expect(toggleExpanded).toHaveBeenCalledTimes(1) | ||
}) | ||
}) | ||
}) |
c6594df
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.
Successfully deployed to the following URLs: