Home Reference Source

application/__tests__/components/common/character-counter-test.js

jest.unmock('./../../../components/common/character-counter');

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 CharacterCounter from './../../../components/common/character-counter';

describe('CharacterCounter', () => {
    beforeEach(() => {
    });

    afterEach(() => {
    });

    it('displays proper counter', () => {
        let testString = 'this is a test';

        const el = TestUtils.renderIntoDocument(<CharacterCounter count={testString} />);
        expect(el.state.count).toEqual(14);
    });

    it('displays default label', () => {
        let testString = 'this is a test';

        const el = TestUtils.renderIntoDocument(<CharacterCounter count={testString} />);
        const span = TestUtils.findRenderedDOMComponentWithTag(el, 'span');
        expect(span.textContent).toContain('characters');
    });

    it('pluralizes default label', () => {
        let testString = 'o';

        const el = TestUtils.renderIntoDocument(<CharacterCounter count={testString} />);
        const span = TestUtils.findRenderedDOMComponentWithTag(el, 'span');
        expect(span.textContent).toContain('character');
        expect(span.textContent).not.toContain('characters');
    });

    it('pluralizes set', () => {
        let testString = 'another thing';

        const el = TestUtils.renderIntoDocument(<CharacterCounter count={testString} label='test' />);
        const span = TestUtils.findRenderedDOMComponentWithTag(el, 'span');
        expect(span.textContent).toContain('tests');
    });

    it('does not display empty', () => {
        let testString = '';

        const el = TestUtils.renderIntoDocument(<CharacterCounter count={testString} />);
        const span = TestUtils.findRenderedDOMComponentWithTag(el, 'span');
        expect(span.textContent.length).toEqual(0);
    });

    it('does display empty', () => {
        let testString = '';

        const el = TestUtils.renderIntoDocument(<CharacterCounter count={testString} displayEmpty={true} />);
        const span = TestUtils.findRenderedDOMComponentWithTag(el, 'span');
        expect(span.textContent).toContain('0 characters');
    });

    it('displays empty string', () => {
        const el = TestUtils.renderIntoDocument(<CharacterCounter />);
        expect(el);
    })

});