var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React from 'react';
import { CommentContent } from './CommentContent';
import { UsersContext } from '../../../contexts/UsersContext';
import { render, screen } from '@testing-library/react';
describe('CommentContent test', function () {
    var createProps = function (text, namedUsers) {
        if (namedUsers === void 0) { namedUsers = []; }
        return {
            comment: {
                content: text,
                namedUsers: namedUsers
            }
        };
    };
    var allUsers = [
        { username: 'vyacheslav.kovyazin', email: 'vyacheslav.kovyazin@reltio.com' },
        { username: 'user', email: 'user@reltio.com' }
    ];
    var setUp = function (props, usersContext) {
        if (usersContext === void 0) { usersContext = allUsers; }
        var Providers = function (_a) {
            var children = _a.children;
            return (React.createElement(UsersContext.Provider, { value: usersContext }, children));
        };
        return render(React.createElement(CommentContent, __assign({}, props)), { wrapper: Providers });
    };
    it('should render comment without mentions correctly', function () {
        setUp(createProps('Hello world!!!'));
        expect(screen.queryByText('Hello world!!!')).toBeInTheDocument();
    });
    it('should render comment with one mention correctly', function () {
        setUp(createProps('Hello +vyacheslav.kovyazin', ['vyacheslav.kovyazin']));
        var link = screen.getByRole('link');
        var textBlock = screen.getByText('Hello');
        expect(link).toHaveAttribute('href', 'mailto:vyacheslav.kovyazin@reltio.com');
        expect(link).toHaveTextContent('+vyacheslav.kovyazin');
        expect(textBlock.childNodes[1]).toBe(link);
        expect(textBlock.textContent).toBe('Hello +vyacheslav.kovyazin');
    });
    it('should render comment with one mention in the beginning correctly', function () {
        setUp(createProps('+vyacheslav.kovyazin Hello', ['vyacheslav.kovyazin']));
        var link = screen.getByRole('link');
        var textBlock = screen.getByText('Hello');
        expect(textBlock.childNodes[0]).toBe(link);
        expect(textBlock.textContent).toBe('+vyacheslav.kovyazin Hello');
    });
    it('should render comment with two mentions correctly', function () {
        var container = setUp(createProps('Hello +vyacheslav.kovyazin and +user!!!', ['vyacheslav.kovyazin', 'user'])).container;
        var links = screen.getAllByRole('link');
        var textBlock = container.querySelector('.root');
        expect(textBlock.childNodes[1]).toBe(links[0]);
        expect(textBlock.childNodes[3]).toBe(links[1]);
        expect(textBlock.textContent).toBe('Hello +vyacheslav.kovyazin and +user!!!');
    });
    it('should render comment correctly if users is empty array', function () {
        var container = setUp(createProps('Hello +vyacheslav.kovyazin', ['vyacheslav.kovyazin']), []).container;
        expect(container.querySelector('.root').textContent).toBe('Hello +vyacheslav.kovyazin');
    });
});
