Home Reference Source

application/__tests__/components/common/rich-editor-test.js

jest.unmock('./../../../components/common/rich-editor');
jest.unmock('./../../../services/base-service');
jest.unmock('./../../../services/copyNote-service');

jest.unmock('./../../../components/common/rich-editor/pull-quote');
jest.unmock('./../../../components/common/rich-editor/embed');
jest.unmock('./../../../components/common/rich-editor/media');
jest.unmock('./../../../components/common/rich-editor/link');

jest.unmock('./../../../alt');

jest.unmock('draft-js');

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 RichEditor from './../../../components/common/rich-editor';
import {CopyNoteService, CopyNoteStore} from './../../../services/copyNote-service';

// We're only testing additional functionality and some of the basic
// properties built in. The assumption being that Draft is an external
// lib and is already tested
describe('RichEditor', () => {

    beforeEach(() => {
        jasmine.clock().uninstall();
    });

    it('loads default state', () => {
        const editor = TestUtils.renderIntoDocument(
            <RichEditor
                label="Test"
                name="test"
                readOnly={false}
                version={1}
                defaultValue='test'
                onChange={() => {}}
                />
        );

        expect(editor.editingReferenceCounter).toEqual(0);
    });

    it('increments and decrements reference counter', () => {
        const editor = TestUtils.renderIntoDocument(
            <RichEditor
                label="Test"
                name="test"
                readOnly={false}
                version={1}
                defaultValue='test'
                onChange={() => {}}
                />
        );

        editor.retain();
        editor.retain();
        expect(editor.editingReferenceCounter).toEqual(2);
        expect(editor.state.isComponentEditing).toEqual(true);

        editor.release();
        expect(editor.editingReferenceCounter).toEqual(1);
        expect(editor.state.isComponentEditing).toEqual(true);

        editor.release();
        expect(editor.editingReferenceCounter).toEqual(0);
        expect(editor.state.isComponentEditing).toEqual(false);
    });
});