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 i18n from 'ui-i18n';
import { identity } from 'ramda';
import { render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { createTheme } from '@mui/material/styles';
import { ThemeProvider } from '@mui/styles';
import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { runTaskAction, getTaskById, addCommentForTask } from '@reltio/mdm-sdk';
import { theme } from '../../../../../constants';
import { MdmModuleProvider } from '../../../../../contexts/MdmModuleContext';
import { WorkflowTasksContext } from '../../../../../contexts/WorkflowTasksContext';
import { CommentDialogProvider } from '../../../../../contexts/CommentDialogContext';
import { ErrorPopup } from '../../../../../ErrorPopup';
import { getDefaultTask } from './task.test-data';
import { GenericWorkflowTaskCard } from './GenericWorkflowTaskCard';
import { ReviewDCRButton } from '../../../ReviewDCRButton';
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { runTaskAction: jest.fn().mockReturnValue(Promise.resolve()), getAssigneeForTask: jest.fn().mockResolvedValue({ data: ['assignee1', 'assignee2'] }), addCommentForTask: jest.fn().mockResolvedValue({ status: 'success' }), getTaskById: jest.fn() })); });
var onActionSuccess = jest.fn();
var workflowTaskContextValue = { onActionSuccess: onActionSuccess };
var defaultUser = {
    userPermissions: {
        permissions: {
            'workflow:data.process': {
                READ: ['t1'],
                UPDATE: ['t1']
            },
            'workflow:data.tasks': {
                UPDATE: ['t1']
            }
        },
        permissionsByService: {},
        roles: {}
    },
    username: 'egorshkov'
};
var tenant = { id: 't1', name: 't1' };
var workflowPath = 'workflowPath';
var workflowEnvironmentUrl = 'workflowEnvironmentUrl';
var defaultMdmValues = {
    user: defaultUser,
    tenant: tenant,
    workflowPath: workflowPath,
    workflowEnvironmentUrl: workflowEnvironmentUrl
};
var errorSet = jest.fn();
var defaultTask = getDefaultTask();
var setUp = function (_a) {
    var _b = _a === void 0 ? {} : _a, _c = _b.mdmValues, mdmValues = _c === void 0 ? defaultMdmValues : _c, _d = _b.task, task = _d === void 0 ? defaultTask : _d, customActionsSlot = _b.customActionsSlot;
    var user = userEvent.setup();
    return __assign(__assign({}, render(React.createElement(MdmModuleProvider, { values: mdmValues, actions: { errorSet: errorSet } },
        React.createElement(ThemeProvider, { theme: createTheme(theme) },
            React.createElement(LocalizationProvider, { dateAdapter: AdapterMoment },
                React.createElement(CommentDialogProvider, null,
                    React.createElement(WorkflowTasksContext.Provider, { value: workflowTaskContextValue },
                        React.createElement(GenericWorkflowTaskCard, { task: task, customActionsSlot: customActionsSlot },
                            React.createElement("div", { className: "someChildren" }, "some children")),
                        React.createElement(ErrorPopup, { showErrorFromStore: true })))))))), { user: user });
};
var checkAlwaysVisibleElements = function (task) {
    var processDefinitionDisplayName = task.processDefinitionDisplayName, createdBy = task.createdBy, createTime = task.createTime, dueDate = task.dueDate, displayName = task.displayName;
    expect(screen.getByText(processDefinitionDisplayName)).toBeInTheDocument();
    expect(screen.getByTestId('info-block')).toHaveTextContent("Created by: ".concat(createdBy, " on ").concat(createTime));
    expect(screen.getByText(String(dueDate))).toBeInTheDocument();
    expect(screen.getByTestId('info-block')).toHaveTextContent("Step: ".concat(displayName));
    expect(screen.getByTestId('collapse-button')).toBeInTheDocument();
};
jest.spyOn(i18n, 'date').mockImplementation(identity);
describe('GenericWorkflowTaskCard tests', function () {
    afterEach(function () {
        jest.clearAllMocks();
    });
    it('should render elements in collapsed mode', function () {
        var _a, _b;
        setUp();
        checkAlwaysVisibleElements(defaultTask);
        expect(screen.getByTestId('task-actions')).toBeInTheDocument();
        expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
        expect(screen.queryByText('Comments')).not.toBeInTheDocument();
        expect(screen.getByText("".concat((_a = defaultTask.processInstanceComments) === null || _a === void 0 ? void 0 : _a.length))).toBeInTheDocument();
        (_b = defaultTask.processInstanceComments) === null || _b === void 0 ? void 0 : _b.forEach(function (comment) {
            expect(screen.queryByText(comment.message)).not.toBeInTheDocument();
        });
    });
    it('should render elements in expanded mode', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user;
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    user = setUp().user;
                    checkAlwaysVisibleElements(defaultTask);
                    return [4 /*yield*/, user.click(screen.getByTestId('collapse-button'))];
                case 1:
                    _b.sent();
                    expect(screen.getByTestId('task-actions')).toBeInTheDocument();
                    expect(screen.getByText('Comments')).toBeInTheDocument();
                    expect(screen.getByText('Priority')).toBeInTheDocument();
                    expect(screen.getByText('Due date')).toBeInTheDocument();
                    expect(screen.getByText('Assigned to')).toBeInTheDocument();
                    expect(screen.getByText('some children')).toBeInTheDocument();
                    expect(screen.getByText(defaultTask.processInstanceComments[0].message)).toBeInTheDocument();
                    expect(screen.getByPlaceholderText('Write a comment')).toBeInTheDocument();
                    expect(screen.getByText((_a = defaultTask.preferredAction) === null || _a === void 0 ? void 0 : _a.label)).toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should disable controls for closed task', function () { return __awaiter(void 0, void 0, void 0, function () {
        var anotherTask, user, inputs, _i, inputs_1, input;
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    anotherTask = getDefaultTask();
                    anotherTask.isOpen = false;
                    user = setUp({ task: anotherTask }).user;
                    checkAlwaysVisibleElements(anotherTask);
                    expect(screen.queryByTestId('task-actions')).not.toBeInTheDocument();
                    return [4 /*yield*/, user.click(screen.getByTestId('collapse-button'))];
                case 1:
                    _b.sent();
                    inputs = screen.getAllByRole('textbox');
                    for (_i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {
                        input = inputs_1[_i];
                        expect(input).toBeDisabled();
                    }
                    expect(screen.queryByPlaceholderText('Write a comment')).not.toBeInTheDocument();
                    expect(screen.queryByText((_a = anotherTask.preferredAction) === null || _a === void 0 ? void 0 : _a.label)).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should render dcr id if it exists in task', function () {
        var anotherTask = getDefaultTask();
        anotherTask.objectURIs = __spreadArray(['changeRequests/123'], defaultTask.objectURIs, true);
        setUp({ task: anotherTask });
        expect(screen.getByTestId('info-block')).toHaveTextContent('DCR ID: 123');
    });
    it('should not render comments info if there are no comments for task', function () { return __awaiter(void 0, void 0, void 0, function () {
        var anotherTask, user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    anotherTask = getDefaultTask();
                    anotherTask.processInstanceComments = [];
                    user = setUp().user;
                    expect(screen.queryByText("".concat(anotherTask.processInstanceComments.length))).not.toBeInTheDocument();
                    return [4 /*yield*/, user.click(screen.getByTestId('collapse-button'))];
                case 1:
                    _a.sent();
                    expect(screen.queryByText("".concat(anotherTask.processInstanceComments.length))).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should not render comments if there are no permissions to comment task', function () { return __awaiter(void 0, void 0, void 0, function () {
        var newUser, mdmValues, user;
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    newUser = __assign(__assign({}, defaultUser), { userPermissions: __assign(__assign({}, defaultUser.userPermissions), { permissions: {
                                'workflow:data.process': {
                                    UPDATE: ['t1'],
                                    READ: ['t2']
                                },
                                'workflow:data.tasks': {
                                    UPDATE: ['t1']
                                }
                            } }) });
                    mdmValues = __assign(__assign({}, defaultMdmValues), { user: newUser });
                    user = setUp({ mdmValues: mdmValues }).user;
                    return [4 /*yield*/, user.click(screen.getByTestId('collapse-button'))];
                case 1:
                    _b.sent();
                    expect(screen.queryByText(defaultTask.processInstanceComments[0].message)).not.toBeInTheDocument();
                    expect(screen.queryByPlaceholderText('Write a comment')).not.toBeInTheDocument();
                    expect(screen.queryByText((_a = defaultTask.preferredAction) === null || _a === void 0 ? void 0 : _a.label)).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should not render task actions menu if task is assigned to not current user', function () { return __awaiter(void 0, void 0, void 0, function () {
        var anotherTask;
        return __generator(this, function (_a) {
            anotherTask = getDefaultTask();
            anotherTask.assignee = 'anotherUser';
            setUp({ task: anotherTask });
            expect(screen.queryByTestId('task-actions')).not.toBeInTheDocument();
            return [2 /*return*/];
        });
    }); });
    it('should call onActionSuccess and runTaskAction with comment on action selecting in comment section', function () { return __awaiter(void 0, void 0, void 0, function () {
        var newCommentMessage, user;
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    newCommentMessage = 'new comment message';
                    user = setUp().user;
                    return [4 /*yield*/, user.click(screen.getByTestId('collapse-button'))];
                case 1:
                    _b.sent();
                    return [4 /*yield*/, user.type(screen.getByPlaceholderText('Write a comment'), newCommentMessage)];
                case 2:
                    _b.sent();
                    return [4 /*yield*/, user.click(screen.getByRole('button', { name: (_a = defaultTask.preferredAction) === null || _a === void 0 ? void 0 : _a.label }))];
                case 3:
                    _b.sent();
                    return [4 /*yield*/, user.click(screen.getByTestId("reltio-profile-select-mode-".concat(defaultTask.possibleActions[1].label)))];
                case 4:
                    _b.sent();
                    expect(runTaskAction).toHaveBeenCalledWith({
                        workflowPath: workflowPath,
                        environment: workflowEnvironmentUrl,
                        tenant: tenant.id,
                        taskId: defaultTask.taskId,
                        action: defaultTask.possibleActions[1].action,
                        processInstanceComment: newCommentMessage
                    });
                    expect(onActionSuccess).toHaveBeenCalledWith(defaultTask.possibleActions[1].action);
                    return [2 /*return*/];
            }
        });
    }); });
    it('should call onActionSuccess and runTaskAction without comment on action selecting in comment section if comment input is empty', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user;
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    user = setUp().user;
                    return [4 /*yield*/, user.click(screen.getByTestId('collapse-button'))];
                case 1:
                    _b.sent();
                    return [4 /*yield*/, user.click(screen.getByRole('button', { name: (_a = defaultTask.preferredAction) === null || _a === void 0 ? void 0 : _a.label }))];
                case 2:
                    _b.sent();
                    return [4 /*yield*/, user.click(screen.getByTestId("reltio-profile-select-mode-".concat(defaultTask.possibleActions[1].label)))];
                case 3:
                    _b.sent();
                    expect(runTaskAction).toHaveBeenCalledWith({
                        workflowPath: workflowPath,
                        environment: workflowEnvironmentUrl,
                        tenant: tenant.id,
                        taskId: defaultTask.taskId,
                        action: defaultTask.possibleActions[1].action,
                        processInstanceComment: null
                    });
                    expect(onActionSuccess).toHaveBeenCalledWith(defaultTask.possibleActions[1].action);
                    return [2 /*return*/];
            }
        });
    }); });
    it('should call onActionSuccess and runTaskAction on action selecting in task actions menu', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp().user;
                    return [4 /*yield*/, user.click(screen.getByTestId('task-actions'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click(screen.getByText(defaultTask.possibleActions[1].label))];
                case 2:
                    _a.sent();
                    expect(runTaskAction).toHaveBeenCalledWith({
                        workflowPath: workflowPath,
                        environment: workflowEnvironmentUrl,
                        tenant: tenant.id,
                        taskId: defaultTask.taskId,
                        action: defaultTask.possibleActions[1].action,
                        processInstanceComment: null
                    });
                    expect(onActionSuccess).toHaveBeenCalledWith(defaultTask.possibleActions[1].action);
                    return [2 /*return*/];
            }
        });
    }); });
    it('should not call runTaskAction in case of missing workflow path', function () { return __awaiter(void 0, void 0, void 0, function () {
        var mdmValues, user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    mdmValues = __assign(__assign({}, defaultMdmValues), { workflowPath: '' });
                    user = setUp({ mdmValues: mdmValues }).user;
                    return [4 /*yield*/, user.click(screen.getByTestId('task-actions'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click(screen.getByText(defaultTask.possibleActions[0].label))];
                case 2:
                    _a.sent();
                    expect(runTaskAction).not.toHaveBeenCalled();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should show error if update request was unsuccessful', function () { return __awaiter(void 0, void 0, void 0, function () {
        var apiError, user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    apiError = { error: { errorMessage: 'error!' } };
                    runTaskAction.mockImplementation(function () { return Promise.reject(apiError); });
                    user = setUp().user;
                    return [4 /*yield*/, user.click(screen.getByTestId('task-actions'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click(screen.getByText(defaultTask.possibleActions[1].label))];
                case 2:
                    _a.sent();
                    expect(runTaskAction).toHaveBeenCalledWith({
                        workflowPath: workflowPath,
                        environment: workflowEnvironmentUrl,
                        tenant: tenant.id,
                        taskId: defaultTask.taskId,
                        action: defaultTask.possibleActions[1].action,
                        processInstanceComment: null
                    });
                    expect(onActionSuccess).not.toHaveBeenCalled();
                    expect(screen.getByText('Error')).toBeInTheDocument();
                    expect(screen.getByText(apiError.error.errorMessage)).toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should not send add comment request when user clicks on Shift + Enter in the comment input', function () { return __awaiter(void 0, void 0, void 0, function () {
        var newCommentMessage, user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    newCommentMessage = 'new comment message';
                    user = setUp().user;
                    return [4 /*yield*/, user.click(screen.getByTestId('collapse-button'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.type(screen.getByPlaceholderText('Write a comment'), newCommentMessage)];
                case 2:
                    _a.sent();
                    return [4 /*yield*/, user.keyboard('{shift>}{enter}{/shift}')];
                case 3:
                    _a.sent();
                    expect(addCommentForTask).not.toHaveBeenCalled();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should send correct add comment request when user sends multiline comment', function () { return __awaiter(void 0, void 0, void 0, function () {
        var firstLineCommentMessage, secondLineCommentMessage, user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    getTaskById.mockResolvedValue({
                        processInstanceComments: []
                    });
                    firstLineCommentMessage = 'string 1';
                    secondLineCommentMessage = 'string 2';
                    user = setUp().user;
                    return [4 /*yield*/, user.click(screen.getByTestId('collapse-button'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.type(screen.getByPlaceholderText('Write a comment'), firstLineCommentMessage)];
                case 2:
                    _a.sent();
                    return [4 /*yield*/, user.keyboard('{shift>}{enter}{/shift}')];
                case 3:
                    _a.sent();
                    return [4 /*yield*/, user.type(screen.getByPlaceholderText('Write a comment'), secondLineCommentMessage)];
                case 4:
                    _a.sent();
                    return [4 /*yield*/, user.keyboard('{enter}')];
                case 5:
                    _a.sent();
                    expect(addCommentForTask).toHaveBeenCalledWith(expect.objectContaining({ comment: 'string 1\nstring 2' }));
                    return [2 /*return*/];
            }
        });
    }); });
    it('should  not print "\n" after clicking Enter if the comment is empty', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, value;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp().user;
                    return [4 /*yield*/, user.click(screen.getByTestId('collapse-button'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.type(screen.getByPlaceholderText('Write a comment'), '{enter}')];
                case 2:
                    _a.sent();
                    value = screen.getByPlaceholderText('Write a comment').value;
                    expect(value).toBe('');
                    return [2 /*return*/];
            }
        });
    }); });
    it('should render custom actions slot if it is provided', function () { return __awaiter(void 0, void 0, void 0, function () {
        var openReviewDialog, user, reviewDCRButton;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    openReviewDialog = jest.fn();
                    user = setUp({ customActionsSlot: React.createElement(ReviewDCRButton, { onClick: openReviewDialog }) }).user;
                    reviewDCRButton = screen.getByRole('button', { name: 'Review DCR' });
                    expect(reviewDCRButton).toBeInTheDocument();
                    return [4 /*yield*/, user.click(reviewDCRButton)];
                case 1:
                    _a.sent();
                    expect(openReviewDialog).toHaveBeenCalled();
                    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: 'Delete',
                                    label: 'Delete',
                                    commentRequired: true
                                },
                                {
                                    action: 'Cancel',
                                    label: 'Cancel',
                                    commentRequired: false
                                }
                            ] });
                        user = setUp({ task: task }).user;
                        return [4 /*yield*/, user.click(screen.getByTestId('task-actions'))];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(screen.getByText(task.possibleActions[0].label))];
                    case 2:
                        _a.sent();
                        expect(runTaskAction).not.toHaveBeenCalled();
                        dialog = screen.getAllByRole('presentation')[1];
                        expect(within(dialog).getByText('Please provide a comment for your action')).toBeInTheDocument();
                        expect(within(dialog).getByText('Type a comment')).toBeInTheDocument();
                        expect(within(dialog).getByText('Cancel')).toBeInTheDocument();
                        expect(within(dialog).getByText('Done')).toBeInTheDocument();
                        comment = 'comment';
                        commentInput = 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(within(screen.getAllByRole('presentation')[1]).getByText('Done'))];
                    case 5:
                        _a.sent();
                        expect(runTaskAction).toHaveBeenCalledWith({
                            workflowPath: workflowPath,
                            environment: workflowEnvironmentUrl,
                            tenant: tenant.id,
                            taskId: defaultTask.taskId,
                            action: defaultTask.possibleActions[0].action,
                            processInstanceComment: comment
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it('should not show comment dialog when user types comment and run action', function () { return __awaiter(void 0, void 0, void 0, function () {
            var task, user, comment, commentInput;
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        task = __assign(__assign({}, defaultTask), { possibleActions: [
                                {
                                    action: 'Delete',
                                    label: 'Delete',
                                    commentRequired: true
                                },
                                {
                                    action: 'Cancel',
                                    label: 'Cancel',
                                    commentRequired: false
                                }
                            ] });
                        user = setUp({ task: task }).user;
                        return [4 /*yield*/, user.click(screen.getByTestId('collapse-button'))];
                    case 1:
                        _b.sent();
                        comment = 'comment';
                        commentInput = screen.getByPlaceholderText('Write a comment');
                        return [4 /*yield*/, user.click(commentInput)];
                    case 2:
                        _b.sent();
                        return [4 /*yield*/, user.paste(comment)];
                    case 3:
                        _b.sent();
                        return [4 /*yield*/, user.click(screen.getByRole('button', { name: (_a = task.preferredAction) === null || _a === void 0 ? void 0 : _a.label }))];
                    case 4:
                        _b.sent();
                        return [4 /*yield*/, user.click(screen.getByTestId("reltio-profile-select-mode-".concat(task.possibleActions[0].label)))];
                    case 5:
                        _b.sent();
                        expect(screen.queryByText('Please provide a comment for your action')).not.toBeInTheDocument();
                        expect(runTaskAction).toHaveBeenCalledWith({
                            workflowPath: workflowPath,
                            environment: workflowEnvironmentUrl,
                            tenant: tenant.id,
                            taskId: defaultTask.taskId,
                            action: defaultTask.possibleActions[0].action,
                            processInstanceComment: comment
                        });
                        return [2 /*return*/];
                }
            });
        }); });
    });
});
