-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Viewer: Selection of one or more elements via tree view (#597)
* multi select from nav panel * added test for NavTree click and shift click
- Loading branch information
Showing
4 changed files
with
71 additions
and
32 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
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,18 +1,58 @@ | ||
import React from 'react' | ||
import {render} from '@testing-library/react' | ||
import {render, act, fireEvent} from '@testing-library/react' | ||
import ShareMock from '../ShareMock' | ||
import {MockViewer, newMockStringValueElt} from '../utils/IfcMock.test' | ||
import NavTree from './NavTree' | ||
|
||
|
||
test('NavTree for single element', () => { | ||
const testLabel = 'Test node label' | ||
const {getByText} = render( | ||
<ShareMock> | ||
jest.mock('@mui/lab/TreeItem', () => { | ||
const original = jest.requireActual('@mui/lab/TreeItem') | ||
return { | ||
__esModule: true, | ||
...original, | ||
useTreeItem: jest.fn().mockReturnValue({ | ||
disabled: false, | ||
expanded: false, | ||
selected: false, | ||
focused: false, | ||
handleExpansion: jest.fn(), | ||
handleSelection: jest.fn(), | ||
}), | ||
} | ||
}) | ||
|
||
describe('NavTree', () => { | ||
test('NavTree for single element', () => { | ||
const testLabel = 'Test node label' | ||
const {getByText} = render( | ||
<ShareMock> | ||
<NavTree | ||
viewer={new MockViewer} | ||
element={newMockStringValueElt(testLabel)} | ||
/> | ||
</ShareMock>) | ||
expect(getByText(testLabel)).toBeInTheDocument() | ||
}) | ||
|
||
it('should select element on click', async () => { | ||
const selectElementsMock = jest.fn() | ||
const testLabel = 'Test node label' | ||
const ifcElementMock = newMockStringValueElt(testLabel) | ||
const {getByText} = render( | ||
<NavTree | ||
viewer={new MockViewer} | ||
element={newMockStringValueElt(testLabel)} | ||
/> | ||
</ShareMock>) | ||
expect(getByText(testLabel)).toBeInTheDocument() | ||
element={ifcElementMock} | ||
pathPrefix={'/share/v/p/index.ifc'} | ||
selectWithShiftClickEvents={selectElementsMock} | ||
/>) | ||
const root = await getByText(testLabel) | ||
expect(getByText(testLabel)).toBeInTheDocument() | ||
await act(async () => { | ||
await fireEvent.click(root) | ||
}) | ||
expect(selectElementsMock).toHaveBeenLastCalledWith(false, 1) | ||
await act(async () => { | ||
await fireEvent.click(root, {shiftKey: true}) | ||
}) | ||
expect(selectElementsMock).toHaveBeenLastCalledWith(true, 1) | ||
}) | ||
}) |
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