-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add middle click dashboard tab deletion (#1992)
Resolves #1990 - Add functionality to close dashboard tab with middle mouse click by specifying onAuxClick event - Create NavBar component test cases that test changes
- Loading branch information
1 parent
bb23671
commit c922f87
Showing
2 changed files
with
78 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { useRef } from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { | ||
DragDropContext, | ||
DropResult, | ||
Droppable, | ||
ResponderProvided, | ||
} from 'react-beautiful-dnd'; | ||
import NavTab from './NavTab'; | ||
|
||
const mockOnClose = jest.fn(); | ||
|
||
const defaultProps = { | ||
tab: { key: 'TEST', title: 'TEST', isCloseable: true }, | ||
key: 'testKey', | ||
index: 0, | ||
isActive: true, | ||
onSelect: (key: string) => null, | ||
isDraggable: true, | ||
}; | ||
|
||
function MakeNavTab() { | ||
const mockActiveTabRef = useRef<HTMLDivElement>(null); | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
const handleDragEnd = (e: DropResult, provided: ResponderProvided) => {}; | ||
const props = { | ||
...defaultProps, | ||
activeRef: mockActiveTabRef, | ||
onClose: mockOnClose, | ||
}; | ||
return ( | ||
<DragDropContext onDragEnd={handleDragEnd}> | ||
<Droppable droppableId="test-droppable-id"> | ||
{provided => ( | ||
<div ref={provided.innerRef}> | ||
{/* eslint-disable-next-line react/jsx-props-no-spreading */} | ||
<NavTab {...props}>ButtonText</NavTab> | ||
</div> | ||
)} | ||
</Droppable> | ||
</DragDropContext> | ||
); | ||
} | ||
|
||
it('should not delete by calling onClose on left click', async () => { | ||
const user = userEvent.setup(); | ||
render(<MakeNavTab />); | ||
const navTabComponent = screen.getByTestId('btn-nav-tab-TEST'); | ||
await user.pointer({ keys: '[MouseLeft]', target: navTabComponent }); | ||
expect(mockOnClose).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should delete by calling onClose on middle click', async () => { | ||
const user = userEvent.setup(); | ||
render(<MakeNavTab />); | ||
const navTabComponent = screen.getByTestId('btn-nav-tab-TEST'); | ||
await user.pointer({ keys: '[MouseMiddle]', target: navTabComponent }); | ||
expect(mockOnClose).toHaveBeenCalled(); | ||
}); |
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