application/__tests__/components/common/rich-editor/note-viewer-test.js
jest.unmock('./../../../../components/common/rich-editor/note-viewer');
jest.unmock('./../../../../services/base-service');
jest.unmock('./../../../../services/copyNote-service');
jest.unmock('./../../../../services/noteComment-service');
jest.unmock('./../../../../util/strings');
jest.unmock('./../../../../util/mock-fetch');
jest.unmock('./../../../../components/common/simple-editor');
jest.unmock('./../../../../services/error-service');
jest.unmock('./../../../../components/common/simple-editor/service');
jest.unmock('./../../../../components/common/simple-editor/inline-style-controls');
jest.unmock('./../../../../components/common/simple-editor/block-style-controls');
jest.unmock('./../../../../components/common/simple-editor/format-style-controls');
jest.unmock('./../../../../alt');
jest.unmock('draft-js');
import injectTapEventPlugin from 'react-tap-event-plugin';
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 FlatButton from 'material-ui/FlatButton';
import NoteViewer from './../../../../components/common/rich-editor/note-viewer';
import {NoteBox, SingleNote, CommentBox} from './../../../../components/common/rich-editor/note-viewer';
import alt from './../../../../alt';
import {CopyNoteService, CopyNoteStore} from './../../../../services/copyNote-service';
import NoteCommentFlux from './../../../../services/noteComment-service';
import fetch from './../../../../util/mock-fetch';
injectTapEventPlugin();
describe('NoteViewerEditorComponent', () => {
    beforeEach(() => {
        jasmine.clock().uninstall();
        jasmine.clock().install();
        sinon.stub(window, 'fetch').returns(fetch({
            'items': [
                {
                    id: 1,
                    uuid: '123-456',
                    content: 'foo',
                    user: {}
                }
            ]
        }));
    });
    afterEach(() => {
        jasmine.clock().uninstall();
        window.fetch.restore();
    });
    it('loads note stack', () => {
        const el = TestUtils.renderIntoDocument(<NoteViewer />);
        el.componentWillMount();
        CopyNoteService.add(1, 1, 'test note', 'test user', false, 1, 1);
        jasmine.clock().tick(2);
        const results = TestUtils.scryRenderedComponentsWithType(el, NoteBox);
        expect(results.length).toBeGreaterThan(0);
    });
    it('sets note selection', () => {
        const clickSpy = sinon.spy(CopyNoteService, 'setLastSelectedNote');
        const el = TestUtils.renderIntoDocument(<NoteViewer />);
        el.componentWillMount();
        CopyNoteService.add('123-456', '987-664', 'test note', 'test user', false, 1, 1);
        jasmine.clock().tick(2);
        const results = TestUtils.scryRenderedDOMComponentsWithClass(el, 'richEditor-copyNoteView');
        TestUtils.Simulate.click(results[0], {});
        expect(clickSpy.called).toEqual(true);
        CopyNoteService.setLastSelectedNote.restore();
    });
    it('creates comments', (done) => {
        // el.componentWillMount();
        CopyNoteService.reset();
        jasmine.clock().tick(2);
        expect(CopyNoteStore.getState().notes.length).toEqual(0);
        CopyNoteService.add('543-6543', '987-664', 'test note', 'test user', false, 1, 1);
        jasmine.clock().tick(2);
        expect(CopyNoteStore.getState().notes.length).toEqual(1);
        const el = TestUtils.renderIntoDocument(<NoteViewer />);
        el.setState({selection: '987-664'});
        // const results = TestUtils.scryRenderedDOMComponentsWithClass(el, 'RichEditor-copyNoteView');
        const result = TestUtils.findRenderedComponentWithType(el, NoteBox);
        expect(result).not.toBeUndefined();
        expect(result.props.currentlySelected).toEqual(true);
        const commentBox = TestUtils.findRenderedComponentWithType(el, CommentBox);
        expect(commentBox).not.toBeUndefined();
        expect(commentBox.props.currentlySelected).toEqual(true);
        const commentItems = TestUtils.scryRenderedComponentsWithType(commentBox, SingleNote);
        expect(commentItems.length).toEqual(0);
        const submitSpy = sinon.spy(commentBox, 'confirm');
        const button = TestUtils.findRenderedComponentWithType(commentBox, FlatButton);
        expect(button).not.toBeUndefined();
        const buttonNode = ReactDOM.findDOMNode(button);
        TestUtils.Simulate.touchTap(buttonNode, {metaKey: true, which: 13});
        expect(window.fetch.called).toEqual(true);
        done();
    });
});