"use strict";
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));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var react_2 = require("@testing-library/react");
var user_event_1 = __importDefault(require("@testing-library/user-event"));
var moment_1 = __importDefault(require("moment"));
var LocalizationProvider_1 = require("@mui/x-date-pickers/LocalizationProvider");
var AdapterMoment_1 = require("@mui/x-date-pickers/AdapterMoment");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var MdmModuleContext_1 = require("../../../../../contexts/MdmModuleContext");
var CommentDialogContext_1 = require("../../../../../contexts/CommentDialogContext");
var DataChangeRequestTaskCard_1 = require("./DataChangeRequestTaskCard");
var WorkflowTasksContext_1 = require("../../../../../contexts/WorkflowTasksContext");
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getDataChangeRequest: jest.fn(), getEntitiesByUris: jest.fn(), runTaskAction: jest.fn() })); });
var onActionSuccess = jest.fn();
var workflowTaskContextValue = { onActionSuccess: onActionSuccess };
describe('DataChangeRequestTaskCard tests', function () {
    var _a, _b;
    var metadata = {
        entityTypes: [
            {
                uri: 'configuration/entityTypes/Company',
                label: 'Company',
                description: 'Company',
                extendsTypeURI: 'configuration/entityTypes/Organization',
                attributes: [
                    {
                        label: 'Activation Date',
                        name: 'ActivationDate',
                        type: 'String',
                        uri: 'configuration/entityTypes/Company/attributes/ActivationDate'
                    },
                    {
                        label: 'Name',
                        name: 'Name',
                        type: 'String',
                        uri: 'configuration/entityTypes/Company/attributes/Name'
                    },
                    {
                        dependentLookupCode: 'COUNTRY_CD',
                        label: 'Country Code',
                        name: 'CountryCode',
                        type: 'String',
                        uri: 'configuration/entityTypes/Company/attributes/CountryCode'
                    },
                    {
                        label: 'Address',
                        name: 'Address',
                        type: 'Reference',
                        uri: 'configuration/entityTypes/Company/attributes/Address',
                        referencedAttributeURIs: ['configuration/entityTypes/Location/attributes/City'],
                        referencedEntityTypeURI: 'configuration/entityTypes/Location'
                    },
                    {
                        label: 'NestedFirstLevel',
                        name: 'NestedFirstLevel',
                        type: 'Nested',
                        uri: 'configuration/entityTypes/Company/attributes/NestedFirstLevel',
                        attributes: [
                            {
                                label: 'NestedSecondLevel',
                                name: 'NestedSecondLevel',
                                type: 'Nested',
                                uri: 'configuration/entityTypes/Company/attributes/NestedFirstLevel/attributes/NestedSecondLevel',
                                attributes: [
                                    {
                                        label: 'FifthLevelSimple4',
                                        name: 'FifthLevelSimple4',
                                        type: 'String',
                                        uri: 'configuration/entityTypes/Company/attributes/NestedFirstLevel/attributes/NestedSecondLevel/attributes/FifthLevelSimple4'
                                    },
                                    {
                                        label: 'FifthLevelSimple5',
                                        name: 'FifthLevelSimple5',
                                        type: 'String',
                                        uri: 'configuration/entityTypes/Company/attributes/NestedFirstLevel/attributes/NestedSecondLevel/attributes/FifthLevelSimple5'
                                    }
                                ]
                            }
                        ]
                    }
                ],
                abstract: false
            },
            {
                uri: 'configuration/entityTypes/Location',
                label: 'Address',
                attributes: [
                    {
                        label: 'City',
                        name: 'City',
                        type: 'String',
                        uri: 'configuration/entityTypes/Location/attributes/City'
                    }
                ],
                abstract: false
            }
        ],
        relationTypes: [
            {
                uri: 'configuration/relationTypes/Managed',
                label: 'Managed',
                startObject: {
                    uri: 'configuration/relationTypes/Managed/startObject',
                    objectTypeURI: 'configuration/entityTypes/Company'
                },
                endObject: {
                    uri: 'configuration/relationTypes/Managed/endObject',
                    objectTypeURI: 'configuration/entityTypes/Company'
                },
                attributes: [],
                direction: 'directed'
            }
        ]
    };
    var entityUri = 'entities/00COBWl';
    var relationUri = 'relations/07VxtSE';
    var userName = 'eugeny.sokolov';
    var priorityClass = 'Medium';
    var displayName = 'DCR Review';
    var processDefinitionDisplayName = 'Data Change Request Review';
    var dcrId = '0kCnzFE';
    var dcrUri = "changeRequests/".concat(dcrId);
    var dueDate = 1731825314640;
    var newStartDate = (0, moment_1.default)('11/15/2024', 'MM/DD/YYYY').valueOf();
    var defaultTask = {
        assignee: userName,
        processInstanceId: '60260030',
        processType: 'dataChangeRequestReview',
        objectURIs: [dcrUri, entityUri, relationUri],
        suspended: false,
        createdBy: userName,
        priorityClass: priorityClass,
        taskType: 'dcrReview',
        createTime: 1731652514639,
        dueDate: dueDate,
        taskId: '60260042',
        displayName: displayName,
        processDefinitionDisplayName: processDefinitionDisplayName
    };
    var entityLabel = 'EntityLabel';
    var relationEntityLabel = 'RelationEntityLabel';
    var refEntityLabel = 'RefEntityLabel';
    var oldNameValue = 'oldNameValue';
    var newNameValue = 'newNameValue';
    var dcr = {
        uri: 'changeRequests/0kCnzFE',
        createdBy: userName,
        createdTime: 1731652509123,
        updatedBy: userName,
        updatedTime: 1731652511713,
        changes: (_a = {},
            _a[entityUri] = [
                {
                    id: '0kCo7lk',
                    type: mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE,
                    createdTime: 1731652511713,
                    createdBy: userName,
                    attributePath: 'Name/xhGw4BJ',
                    oldValue: {
                        value: oldNameValue
                    },
                    newValue: {
                        value: newNameValue
                    },
                    attributeType: 'configuration/entityTypes/Company/attributes/Name'
                }
            ],
            _a[relationUri] = [
                {
                    id: '0kCnuyy',
                    type: mdm_sdk_1.DCRTypes.UPDATE_START_DATE,
                    createdTime: 1731652509123,
                    createdBy: userName,
                    newValue: [newStartDate]
                }
            ],
            _a),
        objectsInfo: (_b = {},
            _b[entityUri] = {
                type: 'configuration/entityTypes/Company',
                label: entityLabel
            },
            _b[relationUri] = {
                type: 'configuration/relationTypes/Managed',
                startObjectUri: 'entities/07AWt2z',
                startObjectLabel: relationEntityLabel,
                endObjectUri: entityUri,
                endObjectLabel: entityLabel
            },
            _b['entities/19emZkLd'] = {
                type: 'configuration/entityTypes/Location',
                label: refEntityLabel
            },
            _b),
        type: 'configuration/changeRequestTypes/default',
        state: 'AWAITING_REVIEW'
    };
    var entities = [
        {
            uri: 'entities/07AWt2z',
            type: 'configuration/entityTypes/Company',
            label: relationEntityLabel
        }
    ];
    var tenant = { id: 't1', name: 't1' };
    var workflowPath = 'workflowPath';
    var workflowEnvironmentUrl = 'workflowEnvironmentUrl';
    var mdmDefaultValues = {
        metadata: metadata,
        user: {
            username: userName
        },
        tenant: tenant,
        workflowPath: workflowPath,
        workflowEnvironmentUrl: workflowEnvironmentUrl,
        entity: { uri: entityUri }
    };
    var setUp = function (_a) {
        var _b = _a === void 0 ? {} : _a, _c = _b.task, task = _c === void 0 ? defaultTask : _c, _d = _b.mdmValues, mdmValues = _d === void 0 ? mdmDefaultValues : _d;
        var user = user_event_1.default.setup();
        var Providers = function (_a) {
            var children = _a.children;
            return (react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues },
                react_1.default.createElement(LocalizationProvider_1.LocalizationProvider, { dateAdapter: AdapterMoment_1.AdapterMoment },
                    react_1.default.createElement(WorkflowTasksContext_1.WorkflowTasksContext.Provider, { value: workflowTaskContextValue },
                        react_1.default.createElement(CommentDialogContext_1.CommentDialogProvider, null, children)))));
        };
        return __assign(__assign({}, (0, react_2.render)(react_1.default.createElement(DataChangeRequestTaskCard_1.DataChangeRequestTaskCard, { task: task }), { wrapper: Providers })), { user: user });
    };
    beforeAll(function () {
        mdm_sdk_1.getEntitiesByUris.mockResolvedValue(entities);
        mdm_sdk_1.runTaskAction.mockResolvedValue(null);
    });
    afterEach(function () {
        jest.clearAllMocks();
    });
    it('should render main parts', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, changesContainers;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    mdm_sdk_1.getDataChangeRequest.mockResolvedValue(dcr);
                    user = setUp().user;
                    expect(react_2.screen.getByTestId('SvgDcrTaskIcon')).toBeInTheDocument();
                    expect(react_2.screen.getByText(processDefinitionDisplayName)).toBeInTheDocument();
                    expect(react_2.screen.getByText((0, moment_1.default)(dueDate).format('MM/DD/YYYY'))).toBeInTheDocument();
                    expect(react_2.screen.getByText(dcrId)).toBeInTheDocument();
                    expect(react_2.screen.getByText(userName)).toBeInTheDocument();
                    expect(react_2.screen.getByText(displayName)).toBeInTheDocument();
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('collapse-button'))];
                case 1:
                    _a.sent();
                    changesContainers = react_2.screen.getAllByTestId('changes-container');
                    expect(changesContainers).toHaveLength(2);
                    expect((0, react_2.within)(changesContainers[0]).getByText('Name')).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[0]).getByText(entityLabel)).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[0]).getByText(new RegExp("^".concat(oldNameValue, ".*").concat(newNameValue, "$")))).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[0]).getByTestId('arrow-right')).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[0]).getByText(mdm_sdk_1.DCROperationTypes.EDITED)).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[1]).getByText(relationEntityLabel)).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[1]).getByText('Relationships')).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[1]).getByText('Managed')).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[1]).getByText(entityLabel)).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[1]).getByText('Start date')).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[1]).getByText((0, moment_1.default)(newStartDate).format('MM/DD/YYYY'))).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[1]).getByText(mdm_sdk_1.DCROperationTypes.ADDED)).toBeInTheDocument();
                    expect((0, react_2.within)(changesContainers[1]).queryByTestId('arrow-right')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should work correctly with nested attributes', function () { return __awaiter(void 0, void 0, void 0, function () {
        var nestedAttrName, subNestedAttrName, subSubNestedAttr1, addedNestedValue, changedWithNested, dcrWithNested, user;
        var _a, _b;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    nestedAttrName = 'NestedFirstLevel';
                    subNestedAttrName = 'NestedSecondLevel';
                    subSubNestedAttr1 = 'FifthLevelSimple4';
                    addedNestedValue = 'addedNestedValue';
                    changedWithNested = (_a = {},
                        _a[entityUri] = [
                            {
                                id: '0kCoGIG',
                                type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                                createdTime: 1731652511713,
                                createdBy: userName,
                                attributePath: nestedAttrName,
                                newValue: {
                                    value: (_b = {},
                                        _b[subNestedAttrName] = [
                                            {
                                                value: {
                                                    FifthLevelSimple4: [
                                                        {
                                                            value: addedNestedValue
                                                        }
                                                    ]
                                                }
                                            }
                                        ],
                                        _b)
                                },
                                attributeType: 'configuration/entityTypes/Company/attributes/NestedFirstLevel'
                            }
                        ],
                        _a);
                    dcrWithNested = __assign(__assign({}, dcr), { changes: changedWithNested });
                    mdm_sdk_1.getDataChangeRequest.mockResolvedValue(dcrWithNested);
                    user = setUp().user;
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('collapse-button'))];
                case 1:
                    _c.sent();
                    expect(react_2.screen.getByText(nestedAttrName)).toBeInTheDocument();
                    expect(react_2.screen.getByText(subNestedAttrName)).toBeInTheDocument();
                    expect(react_2.screen.getByText(subSubNestedAttr1)).toBeInTheDocument();
                    expect(react_2.screen.getByText(mdm_sdk_1.DCROperationTypes.ADDED)).toBeInTheDocument();
                    expect(react_2.screen.queryByTestId('arrow-right')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should work correctly with reference attributes', function () { return __awaiter(void 0, void 0, void 0, function () {
        var attributePath, refAttributeName, addedRefValue, changedWithRef, dcrWithRef, user;
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    attributePath = 'Address';
                    refAttributeName = 'City';
                    addedRefValue = 'addedRefValue';
                    changedWithRef = (_a = {},
                        _a[entityUri] = [
                            {
                                id: '0kCoC20',
                                type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
                                createdTime: 1731652511713,
                                createdBy: 'eugeny.sokolov',
                                attributePath: attributePath,
                                newValue: {
                                    value: {
                                        City: [
                                            {
                                                value: addedRefValue
                                            }
                                        ]
                                    },
                                    refEntity: {
                                        objectURI: 'entities/19emZkLd'
                                    }
                                },
                                attributeType: 'configuration/entityTypes/Company/attributes/Address'
                            }
                        ],
                        _a);
                    dcrWithRef = __assign(__assign({}, dcr), { changes: changedWithRef });
                    mdm_sdk_1.getDataChangeRequest.mockResolvedValue(dcrWithRef);
                    user = setUp().user;
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('collapse-button'))];
                case 1:
                    _b.sent();
                    expect(react_2.screen.getByText(attributePath)).toBeInTheDocument();
                    expect(react_2.screen.getByText(refAttributeName)).toBeInTheDocument();
                    expect(react_2.screen.getByText(refEntityLabel)).toBeInTheDocument();
                    expect(react_2.screen.getByText(addedRefValue)).toBeInTheDocument();
                    expect(react_2.screen.getByText(mdm_sdk_1.DCROperationTypes.ADDED)).toBeInTheDocument();
                    expect(react_2.screen.queryByTestId('arrow-right')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should render ShowMoreLink if length of merged changes more than 3', function () { return __awaiter(void 0, void 0, void 0, function () {
        var bigChanges, dcrWithBigChanges, user;
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    bigChanges = (_a = {},
                        _a[entityUri] = __spreadArray(__spreadArray([], dcr.changes[entityUri], true), [
                            {
                                attributePath: 'CountryCode',
                                attributeType: 'configuration/entityTypes/Company/attributes/CountryCode',
                                id: '41cb3c0i',
                                newValue: { value: 'Bahamas', lookupCode: 'BS', lookupRawValue: 'BS', pin: true },
                                type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE
                            },
                            {
                                attributePath: 'ActivationDate',
                                attributeType: 'configuration/entityTypes/Company/attributes/ActivationDate',
                                id: '41cb3t3k',
                                newValue: { value: '12.10.2011' },
                                type: mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE
                            },
                            {
                                attributePath: 'CountryCode/3AqlrpfGa',
                                attributeType: 'configuration/entityTypes/Company/attributes/CountryCode',
                                id: '41cb3gGy',
                                newValue: { value: 'Chile', lookupCode: 'CL', lookupRawValue: 'Chile', pin: true },
                                oldValue: { value: 'Chile', lookupCode: 'CL', lookupRawValue: 'Chile', pin: true },
                                type: mdm_sdk_1.DCRTypes.IGNORE_ATTRIBUTE
                            }
                        ], false),
                        _a);
                    dcrWithBigChanges = __assign(__assign({}, dcr), { changes: bigChanges });
                    mdm_sdk_1.getDataChangeRequest.mockResolvedValue(dcrWithBigChanges);
                    user = setUp().user;
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('collapse-button'))];
                case 1:
                    _b.sent();
                    expect(react_2.screen.getByText('Country Code')).toBeInTheDocument();
                    expect(react_2.screen.getByText('Bahamas (BS)')).toBeInTheDocument();
                    expect(react_2.screen.getByText('Activation Date')).toBeInTheDocument();
                    expect(react_2.screen.getByText('12.10.2011')).toBeInTheDocument();
                    expect(react_2.screen.getByText('Name')).toBeInTheDocument();
                    expect(react_2.screen.queryByText('Chile (CL)')).not.toBeInTheDocument();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('View 1 more suggestions'))];
                case 2:
                    _b.sent();
                    expect(react_2.screen.getByText('Chile (CL)')).toBeInTheDocument();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('View less suggestions'))];
                case 3:
                    _b.sent();
                    expect(react_2.screen.queryByText('Chile (CL)')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should not show Review DCR button when current entity is a new created entity by DCR', function () { return __awaiter(void 0, void 0, void 0, function () {
        var mdmValues;
        return __generator(this, function (_a) {
            mdmValues = __assign(__assign({}, mdmDefaultValues), { reviewDCREnabled: true, entity: { uri: "".concat(dcrUri, "/changes/").concat(entityUri) } });
            mdm_sdk_1.getDataChangeRequest.mockResolvedValue(dcr);
            setUp({ mdmValues: mdmValues });
            expect(react_2.screen.queryByRole('button', { name: 'Review DCR' })).not.toBeInTheDocument();
            return [2 /*return*/];
        });
    }); });
    it('should create correct link for new entity', function () { return __awaiter(void 0, void 0, void 0, function () {
        var changesWithNewEntity, dcrWithNewEntity, user, linkElement, href;
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    changesWithNewEntity = (_a = {},
                        _a[entityUri] = [
                            {
                                id: '3aMaA7ds',
                                type: mdm_sdk_1.DCRTypes.CREATE_ENTITY,
                                createdBy: 'alan.khugaev',
                                newValue: {
                                    uri: 'entities/1WNHTsJw',
                                    type: 'configuration/entityTypes/HCA',
                                    attributes: {
                                        CountryCode: [
                                            {
                                                value: 'Germany',
                                                lookupCode: 'DE',
                                                lookupRawValue: 'DE'
                                            }
                                        ],
                                        ActivationDate: [
                                            {
                                                value: '12.10.2011'
                                            }
                                        ]
                                    },
                                    isFavorite: false
                                }
                            }
                        ],
                        _a);
                    dcrWithNewEntity = __assign(__assign({}, dcr), { changes: changesWithNewEntity });
                    mdm_sdk_1.getDataChangeRequest.mockResolvedValue(dcrWithNewEntity);
                    user = setUp().user;
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('collapse-button'))];
                case 1:
                    _b.sent();
                    linkElement = react_2.screen.getByRole('link');
                    href = linkElement.getAttribute('href');
                    expect(href).toMatch(new RegExp("".concat(dcrUri, "/changes/").concat(entityUri, "$")));
                    return [2 /*return*/];
            }
        });
    }); });
    describe('Required comments', function () {
        it('should show comment dialog when user runs action and comment is required', function () { return __awaiter(void 0, void 0, void 0, function () {
            var task, user, dialog, comment, commentInput;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        task = __assign(__assign({}, defaultTask), { possibleActions: [
                                {
                                    action: 'Approve',
                                    label: 'Approve',
                                    commentRequired: true
                                },
                                {
                                    action: 'Reject',
                                    label: 'Reject',
                                    commentRequired: false
                                }
                            ] });
                        mdm_sdk_1.getDataChangeRequest.mockResolvedValue(dcr);
                        user = setUp({ task: task }).user;
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('task-actions'))];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByText(task.possibleActions[0].label))];
                    case 2:
                        _a.sent();
                        expect(mdm_sdk_1.runTaskAction).not.toHaveBeenCalled();
                        dialog = react_2.screen.getAllByRole('presentation')[1];
                        expect((0, react_2.within)(dialog).getByText('Please provide a comment for your action')).toBeInTheDocument();
                        expect((0, react_2.within)(dialog).getByText('Type a comment')).toBeInTheDocument();
                        expect((0, react_2.within)(dialog).getByText('Cancel')).toBeInTheDocument();
                        expect((0, react_2.within)(dialog).getByText('Done')).toBeInTheDocument();
                        comment = 'Some comment';
                        commentInput = react_2.screen.getAllByRole('textbox')[0];
                        return [4 /*yield*/, user.click(commentInput)];
                    case 3:
                        _a.sent();
                        return [4 /*yield*/, user.paste(comment)];
                    case 4:
                        _a.sent();
                        return [4 /*yield*/, user.click((0, react_2.within)(dialog).getByText('Done'))];
                    case 5:
                        _a.sent();
                        expect(react_2.screen.queryByText('Please provide a comment for your action')).not.toBeInTheDocument();
                        expect(mdm_sdk_1.runTaskAction).toHaveBeenCalledWith({
                            workflowPath: workflowPath,
                            environment: workflowEnvironmentUrl,
                            tenant: tenant.id,
                            taskId: task.taskId,
                            action: task.possibleActions[0].action,
                            processInstanceComment: comment
                        });
                        return [2 /*return*/];
                }
            });
        }); });
    });
});
