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 { CollaborationObjectTypes } from '@reltio/mdm-sdk';
import CollaborationItem from './CollaborationItem';
import { render, screen } from '@testing-library/react';
import { MdmModuleProvider } from '../contexts/MdmModuleContext';
var createComment = function (hasReplies) {
    if (hasReplies === void 0) { hasReplies = false; }
    var comment = {
        selfLink: 'https://cservice-dev.reltio.com/tst-01/sokol/comments/00001lo',
        commentId: '00001lo',
        createdBy: 'vyacheslav.kovyazin',
        createdTime: 1620280049022,
        modifiedTime: 1620280061505,
        deleted: false,
        visibility: 'public',
        status: 'resolved',
        objectId: 'entities/13JKIKAz/attributes/Name/2mlWuqDq5',
        objectType: CollaborationObjectTypes.ENTITY_ATTRIBUTE,
        permanentLink: 'http://localhost:3000/ui/sokol/#p~com.reltio.plugins.entity.perspective.HCA_e~entities%2F13JKIKAz_ps~profile_cmt~00001lo',
        content: 'comment',
        namedUsers: [],
        replies: [],
        relatedObjectUris: ['entities/13JKIKAz']
    };
    if (hasReplies) {
        comment.replies.push({
            selfLink: 'https://cservice-dev.reltio.com/tst-01/sokol/comments/00001lo/replies/000007s',
            replyId: '000007s',
            createdBy: 'other.user',
            createdTime: 1620280061505,
            modifiedTime: 1620280061505,
            deleted: false,
            action: 'none',
            content: 'other comment',
            namedUsers: []
        });
    }
    return comment;
};
var createProps = function (comment) {
    return {
        comment: comment,
        uri: 'entities/13JKIKAz/attributes/Name/2mlWuqDq5',
        relatedObjectUris: ['entities/13JKIKAz'],
        objectType: CollaborationObjectTypes.ENTITY_ATTRIBUTE
    };
};
describe('CollaborationItem tests', function () {
    var entity = {
        type: 'configuration/entityTypes/HCP',
        uri: 'entities/02ZRRE9',
        attributes: {
            FirstName: [
                {
                    type: 'configuration/entityTypes/HCP/attributes/FirstName',
                    ov: true,
                    value: 'nameValue',
                    uri: 'entities/02ZRRE9/attributes/FirstName/15p60Tel'
                }
            ]
        }
    };
    var metadata = {
        entityTypes: [
            {
                uri: 'configuration/entityTypes/HCP',
                attributes: [
                    {
                        uri: 'configuration/entityTypes/HCP/attributes/FirstName',
                        type: 'String',
                        name: 'FirstName',
                        label: 'First Name',
                        access: ['READ', 'CREATE', 'UPDATE', 'INITIATE_CHANGE_REQUEST']
                    }
                ]
            }
        ]
    };
    var actions = {
        removeAttribute: function () { }
    };
    var mdmDefaultValues = {
        user: {
            username: 'test.testmail'
        },
        entity: entity,
        metadata: metadata,
        modifiedEntities: { 'entities/02ZRRE9': entity },
        dependentLookups: { editors: {}, structure: {}, initedTypeUris: [] }
    };
    var setUp = function (props) {
        var Providers = function (_a) {
            var children = _a.children;
            return (React.createElement(MdmModuleProvider, { values: mdmDefaultValues, actions: actions }, children));
        };
        return render(React.createElement(CollaborationItem, __assign({}, props)), { wrapper: Providers });
    };
    it('should render Comment correctly if comment exist', function () {
        setUp(createProps(createComment()));
        expect(screen.queryByText('VK')).toBeInTheDocument();
        expect(screen.queryByText('vyacheslav.kovyazin')).toBeInTheDocument();
        expect(screen.queryByText('comment')).toBeInTheDocument();
    });
    it('should not render Comment and RepliedComment if comment do not exist', function () {
        var container = setUp(createProps()).container;
        expect(container.querySelector('.comment')).not.toBeInTheDocument();
        expect(container.querySelector('.replies')).not.toBeInTheDocument();
    });
    it('should render SendMessageArea correctly', function () {
        var container = setUp(createProps(createComment())).container;
        expect(screen.queryByText('TT')).toBeInTheDocument();
        expect(container.querySelector('.sendMessageArea')).toBeInTheDocument();
    });
    it('should render replied comments correctly if they do exist', function () {
        setUp(createProps(createComment(true)));
        expect(screen.queryByText('OU')).toBeInTheDocument();
        expect(screen.queryByText('other.user')).toBeInTheDocument();
        expect(screen.queryByText('other comment')).toBeInTheDocument();
    });
});
