Home Reference Source

application/__tests__/components/content/content-audit-log-test.js

jest.unmock('./../../../components/content/content-audit-log');

import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import Immutable from 'immutable';
import sinon from 'sinon';
import AltTestingUtils from 'alt-utils/lib/AltTestingUtils';
import {Table, TableBody, TableFooter, TableHeader, TableHeaderColumn, TableRow, TableRowColumn} from 'material-ui/Table';
import Dialog from 'material-ui/Dialog';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';

import AuditLog from './../../../components/content/content-audit-log';

describe('AuditLog component', () => {

    it('loads without logs', () => {
        const el = TestUtils.renderIntoDocument(<AuditLog />);
        expect(el);

        const node = TestUtils.findRenderedDOMComponentWithTag(el, 'span');
        expect(node);
    });

    it('loads logs', () => {
        const logs = Immutable.fromJS([
            {
                "id": "2",
                "user_id": "1",
                "message": "content created",
                "created_at": "2016-05-20 20:01:45",
                "source_name": "content",
                "source_id": "114",
                "user": {
                    "id": "1",
                    "uuid": "529a0f9f-70ce-4132-85e7-30ef737aaff7",
                    "name": "Mike Joseph",
                    "email": "mike@getsnworks.com",
                    "is_snworks": "0",
                    "public_key": "pk_3hpNOsNYPtnEkmxX8NWDfPj7qYM8Oi",
                    "srn": "srn:tsn:ceo-core\/user:529a0f9f-70ce-4132-85e7-30ef737aaff7"
                }
            },
            {
                "id": "3",
                "user_id": "1",
                "message": "content updated: version",
                "created_at": "2016-05-20 20:10:29",
                "source_name": "content",
                "source_id": "114",
                "user": {
                    "id": "1",
                    "uuid": "529a0f9f-70ce-4132-85e7-30ef737aaff7",
                    "name": "Mike Joseph",
                    "email": "mike@getsnworks.com",
                    "is_snworks": "0",
                    "public_key": "pk_3hpNOsNYPtnEkmxX8NWDfPj7qYM8Oi",
                    "srn": "srn:tsn:ceo-core\/user:529a0f9f-70ce-4132-85e7-30ef737aaff7"
                }
            },
            {
                "id": "4",
                "user_id": "1",
                "message": "content updated: version",
                "created_at": "2016-05-20 20:10:31",
                "source_name": "content",
                "source_id": "114",
                "user": {
                    "id": "1",
                    "uuid": "529a0f9f-70ce-4132-85e7-30ef737aaff7",
                    "name": "Mike Joseph",
                    "email": "mike@getsnworks.com",
                    "is_snworks": "0",
                    "public_key": "pk_3hpNOsNYPtnEkmxX8NWDfPj7qYM8Oi",
                    "srn": "srn:tsn:ceo-core\/user:529a0f9f-70ce-4132-85e7-30ef737aaff7"
                }
            }
        ]);

        const el = TestUtils.renderIntoDocument(<AuditLog logs={logs} />);
        expect(el);
        el.setState({'modalIsOpen': true});

        const items = TestUtils.scryRenderedComponentsWithType(el, Dialog);
        expect(items.length).toEqual(1);
        const dialog = TestUtils.renderIntoDocument(<MuiThemeProvider>{items[0].renderLayer()}</MuiThemeProvider>);

        const rows = TestUtils.scryRenderedComponentsWithType(dialog, TableRow);
        expect(rows.length).toEqual(3);
    });

});