Home Reference Source

application/__tests__/components/draftable/draft-last-autosave-test.js

jest.unmock('./../../../components/draftable/draft-last-autosave');
jest.unmock('./../../../util/strings');

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 moment from 'moment';

import DraftLastAutosave from './../../../components/draftable/draft-last-autosave';

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

    afterEach(() => {
    });

    it('renders default format', () => {
        const now = moment('2016-10-28 15:30').utc();

        const el = TestUtils.renderIntoDocument(<DraftLastAutosave lastsave={now} />);
        const node = ReactDOM.findDOMNode(el);

        expect(node.textContent).toContain('03:30:00');
    });

    it('does not render if no time', () => {
        const now = false;

        const el = TestUtils.renderIntoDocument(<DraftLastAutosave lastsave={now} />);
        const node = ReactDOM.findDOMNode(el);

        expect(node.textContent).not.toContain('Last saved');
    });

    it('renders custom label', () => {
        const now = moment('2016-10-28 15:30').utc();

        const el = TestUtils.renderIntoDocument(<DraftLastAutosave label="Updated" lastsave={now} />);
        const node = ReactDOM.findDOMNode(el);

        expect(node.textContent).toContain('Updated 03:30:00');
    });

    it('rnders custom format', () => {
        const now = moment('2016-10-28 15:30').utc();

        const el = TestUtils.renderIntoDocument(<DraftLastAutosave format="lll" lastsave={now} />);
        const node = ReactDOM.findDOMNode(el);

        expect(node.textContent).toContain('Draft saved Oct 28, 2016 3:30 PM');
    });

});