Home Reference Source

application/__tests__/components/draftable/draft-restore-test.js

jest.unmock('./../../../components/draftable/draft-restore');

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 RaisedButton from 'material-ui/RaisedButton';

import DraftRestore from './../../../components/draftable/draft-restore';

describe('DraftRestore component', () => {
    beforeEach(() => {
    });

    afterEach(() => {
    });

    it('calls click handler', () => {
        const mockSpy = sinon.mock();
        const pending = Immutable.fromJS({
            'content': 'fork!'
        });

        const el = TestUtils.renderIntoDocument(
            <DraftRestore pendingDraft={pending} onRestore={mockSpy} />
        );
        const link = TestUtils.findRenderedComponentWithType(el, RaisedButton);
        expect(link);

        // TestUtils.Simulate.click(link, {});
        el.handleClick({
            preventDefault: () => {},
            stopPropagation: () => {}
        });

        expect(mockSpy.calledOnce).toEqual(true);
    });

    it('hides on empty', () => {
        const pending = false;
        const mockSpy = sinon.mock();

        const el = TestUtils.renderIntoDocument(
            <DraftRestore pendingDraft={pending} onRestore={mockSpy} />
        );

        const node = ReactDOM.findDOMNode(el);
        expect(node.textContent.length).toEqual(0);
    });

    it('sets notice label', () => {
        const mockSpy = sinon.mock();
        const pending = Immutable.fromJS({
            'content': 'fork!'
        });

        const el = TestUtils.renderIntoDocument(
            <DraftRestore label='There is a draft pending...' pendingDraft={pending} onRestore={mockSpy} />
        );
        const node = ReactDOM.findDOMNode(el);
        expect(node.textContent).toContain('There is a draft pending...');
    });

    it('sets button label', () => {
        const mockSpy = sinon.mock();
        const pending = Immutable.fromJS({
            'content': 'fork!'
        });

        const el = TestUtils.renderIntoDocument(
            <DraftRestore buttonLabel='Restore draft!' pendingDraft={pending} onRestore={mockSpy} />
        );

        const link = TestUtils.findRenderedComponentWithType(el, RaisedButton);
        const node = ReactDOM.findDOMNode(link);
        expect(node.textContent).toContain('Restore draft!');
    });

    it('sets button class', () => {
        const mockSpy = sinon.mock();
        const pending = Immutable.fromJS({
            'content': 'fork!'
        });

        const el = TestUtils.renderIntoDocument(
            <DraftRestore buttonClass='btn btn-large-fraf' pendingDraft={pending} onRestore={mockSpy} />
        );
        const node = ReactDOM.findDOMNode(el);
        const link = TestUtils.findRenderedDOMComponentWithClass(el, 'btn-large-fraf');
        expect(link);
    });

});