application/__tests__/components/common/rich-editor/media-resize-test.js
jest.unmock('./../../../../components/common/rich-editor/media-resize');
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 MediaResize from './../../../../components/common/rich-editor/media-resize';
// This is mostly based off the resize-box component
// which is already tested - so we're just testing states
describe('MediaResizeEditorComponent', () => {
beforeEach(() => {
jasmine.clock().uninstall();
});
it('loads default state', () => {
const content = Immutable.fromJS({size: 1000, attachment: {}});
const el = TestUtils.renderIntoDocument(<MediaResize content={content} />);
el.componentWillMount();
expect(el.state.initialHeight).toEqual(0);
expect(el.state.initialWidth).toEqual(0);
expect(el.state.height).toEqual(0);
expect(el.state.width).toEqual(0);
});
it('loads set state', () => {
const content = Immutable.fromJS({size: 1000, attachment: {}});
const el = TestUtils.renderIntoDocument(<MediaResize content={content} height={101} width={201} />);
el.componentWillMount();
expect(el.state.initialHeight).toEqual(101);
expect(el.state.initialWidth).toEqual(201);
expect(el.state.height).toEqual(101);
expect(el.state.width).toEqual(201);
});
it('updated size on drag', () => {
const content = Immutable.fromJS({size: 1000, attachment: {}});
const el = TestUtils.renderIntoDocument(<MediaResize content={content} />);
el.componentWillMount();
const resizeStub = sinon.stub(el.refs.container, 'getBoundingClientRect', () => {
return {height: 51, width: 101};
});
el.setSize();
expect(el.state.height).toEqual(51);
expect(el.state.width).toEqual(101);
});
});