Skip to content

Commit

Permalink
[KFI]test(document-viewer-react): Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
herflis committed Feb 6, 2019
1 parent 6443847 commit cbb41de
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 5 deletions.
Expand Up @@ -41,8 +41,12 @@ export class PrintComponent extends React.Component<
*/
public render() {
return (
<div style={{ display: 'inline-block' }} onClick={() => this.props.print(this.props.document)}>
<IconButton color="inherit" title={this.props.title}>
<div style={{ display: 'inline-block' }}>
<IconButton
color="inherit"
title={this.props.title}
onClick={() => this.props.print(this.props.document)}
id="Print">
<Print />
</IconButton>
</div>
Expand Down
Expand Up @@ -49,10 +49,18 @@ export class RotateActivePagesComponent extends React.Component<
public render() {
return (
<div style={{ display: 'inline-block' }}>
<IconButton color="inherit" title={this.props.rotateDocumentLeft} onClick={() => this.rotateDocumentLeft()}>
<IconButton
color="inherit"
title={this.props.rotateDocumentLeft}
onClick={() => this.rotateDocumentLeft()}
id="RotateActiveLeft">
<RotateLeft />
</IconButton>
<IconButton color="inherit" title={this.props.rotateDocumentRight} onClick={() => this.rotateDocumentRight()}>
<IconButton
color="inherit"
title={this.props.rotateDocumentRight}
onClick={() => this.rotateDocumentRight()}
id="RotateActiveRight">
<RotateRight />
</IconButton>
</div>
Expand Down
Expand Up @@ -42,7 +42,11 @@ export class ShareComponent extends React.Component<
public render() {
return (
<div style={{ display: 'inline-block' }}>
<IconButton color="inherit" title={this.props.title} onClick={() => this.props.share(this.props.document)}>
<IconButton
color="inherit"
title={this.props.title}
onClick={() => this.props.share(this.props.document)}
id="Share">
<Share />
</IconButton>
</div>
Expand Down
19 changes: 19 additions & 0 deletions packages/sn-document-viewer-react/test/PrintWidget.test.tsx
@@ -0,0 +1,19 @@
import { shallow } from 'enzyme'
import React from 'react'
import { PrintComponent } from '../src/components/document-widgets/PrintWidget'
import { DocumentData } from '../src/models/DocumentData'

describe('DownloadWidget component', () => {
it('Should render without crashing', () => {
const print = jest.fn()
const wrapper = shallow(<PrintComponent print={print} title="" document={{} as DocumentData} />)
expect(wrapper).toMatchSnapshot()
})

it('Should trigger a print request when clicked', () => {
const print = jest.fn()
const wrapper = shallow(<PrintComponent print={print} title="" document={{} as DocumentData} />)
wrapper.find('#Print').simulate('click')
expect(print).toBeCalled()
})
})
36 changes: 36 additions & 0 deletions packages/sn-document-viewer-react/test/RotateActivePage.test.tsx
@@ -0,0 +1,36 @@
import { shallow } from 'enzyme'
import React from 'react'
import { RotateActivePagesComponent } from '../src/components/document-widgets/RotateActivePages'
import { ROTATION_AMOUNT } from '../src/components/page-widgets/RotatePage'
import { examplePreviewImageData } from './__Mocks__/viewercontext'

describe('RotateActivePage component', () => {
const locals = {
rotateDocumentLeft: 'rotateDocumentLeft',
rotateDocumentRight: 'rotateDocumentRight',
pages: [],
activePages: [1],
}
it('Should render without crashing', () => {
const wrapper = shallow(<RotateActivePagesComponent {...locals} rotateImages={jest.fn()} />)
expect(wrapper).toMatchSnapshot()
})

it('RotateLeft should trigger a rotate to left', () => {
const rotateImages = jest.fn()
const wrapper = shallow(<RotateActivePagesComponent {...locals} rotateImages={rotateImages} />)

wrapper.find('#RotateActiveLeft').simulate('click')
expect(rotateImages).toBeCalledWith([examplePreviewImageData.Index], -ROTATION_AMOUNT)
expect(rotateImages).toBeCalled()
})

it('RotateRight should trigger a rotate to right', () => {
const rotateImages = jest.fn()
const wrapper = shallow(<RotateActivePagesComponent {...locals} rotateImages={rotateImages} />)

wrapper.find('#RotateActiveRight').simulate('click')
expect(rotateImages).toBeCalledWith([examplePreviewImageData.Index], ROTATION_AMOUNT)
expect(rotateImages).toBeCalled()
})
})
19 changes: 19 additions & 0 deletions packages/sn-document-viewer-react/test/ShareWidget.test.tsx
@@ -0,0 +1,19 @@
import { shallow } from 'enzyme'
import React from 'react'
import { ShareComponent } from '../src/components/document-widgets/ShareWidget'
import { DocumentData } from '../src/models/DocumentData'

describe('DownloadWidget component', () => {
it('Should render without crashing', () => {
const share = jest.fn()
const wrapper = shallow(<ShareComponent share={share} title="" document={{} as DocumentData} />)
expect(wrapper).toMatchSnapshot()
})

it('Should trigger a print request when clicked', () => {
const share = jest.fn()
const wrapper = shallow(<ShareComponent share={share} title="" document={{} as DocumentData} />)
wrapper.find('#Share').simulate('click')
expect(share).toBeCalled()
})
})
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DownloadWidget component Should render without crashing 1`] = `
<div
style={
Object {
"display": "inline-block",
}
}
>
<WithStyles(IconButton)
color="inherit"
id="Print"
onClick={[Function]}
title=""
>
<pure(PrintIcon) />
</WithStyles(IconButton)>
</div>
`;
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RotateActivePage component Should render without crashing 1`] = `
<div
style={
Object {
"display": "inline-block",
}
}
>
<WithStyles(IconButton)
color="inherit"
id="RotateActiveLeft"
onClick={[Function]}
title="rotateDocumentLeft"
>
<pure(RotateLeftIcon) />
</WithStyles(IconButton)>
<WithStyles(IconButton)
color="inherit"
id="RotateActiveRight"
onClick={[Function]}
title="rotateDocumentRight"
>
<pure(RotateRightIcon) />
</WithStyles(IconButton)>
</div>
`;
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DownloadWidget component Should render without crashing 1`] = `
<div
style={
Object {
"display": "inline-block",
}
}
>
<WithStyles(IconButton)
color="inherit"
id="Share"
onClick={[Function]}
title=""
>
<pure(ShareIcon) />
</WithStyles(IconButton)>
</div>
`;

0 comments on commit cbb41de

Please sign in to comment.