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);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
    return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
import React from 'react';
import { renderHook, act } from '@testing-library/react';
import { getCommentsCount, getTotalCommentsCount, getComment, createComment, createReply, deleteComment, updateComment, getComments, deleteReply, updateReply } from '@reltio/mdm-sdk';
import { MdmModuleProvider } from '../../contexts/MdmModuleContext';
import { useCollaboration } from './useCollaboration';
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getCommentsCount: jest.fn(), getTotalCommentsCount: jest.fn(), getComment: jest.fn(), createComment: jest.fn(), createReply: jest.fn(), updateComment: jest.fn(), deleteComment: jest.fn(), getComments: jest.fn(), deleteReply: jest.fn(), updateReply: jest.fn() })); });
describe('useCollaboration behaviour', function () {
    var defaultMdmValues = {
        uiPath: 'https://localhost:3000/ui/alenat',
        isCollaborationEnabled: true,
        collaborationPath: '123',
        tenant: { id: 'alenat', name: 'alenat' },
        entity: { uri: '1' }
    };
    var setUp = function (_a) {
        var _b = _a === void 0 ? {} : _a, _c = _b.props, props = _c === void 0 ? {} : _c, _d = _b.mdmValues, mdmValues = _d === void 0 ? defaultMdmValues : _d;
        var Providers = function (_a) {
            var children = _a.children;
            return (React.createElement(MdmModuleProvider, { values: mdmValues }, children));
        };
        return renderHook(useCollaboration, { initialProps: props, wrapper: Providers });
    };
    beforeEach(function () {
        getComment.mockResolvedValue({ commentId: 'commentId' });
        getCommentsCount.mockResolvedValue([{ objectId: 'uri1', comments: [] }]);
        getTotalCommentsCount.mockResolvedValue({ total: 1 });
    });
    afterEach(function () {
        jest.resetAllMocks();
    });
    it('should not call getCommentsCount if collaboration is not enabled', function () {
        var mdmValues = __assign(__assign({}, defaultMdmValues), { collaborationPath: undefined, isCollaborationEnabled: false });
        var result = setUp({ mdmValues: mdmValues }).result;
        expect(result.current.commentsMap).toBe(null);
        expect(result.current.totalCommentsCount).toBe(null);
        expect(getCommentsCount).not.toHaveBeenCalled();
        expect(getTotalCommentsCount).not.toHaveBeenCalled();
    });
    it('should call getCommentsCount if collaboration is enabled and uris is undefined and update commentsMap value', function () { return __awaiter(void 0, void 0, void 0, function () {
        var result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    getCommentsCount.mockResolvedValueOnce([]);
                    getTotalCommentsCount.mockResolvedValueOnce({ total: 1 });
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(getCommentsCount).toHaveBeenCalledWith({
                        uris: [],
                        tenant: 'alenat',
                        collaborationPath: defaultMdmValues.collaborationPath
                    });
                    expect(result.current.commentsMap).toEqual({});
                    return [2 /*return*/];
            }
        });
    }); });
    it('should call getCommentsCount if collaboration is enabled and update commentsMap value', function () { return __awaiter(void 0, void 0, void 0, function () {
        var comments, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    comments = [
                        { commentId: 'id1', status: 'open', replies: 1 },
                        { commentId: 'id2', status: 'open', replies: 2 }
                    ];
                    getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: comments }]);
                    result = setUp({ props: { objectIds: ['uri1'] } }).result;
                    expect(getCommentsCount).toHaveBeenCalledWith({
                        uris: ['uri1'],
                        tenant: 'alenat',
                        collaborationPath: defaultMdmValues.collaborationPath
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.commentsMap).toEqual({ uri1: comments });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should set commentsMap value as null in case of unsuccessful request', function () { return __awaiter(void 0, void 0, void 0, function () {
        var result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    getCommentsCount.mockRejectedValueOnce(null);
                    result = setUp().result;
                    expect(getCommentsCount).toHaveBeenCalled();
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.commentsMap).toBe(null);
                    return [2 /*return*/];
            }
        });
    }); });
    it('should call getCommentsCount with new objectIds and add result into commentsMap', function () { return __awaiter(void 0, void 0, void 0, function () {
        var firstComments, secondComments, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    firstComments = [{ commentId: 'id1', status: 'open', replies: 1 }];
                    secondComments = [{ commentId: 'id2', status: 'open', replies: 2 }];
                    getCommentsCount.mockImplementation(function (_a) {
                        var uris = _a.uris;
                        if (uris.includes('uri1')) {
                            return Promise.resolve([{ objectId: 'uri1', comments: firstComments }]);
                        }
                        else {
                            return Promise.resolve([{ objectId: 'uri2', comments: secondComments }]);
                        }
                    });
                    result = setUp({ props: { objectIds: ['uri1'] } }).result;
                    expect(getCommentsCount).toHaveBeenCalledWith({
                        uris: ['uri1'],
                        tenant: 'alenat',
                        collaborationPath: defaultMdmValues.collaborationPath
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.getCommentsCount(['uri2']);
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(getCommentsCount).toHaveBeenCalledWith({
                        uris: ['uri2'],
                        tenant: 'alenat',
                        collaborationPath: defaultMdmValues.collaborationPath
                    });
                    expect(result.current.commentsMap).toEqual({ uri1: firstComments, uri2: secondComments });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should use new comments when objectIds changed', function () { return __awaiter(void 0, void 0, void 0, function () {
        var firstComments, secondComments, _a, result, rerender;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    firstComments = [{ commentId: 'id1', status: 'open', replies: 1 }];
                    secondComments = [{ commentId: 'id2', status: 'open', replies: 2 }];
                    getCommentsCount.mockImplementation(function (_a) {
                        var uris = _a.uris;
                        if (uris.includes('uri1')) {
                            return Promise.resolve([{ objectId: 'uri1', comments: firstComments }]);
                        }
                        else {
                            return Promise.resolve([{ objectId: 'uri2', comments: secondComments }]);
                        }
                    });
                    _a = setUp({ props: { objectIds: ['uri1'] } }), result = _a.result, rerender = _a.rerender;
                    expect(getCommentsCount).toHaveBeenCalledWith({
                        uris: ['uri1'],
                        tenant: 'alenat',
                        collaborationPath: defaultMdmValues.collaborationPath
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0:
                                        rerender({ objectIds: ['uri2'] });
                                        return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 1:
                    _b.sent();
                    expect(getCommentsCount).toHaveBeenCalledWith({
                        uris: ['uri2'],
                        tenant: 'alenat',
                        collaborationPath: defaultMdmValues.collaborationPath
                    });
                    expect(result.current.commentsMap).toEqual({ uri2: secondComments });
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of getComments should call getComments request and set comments and pageToken', function () { return __awaiter(void 0, void 0, void 0, function () {
        var result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    getComments.mockResolvedValueOnce({
                        items: [{ commentId: 'commentId1' }, { commentId: 'commentId2' }],
                        nextPageToken: 'token'
                    });
                    result = setUp().result;
                    expect(result.current.comments).toEqual([]);
                    expect(result.current.pageToken).toBe(null);
                    act(function () {
                        result.current.getComments('uri');
                    });
                    expect(getComments).toHaveBeenCalledWith({
                        collaborationPath: '123',
                        tenant: 'alenat',
                        relatedObjectUri: 'uri'
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.pageToken).toBe('token');
                    expect(result.current.comments).toEqual([{ commentId: 'commentId1' }, { commentId: 'commentId2' }]);
                    getComments.mockResolvedValueOnce({
                        items: [{ commentId: 'commentId2' }, { commentId: 'commentId3' }],
                        nextPageToken: 'token2'
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.getComments('uri', 'token');
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.pageToken).toBe('token2');
                    expect(result.current.comments).toEqual([
                        { commentId: 'commentId1' },
                        { commentId: 'commentId2' },
                        { commentId: 'commentId3' }
                    ]);
                    getComments.mockResolvedValueOnce({
                        items: [{ commentId: 'commentId1' }, { commentId: 'commentId2' }],
                        nextPageToken: 'token'
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.getComments('uri');
                                return [2 /*return*/];
                            });
                        }); })];
                case 3:
                    _a.sent();
                    expect(result.current.pageToken).toBe('token');
                    expect(result.current.comments).toEqual([{ commentId: 'commentId1' }, { commentId: 'commentId2' }]);
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of getComment should call getComment request and set currentComment and loading', function () { return __awaiter(void 0, void 0, void 0, function () {
        var result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    result = setUp().result;
                    expect(result.current.currentComment).toBe(null);
                    expect(result.current.loading).toBe(false);
                    act(function () {
                        result.current.getComment('commentId');
                    });
                    expect(result.current.loading).toBe(true);
                    expect(getComment).toHaveBeenCalledWith({
                        collaborationPath: '123',
                        tenant: 'alenat',
                        commentId: 'commentId'
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.loading).toBe(false);
                    expect(result.current.currentComment).toEqual({
                        commentId: 'commentId'
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of createComment should call createComment request and update currentComment and commentsMap', function () { return __awaiter(void 0, void 0, void 0, function () {
        var comments, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    window.location.assign('https://tst-01.reltio.com/nui/alenat/profile?entityUri=entities%2F2jWtLtNc');
                    comments = [
                        {
                            commentId: 'id1',
                            status: 'open',
                            replies: 1
                        },
                        {
                            commentId: 'id2',
                            status: 'open',
                            replies: 2
                        }
                    ];
                    getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: comments }]);
                    createComment.mockResolvedValueOnce([{ commentId: 'commentId' }]);
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.commentsMap).toEqual({ uri1: comments });
                    expect(result.current.currentComment).toBe(null);
                    expect(result.current.sending).toBe(false);
                    act(function () {
                        result.current.createComment({
                            content: 'content',
                            namedUsers: [],
                            objectType: 'entity',
                            relatedObjectUris: ['uri1'],
                            uri: 'uri1'
                        });
                    });
                    expect(result.current.sending).toBe(true);
                    expect(createComment).toHaveBeenCalledWith({
                        collaborationPath: '123',
                        tenant: 'alenat',
                        data: {
                            objectId: 'uri1',
                            content: 'content',
                            relatedObjectUris: ['uri1'],
                            objectType: 'entity',
                            visibility: 'public',
                            namedUsers: [],
                            permanentLink: 'https://tst-01.reltio.com/nui/alenat/profile?entityUri=entities%2F2jWtLtNc&commentId=%7BcommentId%7D'
                        }
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.sending).toBe(false);
                    expect(result.current.currentComment).toEqual({
                        commentId: 'commentId'
                    });
                    expect(result.current.commentsMap).toEqual({
                        uri1: __spreadArray(__spreadArray([], comments, true), [{ commentId: 'commentId', replies: 0, status: 'open' }], false)
                    });
                    createComment.mockResolvedValueOnce([{ commentId: 'commentId2' }]);
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.createComment({
                                    content: 'content',
                                    namedUsers: [],
                                    objectType: 'entity',
                                    uri: 'uri2',
                                    relatedObjectUris: []
                                });
                                return [2 /*return*/];
                            });
                        }); })];
                case 3:
                    _a.sent();
                    expect(result.current.currentComment).toEqual({
                        commentId: 'commentId2'
                    });
                    expect(result.current.commentsMap).toEqual({
                        uri1: __spreadArray(__spreadArray([], comments, true), [{ commentId: 'commentId', replies: 0, status: 'open' }], false),
                        uri2: [{ commentId: 'commentId2', replies: 0, status: 'open' }]
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of createReply should call createReply request and update currentComment, commentsMap and comments', function () { return __awaiter(void 0, void 0, void 0, function () {
        var commentsCount, comments, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    commentsCount = [
                        { commentId: 'id1', status: 'open', replies: 1 },
                        { commentId: 'id2', status: 'open', replies: 2 }
                    ];
                    comments = [
                        { commentId: 'id1', content: 'first comment', status: 'open', replies: [] },
                        { commentId: 'id2', content: 'second comment', status: 'open', replies: [] }
                    ];
                    getCommentsCount.mockResolvedValue([{ objectId: 'uri1', comments: commentsCount }]);
                    getComments.mockResolvedValue({ items: comments });
                    getComment.mockResolvedValueOnce({
                        commentId: 'id2',
                        replies: []
                    });
                    createReply.mockResolvedValueOnce([{ content: 'reply message' }]);
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.getComments('uri');
                                result.current.getComment('commentId');
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.currentComment).toEqual({
                        commentId: 'id2',
                        replies: []
                    });
                    expect(result.current.commentsMap).toEqual({ uri1: commentsCount });
                    expect(result.current.comments).toEqual(comments);
                    expect(result.current.sending).toBe(false);
                    act(function () {
                        result.current.createReply({
                            content: 'reply message',
                            namedUsers: [],
                            commentId: 'id2',
                            action: 'none',
                            uri: 'uri1'
                        });
                    });
                    expect(result.current.sending).toBe(true);
                    expect(createReply).toHaveBeenCalledWith({
                        collaborationPath: '123',
                        tenant: 'alenat',
                        commentId: 'id2',
                        data: {
                            content: 'reply message',
                            action: 'none',
                            namedUsers: []
                        }
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.sending).toBe(false);
                    expect(result.current.currentComment).toEqual({
                        commentId: 'id2',
                        replies: [{ content: 'reply message' }]
                    });
                    expect(result.current.commentsMap).toEqual({
                        uri1: [commentsCount[0], { commentId: 'id2', status: 'open', replies: 3 }]
                    });
                    expect(result.current.comments).toEqual([
                        {
                            commentId: 'id1',
                            content: 'first comment',
                            status: 'open',
                            replies: []
                        },
                        {
                            commentId: 'id2',
                            content: 'second comment',
                            status: 'open',
                            replies: [{ content: 'reply message' }]
                        }
                    ]);
                    createReply.mockReturnValue(Promise.resolve([
                        {
                            content: '',
                            action: 'resolve'
                        }
                    ]));
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.createReply({
                                    content: '',
                                    namedUsers: [],
                                    commentId: 'id2',
                                    action: 'resolve',
                                    uri: 'uri1'
                                });
                                return [2 /*return*/];
                            });
                        }); })];
                case 3:
                    _a.sent();
                    expect(result.current.currentComment).toEqual(null);
                    expect(result.current.commentsMap).toEqual({
                        uri1: [commentsCount[0], { commentId: 'id2', status: 'resolved', replies: 4 }]
                    });
                    expect(result.current.comments).toEqual([
                        {
                            commentId: 'id1',
                            content: 'first comment',
                            status: 'open',
                            replies: []
                        },
                        {
                            commentId: 'id2',
                            content: 'second comment',
                            status: 'resolved',
                            replies: [{ content: 'reply message' }, { content: '', action: 'resolve' }]
                        }
                    ]);
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of resolveThread should call createReply request and update currentComment, commentsMap and comments', function () { return __awaiter(void 0, void 0, void 0, function () {
        var commentsCount, comments, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    commentsCount = [
                        { commentId: 'id1', status: 'open', replies: 1 },
                        { commentId: 'id2', status: 'open', replies: 2 }
                    ];
                    comments = [
                        { commentId: 'id1', status: 'open', content: 'first comment', replies: [] },
                        { commentId: 'id2', status: 'open', content: 'second comment', replies: [] }
                    ];
                    getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
                    getComment.mockResolvedValueOnce({ commentId: 'id2', replies: [] });
                    getComments.mockResolvedValue({ items: comments });
                    createReply.mockResolvedValueOnce([{ content: '', action: 'resolve' }]);
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.getComments('uri');
                                result.current.getComment('commentId');
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.commentsMap).toEqual({ uri1: commentsCount });
                    expect(result.current.currentComment).toEqual({
                        commentId: 'id2',
                        replies: []
                    });
                    expect(result.current.comments).toEqual(comments);
                    expect(result.current.sending).toBe(false);
                    act(function () {
                        result.current.resolveThread({ commentId: 'id2', uri: 'uri1' });
                    });
                    expect(result.current.sending).toBe(true);
                    expect(createReply).toHaveBeenCalledWith({
                        collaborationPath: '123',
                        tenant: 'alenat',
                        commentId: 'id2',
                        data: {
                            content: '',
                            action: 'resolve',
                            namedUsers: []
                        }
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.sending).toBe(false);
                    expect(result.current.currentComment).toBe(null);
                    expect(result.current.commentsMap).toEqual({
                        uri1: [commentsCount[0], { commentId: 'id2', status: 'resolved', replies: 3 }]
                    });
                    expect(result.current.comments).toEqual([
                        comments[0],
                        __assign(__assign({}, comments[1]), { status: 'resolved', replies: [{ content: '', action: 'resolve' }] })
                    ]);
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of reOpenThread should call createReply request and update currentComment and commentsMap', function () { return __awaiter(void 0, void 0, void 0, function () {
        var commentsCount, comments, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    commentsCount = [
                        { commentId: 'id1', status: 'open', replies: 1 },
                        { commentId: 'id2', status: 'resolved', replies: 2 }
                    ];
                    comments = [
                        { commentId: 'id1', status: 'open', content: 'first comment', replies: [] },
                        { commentId: 'id2', status: 'open', content: 'second comment', replies: [] }
                    ];
                    getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
                    getComment.mockResolvedValueOnce({ commentId: 'id2', replies: [] });
                    getComments.mockResolvedValue({
                        items: comments
                    });
                    createReply.mockResolvedValueOnce([{ content: '', action: 'reopen' }]);
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.getComments('uri');
                                result.current.getComment('commentId');
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.commentsMap).toEqual({ uri1: commentsCount });
                    expect(result.current.currentComment).toEqual({
                        commentId: 'id2',
                        replies: []
                    });
                    expect(result.current.comments).toEqual(comments);
                    expect(result.current.sending).toBe(false);
                    act(function () {
                        result.current.reOpenThread({ commentId: 'id2', uri: 'uri1' });
                    });
                    expect(result.current.sending).toBe(true);
                    expect(createReply).toHaveBeenCalledWith({
                        collaborationPath: '123',
                        tenant: 'alenat',
                        commentId: 'id2',
                        data: {
                            content: '',
                            action: 'reopen',
                            namedUsers: []
                        }
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.sending).toBe(false);
                    expect(result.current.currentComment).toEqual({
                        commentId: 'id2',
                        replies: [{ action: 'reopen', content: '' }]
                    });
                    expect(result.current.commentsMap).toEqual({
                        uri1: [commentsCount[0], { commentId: 'id2', status: 'open', replies: 3 }]
                    });
                    expect(result.current.comments).toEqual([
                        comments[0],
                        __assign(__assign({}, comments[1]), { status: 'open', replies: [{ content: '', action: 'reopen' }] })
                    ]);
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of clearCurrentComment should clear currentComment', function () { return __awaiter(void 0, void 0, void 0, function () {
        var result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.getComment('commentId');
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.currentComment).toEqual({
                        commentId: 'commentId'
                    });
                    act(function () {
                        result.current.clearCurrentComment();
                    });
                    expect(result.current.currentComment).toBe(null);
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of editComment should call editComment request and update comment  and comments', function () { return __awaiter(void 0, void 0, void 0, function () {
        var initialComment, editedComment, initialComments, editedComments, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    initialComment = {
                        commentId: 'id1',
                        content: 'initial comment',
                        namedUsers: [],
                        objectType: 'entity',
                        relatedObjectUris: ['uri1'],
                        visibility: 'public',
                        objectId: 'uri1',
                        replies: []
                    };
                    editedComment = __assign(__assign({}, initialComment), { content: 'edited comment' });
                    initialComments = [initialComment];
                    editedComments = [editedComment];
                    updateComment.mockResolvedValue(editedComment);
                    getComment.mockResolvedValue(initialComment);
                    getComments.mockResolvedValue({ items: initialComments });
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.getComment(initialComment.commentId);
                                result.current.getComments('uri');
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.currentComment).toEqual(initialComment);
                    expect(result.current.comments).toEqual(initialComments);
                    expect(result.current.sending).toBe(false);
                    act(function () {
                        result.current.editComment({
                            commentId: 'id1',
                            content: 'edited comment',
                            namedUsers: [],
                            objectType: 'entity',
                            relatedObjectUris: ['uri1'],
                            uri: 'uri1',
                            replies: []
                        });
                    });
                    expect(result.current.sending).toBe(true);
                    expect(updateComment).toHaveBeenCalledWith({
                        collaborationPath: '123',
                        tenant: 'alenat',
                        data: editedComment
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.sending).toBe(false);
                    expect(result.current.currentComment).toEqual(editedComment);
                    expect(result.current.comments).toEqual(editedComments);
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of deleteComment should call deleteComment request and update comment and commentsMap', function () { return __awaiter(void 0, void 0, void 0, function () {
        var commentsCount, comments, expectedCommentsCount, expectedComments, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    commentsCount = [
                        { commentId: 'id1', status: 'open', replies: 0 },
                        { commentId: 'id2', status: 'open', replies: 0 }
                    ];
                    comments = [
                        { commentId: 'id1', content: 'text 1', status: 'open', replies: [] },
                        { commentId: 'id2', content: 'text2', status: 'open', replies: [] }
                    ];
                    expectedCommentsCount = commentsCount.slice(1);
                    expectedComments = comments.slice(1);
                    getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
                    getComments.mockResolvedValueOnce({ items: comments });
                    deleteComment.mockResolvedValueOnce('');
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.getComments('uri');
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.comments).toEqual(comments);
                    expect(result.current.commentsMap).toEqual({ uri1: commentsCount });
                    expect(result.current.sending).toBe(false);
                    act(function () {
                        result.current.deleteComment({ commentId: 'id1', uri: 'uri1' });
                    });
                    expect(result.current.sending).toBe(true);
                    expect(deleteComment).toHaveBeenCalledWith({
                        collaborationPath: '123',
                        tenant: 'alenat',
                        commentId: 'id1'
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.sending).toBe(false);
                    expect(result.current.commentsMap).toEqual({
                        uri1: expectedCommentsCount
                    });
                    expect(result.current.comments).toEqual(expectedComments);
                    return [2 /*return*/];
            }
        });
    }); });
    it('should set commentsMap value as [] in case of createReply request returned uri thar does not exist in current commentsMap', function () { return __awaiter(void 0, void 0, void 0, function () {
        var commentsCount, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    commentsCount = [
                        { commentId: 'id1', status: 'open', replies: 1 },
                        { commentId: 'id2', status: 'open', replies: 2 }
                    ];
                    getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
                    createReply.mockResolvedValueOnce([{ content: 'reply message' }]);
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                Promise.resolve();
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.commentsMap).toEqual({ uri1: commentsCount });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, result.current.createReply({
                                            content: 'reply message',
                                            namedUsers: [],
                                            commentId: 'id2',
                                            action: 'none',
                                            uri: 'uri2'
                                        })];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.commentsMap).toEqual({
                        uri1: [commentsCount[0], { commentId: 'id2', status: 'open', replies: 2 }],
                        uri2: []
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of deleteReply should call deleteReply request and update comment and commentsMap', function () { return __awaiter(void 0, void 0, void 0, function () {
        var commentsCount, comments, expectedCommentsCount, expectedComments, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    commentsCount = [{ commentId: 'id1', status: 'open', replies: 1 }];
                    comments = [
                        { commentId: 'id1', content: 'text 1', status: 'open', replies: [{ namedUsers: [], replyId: 'replyId1' }] }
                    ];
                    expectedCommentsCount = [{ commentId: 'id1', status: 'open', replies: 0 }];
                    expectedComments = [{ commentId: 'id1', content: 'text 1', status: 'open', replies: [] }];
                    getCommentsCount.mockResolvedValueOnce([{ objectId: 'uri1', comments: commentsCount }]);
                    getComments.mockResolvedValue({ items: comments });
                    deleteReply.mockResolvedValueOnce('');
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.getComments('uri');
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.comments).toEqual(comments);
                    expect(result.current.commentsMap).toEqual({ uri1: commentsCount });
                    expect(result.current.sending).toBe(false);
                    act(function () {
                        result.current.deleteReply({
                            commentId: 'id1',
                            uri: 'uri1',
                            reply: comments[0].replies[0]
                        });
                    });
                    expect(result.current.sending).toBe(true);
                    expect(deleteReply).toHaveBeenCalledWith({
                        collaborationPath: '123',
                        tenant: 'alenat',
                        commentId: 'id1',
                        replyId: 'replyId1'
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.sending).toBe(false);
                    expect(result.current.commentsMap).toEqual({
                        uri1: expectedCommentsCount
                    });
                    expect(result.current.comments).toEqual(expectedComments);
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of editReply should call updateReply request and update comment  and comments', function () { return __awaiter(void 0, void 0, void 0, function () {
        var editedReplyContent, initialComment, editedReply, initialComments, commentWithEditedReply, result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    editedReplyContent = 'edited test reply content';
                    initialComment = {
                        commentId: 'id1',
                        content: 'initial comment',
                        namedUsers: [],
                        objectType: 'entity',
                        relatedObjectUris: ['uri1'],
                        permanentLink: '',
                        visibility: 'public',
                        objectId: 'uri1',
                        replies: [{ namedUsers: [], replyId: 'replyId1', content: 'test reply content' }]
                    };
                    editedReply = { namedUsers: [], replyId: 'replyId1', content: editedReplyContent };
                    initialComments = [initialComment];
                    commentWithEditedReply = __assign(__assign({}, initialComment), { replies: [editedReply] });
                    updateReply.mockResolvedValueOnce(editedReply);
                    getComment.mockResolvedValueOnce(initialComment);
                    getComments.mockResolvedValueOnce({ items: initialComments });
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.getComment(initialComment.commentId);
                                result.current.getComments('uri');
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.currentComment).toEqual(initialComment);
                    expect(result.current.comments).toEqual(initialComments);
                    expect(result.current.sending).toBe(false);
                    act(function () {
                        result.current.editReply({
                            commentId: 'id1',
                            content: editedReplyContent,
                            namedUsers: [],
                            replyId: editedReply.replyId
                        });
                    });
                    expect(result.current.sending).toBe(true);
                    expect(updateReply).toHaveBeenCalledWith({
                        collaborationPath: '123',
                        tenant: 'alenat',
                        commentId: 'id1',
                        replyId: editedReply.replyId,
                        data: {
                            content: editedReply.content,
                            namedUsers: editedReply.namedUsers
                        }
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.sending).toBe(false);
                    expect(result.current.currentComment).toEqual(commentWithEditedReply);
                    expect(result.current.comments).toEqual([commentWithEditedReply]);
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of updateCommentState should update collaborationStateMap by uri and commentUri', function () { return __awaiter(void 0, void 0, void 0, function () {
        var result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    result = setUp().result;
                    expect(result.current.getCommentState('attrUri', 'commentUri')).toEqual({});
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.updateCommentState('attrUri', 'commentUri', {
                                    value: 'value',
                                    plainTextValue: 'value',
                                    mentions: []
                                });
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.getCommentState('attrUri', 'commentUri')).toEqual({
                        value: 'value',
                        plainTextValue: 'value',
                        mentions: []
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.updateCommentState('attrUri', 'commentUri', { isEditing: true });
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.getCommentState('attrUri', 'commentUri')).toEqual({
                        value: 'value',
                        plainTextValue: 'value',
                        mentions: [],
                        isEditing: true
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of clearCommentState should clear collaborationStateMap by uri and commentUri', function () { return __awaiter(void 0, void 0, void 0, function () {
        var result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.updateCommentState('attrUri', 'commentUri', {
                                    value: 'value',
                                    plainTextValue: 'value',
                                    mentions: []
                                });
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.getCommentState('attrUri', 'commentUri')).toEqual({
                        value: 'value',
                        plainTextValue: 'value',
                        mentions: []
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.clearCommentState('attrUri', 'commentUri');
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.getCommentState('attrUri', 'commentUri')).toEqual({});
                    return [2 /*return*/];
            }
        });
    }); });
    it('call of getCommentState should return part of collaborationStateMap by uri and commentUri', function () { return __awaiter(void 0, void 0, void 0, function () {
        var result;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    result = setUp().result;
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.updateCommentState('attrUri1', 'commentUri1', {
                                    value: 'value1',
                                    plainTextValue: 'value1',
                                    mentions: []
                                });
                                return [2 /*return*/];
                            });
                        }); })];
                case 1:
                    _a.sent();
                    expect(result.current.getCommentState('attrUri1', 'commentUri1')).toEqual({
                        value: 'value1',
                        plainTextValue: 'value1',
                        mentions: []
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.updateCommentState('attrUri1', 'commentUri2', {
                                    value: 'value2',
                                    plainTextValue: 'value2',
                                    mentions: []
                                });
                                return [2 /*return*/];
                            });
                        }); })];
                case 2:
                    _a.sent();
                    expect(result.current.getCommentState('attrUri1', 'commentUri2')).toEqual({
                        value: 'value2',
                        plainTextValue: 'value2',
                        mentions: []
                    });
                    return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                result.current.updateCommentState('attrUri2', 'commentUri1', {
                                    value: 'value3',
                                    plainTextValue: 'value3',
                                    mentions: []
                                });
                                return [2 /*return*/];
                            });
                        }); })];
                case 3:
                    _a.sent();
                    expect(result.current.getCommentState('attrUri2', 'commentUri1')).toEqual({
                        value: 'value3',
                        plainTextValue: 'value3',
                        mentions: []
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    describe('totalCommentsCount behavior', function () {
        it('should not call getTotalCommentsCount if collaboration is not enabled', function () {
            var mdmValues = __assign(__assign({}, defaultMdmValues), { collaborationPath: undefined, isCollaborationEnabled: false });
            var result = setUp({ mdmValues: mdmValues }).result;
            expect(result.current.totalCommentsCount).toBe(null);
            expect(getTotalCommentsCount).not.toHaveBeenCalled();
        });
        it('should not call getTotalCommentsCount and update totalCommentsCount value if collaboration is enabled but needsTotalCount is false', function () { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        getTotalCommentsCount.mockResolvedValueOnce({ total: 15 });
                        setUp();
                        expect(getTotalCommentsCount).not.toHaveBeenCalled();
                        return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                                return __generator(this, function (_a) {
                                    switch (_a.label) {
                                        case 0: return [4 /*yield*/, Promise.resolve()];
                                        case 1:
                                            _a.sent();
                                            return [2 /*return*/];
                                    }
                                });
                            }); })];
                    case 1:
                        _a.sent();
                        expect(getTotalCommentsCount).not.toHaveBeenCalled();
                        return [2 /*return*/];
                }
            });
        }); });
        it('should call getTotalCommentsCount and update totalCommentsCount value if collaboration is enabled and needsTotalCount is true', function () { return __awaiter(void 0, void 0, void 0, function () {
            var result;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        getTotalCommentsCount.mockResolvedValueOnce({ total: 15 });
                        result = setUp({ props: { needsTotalCount: true } }).result;
                        expect(getTotalCommentsCount).toHaveBeenCalledWith({
                            relatedObjectUri: '1',
                            collaborationPath: '123',
                            tenant: 'alenat'
                        });
                        return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                                return __generator(this, function (_a) {
                                    switch (_a.label) {
                                        case 0: return [4 /*yield*/, Promise.resolve()];
                                        case 1:
                                            _a.sent();
                                            return [2 /*return*/];
                                    }
                                });
                            }); })];
                    case 1:
                        _a.sent();
                        expect(result.current.totalCommentsCount).toBe(15);
                        return [2 /*return*/];
                }
            });
        }); });
        it('should set totalCommentsCount as null in case of unsuccessful request', function () { return __awaiter(void 0, void 0, void 0, function () {
            var result;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        getTotalCommentsCount.mockRejectedValueOnce(new Error('Network error'));
                        result = setUp({ props: { needsTotalCount: true } }).result;
                        expect(getTotalCommentsCount).toHaveBeenCalled();
                        return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
                                return __generator(this, function (_a) {
                                    switch (_a.label) {
                                        case 0: return [4 /*yield*/, Promise.resolve()];
                                        case 1:
                                            _a.sent();
                                            return [2 /*return*/];
                                    }
                                });
                            }); })];
                    case 1:
                        _a.sent();
                        expect(result.current.totalCommentsCount).toBe(null);
                        return [2 /*return*/];
                }
            });
        }); });
    });
});
