Home Reference Source

application/__tests__/components/common/simple-editor/mention-strategy-test.js

jest.unmock('./../../../../components/common/simple-editor/strategy/mention');
jest.unmock('./../../../../components/common/simple-editor/util');

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 mentionStrategy from './../../../../components/common/simple-editor/strategy/mention';

describe('Mention strategy', () => {

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

    it('parses a mention', (done) => {
        const callback = (index, offset) => {
            expect(index).toEqual(10);
            expect(offset).toEqual(18);
            done();
        };

        const block = {
            getText: () => {
                return 'this is a @frofraz test';
            }
        };

        mentionStrategy(block, callback);
    });

    it('parses a complex mention', (done) => {
        const callback = (index, offset) => {
            expect(index).toEqual(10);
            expect(offset).toEqual(25);
            done();
        };

        const block = {
            getText: () => {
                return 'this is a @fro_fraz023fda test';
            }
        };

        mentionStrategy(block, callback);
    });

    it('ignores hyphens', (done) => {
        const callback = (index, offset) => {
            expect(index).toEqual(10);
            expect(offset).toEqual(14);
            done();
        };

        const block = {
            getText: () => {
                return 'this is a @fro-fraz023fda test';
            }
        };

        mentionStrategy(block, callback);
    });
});