-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add JsonViewer basic unit tests
- Loading branch information
1 parent
04251a5
commit 1aa7d5d
Showing
4 changed files
with
59 additions
and
0 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 @@ | ||
export * from './JsonViewer'; |
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,44 @@ | ||
import * as React from 'react'; | ||
import { mount, ReactWrapper } from 'enzyme'; | ||
|
||
import { JsonViewer } from '../'; | ||
import { withTheme } from '../testProviders'; | ||
|
||
import { ClipboardService } from '../../services/ClipboardService'; | ||
|
||
const origCopySelected = ClipboardService.copySelected; | ||
|
||
describe('Components', () => { | ||
describe('JsonViewer', () => { | ||
let component: ReactWrapper; | ||
const data = { a: 1, b: { c: 'hello' } }; | ||
beforeEach(() => { | ||
component = mount(withTheme(<JsonViewer data={data} />)); | ||
ClipboardService.copySelected = origCopySelected; | ||
}); | ||
|
||
test('should render inner HTML', () => { | ||
expect(component.html()).toContain('class="redoc-json"'); | ||
}); | ||
|
||
test('should collapse/uncollapse', () => { | ||
expect(component.html()).not.toContain('class="hoverable"'); // all are collapesed by default | ||
const expandAll = component.find('div > span[children=" Expand all "]'); | ||
expandAll.simulate('click'); | ||
expect(component.html()).toContain('class="hoverable"'); // all are collapesed | ||
|
||
const collapseAll = component.find('div > span[children=" Collapse all "]'); | ||
collapseAll.simulate('click'); | ||
expect(component.html()).not.toContain('class="hoverable"'); // all are collapesed | ||
}); | ||
|
||
test('should collapse/uncollapse', () => { | ||
ClipboardService.copySelected = jest.fn(); | ||
|
||
const copy = component.find('span[onClick]').first(); | ||
copy.simulate('click'); | ||
|
||
expect(ClipboardService.copySelected as jest.Mock).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
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,13 @@ | ||
import * as React from 'react'; | ||
import { ThemeProvider } from 'styled-components'; | ||
import defaultTheme from '../theme'; | ||
|
||
export default class TestThemeProvider extends React.Component { | ||
render() { | ||
return <ThemeProvider theme={defaultTheme}>{this.props.children}</ThemeProvider>; | ||
} | ||
} | ||
|
||
export function withTheme(children) { | ||
return <TestThemeProvider>{children}</TestThemeProvider>; | ||
} |