-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add menubar component unit test (#385)
* feat: complete ts type definition * test: add menubar component unit test
- Loading branch information
1 parent
6bb6605
commit a6ea337
Showing
4 changed files
with
73 additions
and
5 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
16 changes: 16 additions & 0 deletions
16
src/workbench/menuBar/__tests__/__snapshots__/menubar.test.tsx.snap
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,16 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Test MenuBar Component Match the MenuBar snapshot 1`] = ` | ||
<div | ||
className="mo-menuBar" | ||
> | ||
<div | ||
className="mo-drop-down mo-drop-down--right mo-menuBar__action" | ||
onClick={[Function]} | ||
> | ||
<span | ||
className="codicon codicon-menu" | ||
/> | ||
</div> | ||
</div> | ||
`; |
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,51 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import MenuBar, { actionClassName } from '../menuBar'; | ||
|
||
const TEST_ID = 'test-id'; | ||
const menuData = [ | ||
{ | ||
id: TEST_ID, | ||
name: TEST_ID, | ||
data: [ | ||
{ | ||
id: 'New File', | ||
name: 'New File', | ||
}, | ||
{ | ||
id: 'OpenFile', | ||
name: 'Open', | ||
}, | ||
], | ||
}, | ||
]; | ||
const TEST_FN: jest.Mock<any, any> = jest.fn(); | ||
|
||
describe('Test MenuBar Component', () => { | ||
test('Match the MenuBar snapshot', () => { | ||
const component = renderer.create( | ||
<MenuBar data={menuData} onClick={TEST_FN} /> | ||
); | ||
|
||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
test('Should support to set status for item', () => { | ||
const { container, queryByText, getByRole } = render( | ||
<MenuBar data={menuData} onClick={TEST_FN} /> | ||
); | ||
const component = container.firstElementChild! | ||
.firstElementChild as HTMLDivElement; | ||
expect(component!.className).toContain(actionClassName); | ||
|
||
fireEvent.click(component); | ||
const span = queryByText(TEST_ID) as HTMLSpanElement; | ||
expect(span).not.toBeNull(); | ||
|
||
const menuBar = getByRole('menu').firstElementChild as HTMLLIElement; | ||
expect(menuBar).toBeInTheDocument(); | ||
}); | ||
}); |
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