Home Reference Source

application/__tests__/components/content/diff-test.js

jest.unmock('./../../../components/content/diff');
jest.unmock('./../../../util/strings');

import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';

import Diff from './../../../components/content/diff';

describe('DiffComponent', () => {

    beforeEach(() => {

    });

    afterEach(() => {

    });

    it('diffs two strings', () => {
        const strA = '<p>One <strong>morning</strong>, when he woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment.</p>'
        const strB = '<p>One <strong>morning</strong>, when <a href="#">Gregor Samsa</a> woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment.</p>'

        const el = TestUtils.renderIntoDocument(<Diff inputA={strA} inputB={strB} />);
        el.componentWillMount();

        expect(el.getDiff().__html).toEqual(
            '<p>One <strong>morning</strong>, when <del>he</del><a href="#"><ins>Gregor Samsa</ins></a> woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment.</p>'
        )
    });

    it('displays error on missing prop 1', () => {
        const strA = '<p>One <strong>morning</strong>, when he woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment.</p>'

        const el = TestUtils.renderIntoDocument(<Diff inputA={strA} />);
        el.componentWillMount();

        const div = TestUtils.findRenderedDOMComponentWithTag(el, 'div');

        expect(div.textContent).toEqual(
            'Waiting for second input...'
        )
    });

    it('displays error on missing prop 2', () => {
        const strA = '<p>One <strong>morning</strong>, when he woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment.</p>'

        const el = TestUtils.renderIntoDocument(<Diff inputB={strA} />);
        el.componentWillMount();

        const div = TestUtils.findRenderedDOMComponentWithTag(el, 'div');

        expect(div.textContent).toEqual(
            'Waiting for second input...'
        )
    });

});