Home Reference Source

application/__tests__/components/common/quips-test.js

jest.unmock('./../../../components/common/quips');
jest.unmock('./../../../data/quips');

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 Quips from './../../../components/common/quips';

describe('QuipsComponent', () => {

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

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

    it('loads empty', () => {
        const q = TestUtils.renderIntoDocument(<Quips />);
        q.componentWillMount();

        let text = TestUtils.findRenderedDOMComponentWithClass(q, 'quip');

        const current = text.textContent;
        expect(current.length).toBeGreaterThan(0);
    });

    it('reloads quip on click', () => {
        const q = TestUtils.renderIntoDocument(<Quips />);
        q.componentWillMount();

        let text = TestUtils.findRenderedDOMComponentWithClass(q, 'quip');

        const current = text.textContent;
        expect(current.length).toBeGreaterThan(0);

        TestUtils.Simulate.click(
            text,
            {}
        );
        jasmine.clock().tick(401);

        text = TestUtils.findRenderedDOMComponentWithClass(q, 'quip');
        expect(text.textContent).not.toEqual(current);

    });

    it('reloads quip on interval', (done) => {
        const q = TestUtils.renderIntoDocument(<Quips randomize={500} />);
        const changeSpy = sinon.spy(q, 'onUpdate')
        q.componentWillMount();

        let text = TestUtils.findRenderedDOMComponentWithClass(q, 'quip');

        const current = text.textContent;
        expect(current.length).toBeGreaterThan(0);

        jasmine.clock().tick(2401);

        expect(changeSpy.called).toEqual(true);
        q.onUpdate.restore();

        done();
    });

});