application/__tests__/components/common/rich-editor/pull-quote-test.js
jest.unmock('./../../../../components/common/rich-editor/pull-quote');
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 injectTapEventPlugin from 'react-tap-event-plugin';
import {Card, CardActions, CardHeader, CardMedia, CardTitle, CardText} from 'material-ui/Card';
import PullQuote from './../../../../components/common/rich-editor/pull-quote';
injectTapEventPlugin();
describe('PullQuoteEditorComponent', () => {
it('loads default state', () => {
const el = TestUtils.renderIntoDocument(<PullQuote />);
expect(el.state.editMode).toEqual(false);
const inner = TestUtils.findRenderedComponentWithType(el, Card);
expect(inner).not.toBeUndefined();
});
it('loads edit on click', () => {
const el = TestUtils.renderIntoDocument(<PullQuote />);
el.handleClick();
expect(el.state.editMode).toEqual(true);
const textbox = TestUtils.scryRenderedDOMComponentsWithTag(el, 'textarea');
expect(textbox).not.toBeUndefined();
});
it('updates on save', () => {
const el = TestUtils.renderIntoDocument(<PullQuote />);
const saveSpy = sinon.spy(el, 'handleSave');
el.handleClick();
expect(el.state.editMode).toEqual(true);
// const textbox = TestUtils.findRenderedDOMComponentWithTag(el, 'textarea');
el.refs.content.value = 'test';
const buttons = TestUtils.scryRenderedDOMComponentsWithTag(el, 'button');
TestUtils.Simulate.touchTap(buttons[0], {});
expect(saveSpy.called).toEqual(true);
el.handleSave.restore();
expect(el.state.editMode).toEqual(false);
})
});