-
Notifications
You must be signed in to change notification settings - Fork 33
feat: adds a renderSlot to NavTabList after content #2565
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 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9446d7d
feat: adds a renderSlot to NavTabList after content
dsmmcken 5b9517f
add test coverage
dsmmcken f837d7f
Initial plan
Copilot a5827ae
Address review comments: improve test assertions and add JSDoc
Copilot 9022b89
Fix .gitignore and remove .nx/ directory
Copilot eeb1fe9
Address additional review: rename prop, remove test, simplify mock
Copilot ab5875d
Update .gitignore
dsmmcken 9407d67
Update .gitignore
dsmmcken 4cc2ee7
Revert .gitignore changes to original state
Copilot 876c4e2
Changes before error encountered
Copilot 2ad6841
remove nx stuff
dsmmcken 1e3c039
Merge remote-tracking branch 'origin/main' into dmckenzie_NavTabSlot
dsmmcken 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import NavTabList, { type NavTabItem } from './NavTabList'; | ||
|
|
||
| // Helper to build tabs | ||
| function makeTabs(count = 3): NavTabItem[] { | ||
| return Array.from({ length: count }, (_, i) => ({ | ||
| key: `TAB_${i + 1}`, | ||
| title: `Tab ${i + 1}`, | ||
| isClosable: false, | ||
| })); | ||
| } | ||
|
|
||
| // JSDOM doesn't implement scrollIntoView; stub to avoid errors triggered by effect | ||
| beforeAll(() => { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| (window.HTMLElement as any).prototype.scrollIntoView = jest.fn(); | ||
| }); | ||
|
dsmmcken marked this conversation as resolved.
Outdated
|
||
|
|
||
| describe('NavTabList renderTabSlot', () => { | ||
| it('renders slot content for each tab when renderTabSlot provided', async () => { | ||
| const tabs = makeTabs(3); | ||
| const user = userEvent.setup(); | ||
| const slotTestId = (key: string) => `slot-${key}`; | ||
|
|
||
| render( | ||
| <NavTabList | ||
| activeKey={tabs[0].key} | ||
| tabs={tabs} | ||
| onSelect={jest.fn()} | ||
| renderTabSlot={tab => ( | ||
| <span data-testid={slotTestId(tab.key)}>{`${tab.title}-slot`}</span> | ||
| )} | ||
| /> | ||
| ); | ||
|
|
||
| // Assert each tab's slot is rendered | ||
| tabs.forEach(tab => { | ||
| expect(screen.getByTestId(slotTestId(tab.key))).toHaveTextContent( | ||
| `${tab.title}-slot` | ||
| ); | ||
| }); | ||
|
dsmmcken marked this conversation as resolved.
Outdated
|
||
|
|
||
| // Basic interaction sanity: selecting a tab still works with slot present | ||
| await user.click(screen.getByTestId('btn-nav-tab-Tab 2')); | ||
|
dsmmcken marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| it('does not render slot content when renderTabSlot is omitted', () => { | ||
| const tabs = makeTabs(2); | ||
| render( | ||
| <NavTabList activeKey={tabs[0].key} tabs={tabs} onSelect={jest.fn()} /> | ||
| ); | ||
|
|
||
| // Querying any potential slot test id should fail | ||
| const query = screen.queryByTestId('slot-TAB_1'); | ||
| expect(query).toBeNull(); | ||
| }); | ||
|
dsmmcken marked this conversation as resolved.
Outdated
|
||
| }); | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.