aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/__tests__/components/ContentViewSpec.js
blob: a654870e3255e168243cd0c9bc100c608f40e9b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react'
import renderer from 'react-test-renderer'
import ContentView from '../../components/ContentView'
import { TStore, TFlow } from '../ducks/tutils'
import { Provider } from 'react-redux'
import mockXMLHttpRequest from 'mock-xmlhttprequest'

global.XMLHttpRequest = mockXMLHttpRequest

describe('ContentView Component', () => {
    let store = TStore()

    it('should render correctly', () => {
        store.getState().ui.flow.contentView = 'Edit'
        let tflow = TFlow(),
            provider = renderer.create(
            <Provider store={store}>
                <ContentView flow={tflow} message={tflow.request}/>
            </Provider>),
            tree = provider.toJSON()
        expect(tree).toMatchSnapshot()
    })

    it('should render correctly with empty content', () => {
        let tflow = TFlow()
        tflow.response.contentLength = 0
        let provider = renderer.create(
            <Provider store={store}>
                <ContentView flow={tflow} message={tflow.response} readonly={true}/>
            </Provider>),
            tree = provider.toJSON()
        expect(tree).toMatchSnapshot()
    })

    it('should render correctly with missing content', () => {
        let tflow = TFlow()
        tflow.response.contentLength = null
        let provider = renderer.create(
            <Provider store={store}>
                <ContentView flow={tflow} message={tflow.response} readonly={true}/>
            </Provider>),
            tree = provider.toJSON()
        expect(tree).toMatchSnapshot()
    })

    it('should render correctly with content too large', () => {
        let tflow = TFlow()
        tflow.response.contentLength = 1024 * 1024 * 100
        let provider = renderer.create(
            <Provider store={store}>
                <ContentView
                    flow={tflow}
                    message={tflow.response}
                    readonly={true}
                    uploadContent={jest.fn()}
                    onOpenFile={jest.fn()}
                />
            </Provider>),
            tree = provider.toJSON()
        expect(tree).toMatchSnapshot()
    })
})