"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 __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 mdm_sdk_1 = require("@reltio/mdm-sdk");
var SimpleAttributeEditor_1 = __importDefault(require("./SimpleAttributeEditor"));
var ProfilePerspectiveViewContext_1 = require("../contexts/ProfilePerspectiveViewContext");
var ScrollToElementContext_1 = require("../contexts/ScrollToElementContext");
var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
var AlwaysVisibleAttributesContext_1 = require("../contexts/AlwaysVisibleAttributesContext");
var AuthoringPerspectiveViewContext_1 = require("../contexts/AuthoringPerspectiveViewContext");
var useAutopopulationContextValue_1 = require("./useAutopopulationContextValue");
var useScrollToAttributeError_1 = require("../hooks/useScrollToAttributeError");
var useAsyncMount_1 = require("../hooks/useAsyncMount");
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { getDependentLookups: jest.fn(function () { return Promise.resolve(); }), getLookups: jest.fn(function () { return Promise.resolve(); }) })); });
jest.mock('../contexts/MdmModuleContext', function () { return (__assign(__assign({}, jest.requireActual('../contexts/MdmModuleContext')), { useMdmDependentLookupEditorContext: jest.fn() })); });
jest.mock('./useAutopopulationContextValue', function () { return (__assign(__assign({}, jest.requireActual('./useAutopopulationContextValue')), { useAutopopulationContextValue: jest.fn() })); });
jest.mock('../hooks/useScrollToAttributeError', function () { return (__assign(__assign({}, jest.requireActual('../hooks/useScrollToAttributeError')), { useScrollToAttributeError: jest.fn() })); });
jest.mock('../hooks/useAsyncMount', function () { return (__assign(__assign({}, jest.requireActual('../hooks/useAsyncMount')), { useAsyncMount: jest.fn() })); });
describe('SimpleAttributeEditor', function () {
    var getScrollToElementContextValue = function (error) {
        if (error === void 0) { error = null; }
        return ({
            element: error,
            highlightError: jest.fn(),
            scrollIntoRef: jest.fn(),
            type: ScrollToElementContext_1.ScrollType.Error
        });
    };
    var mdmValues = {
        dependentLookups: {
            editors: {},
            structure: {},
            initedTypeUris: []
        }
    };
    beforeAll(function () {
        useScrollToAttributeError_1.useScrollToAttributeError.mockImplementation(jest.requireActual('../hooks/useScrollToAttributeError').useScrollToAttributeError);
        useAsyncMount_1.useAsyncMount.mockImplementation(jest.requireActual('../hooks/useAsyncMount').useAsyncMount);
        useAutopopulationContextValue_1.useAutopopulationContextValue.mockImplementation(jest.requireActual('./useAutopopulationContextValue').useAutopopulationContextValue);
    });
    beforeEach(function () {
        jest.clearAllMocks();
    });
    var defaultProps = {
        attributeValue: {
            value: 'some string',
            uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
        },
        attributeType: {
            access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
            type: 'String',
            uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
        },
        isReltioCrosswalk: true,
        mode: mdm_sdk_1.Mode.Editing,
        onAddOneMore: jest.fn(),
        onDeleteAttribute: jest.fn(),
        onChangeAttribute: jest.fn(),
        onDeactivateError: jest.fn()
    };
    var setUp = function (_a) {
        var _b = _a === void 0 ? {} : _a, _c = _b.props, props = _c === void 0 ? {} : _c, _d = _b.error, error = _d === void 0 ? null : _d, _e = _b.isProfilePerspective, isProfilePerspective = _e === void 0 ? false : _e, _f = _b.isAuthoringPerspective, isAuthoringPerspective = _f === void 0 ? false : _f, _g = _b.alwaysVisibleAttributes, alwaysVisibleAttributes = _g === void 0 ? [] : _g;
        var user = user_event_1.default.setup();
        var scrollToElementContextValue = getScrollToElementContextValue(error);
        var Providers = function (_a) {
            var children = _a.children;
            return (react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues },
                react_1.default.createElement(AlwaysVisibleAttributesContext_1.AlwaysVisibleAttributesContext.Provider, { value: alwaysVisibleAttributes },
                    react_1.default.createElement(ProfilePerspectiveViewContext_1.ProfilePerspectiveViewContext.Provider, { value: isProfilePerspective },
                        react_1.default.createElement(AuthoringPerspectiveViewContext_1.AuthoringPerspectiveViewContext.Provider, { value: isAuthoringPerspective },
                            react_1.default.createElement(ScrollToElementContext_1.ScrollToElementContext.Provider, { value: scrollToElementContextValue }, children))))));
        };
        return __assign({ user: user, scrollToElementContextValue: scrollToElementContextValue }, (0, react_2.render)(react_1.default.createElement(SimpleAttributeEditor_1.default, __assign({}, defaultProps, props)), { wrapper: Providers }));
    };
    describe('String attribute', function () {
        it('should render the simple attribute to edit with action buttons', function () {
            setUp();
            expect(react_2.screen.getByRole('textbox')).toHaveValue('some string');
            expect(react_2.screen.queryByTestId('error-message')).not.toBeInTheDocument();
            var actions = react_2.screen.getByTestId('reltio-attribute-actions');
            expect((0, react_2.within)(actions).getAllByRole('button')).toHaveLength(2);
            expect(react_2.screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
            expect(react_2.screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
        });
        it('should render additional control between plus and delete buttons if additionalControlsRenderer prop is specified', function () {
            setUp({
                props: {
                    additionalControlsRenderer: function (_a) {
                        var attributeValue = _a.attributeValue, attributeType = _a.attributeType;
                        return (react_1.default.createElement("div", { "data-reltio-id": "additional-controls" },
                            react_1.default.createElement("div", { "data-reltio-id": "attribute-value" }, attributeValue.uri),
                            react_1.default.createElement("div", { "data-reltio-id": "attribute-type" }, attributeType.uri)));
                    }
                }
            });
            expect(react_2.screen.getByTestId('additional-controls')).toBeInTheDocument();
            expect(react_2.screen.getByTestId('attribute-value')).toHaveTextContent('entities/eNt1/attributes/InternalCustomer/gd42423');
            expect(react_2.screen.getByTestId('attribute-type')).toHaveTextContent('configuration/entityTypes/HCA/attributes/InternalCustomer');
        });
        it('should render error message if ownError prop is specified', function () {
            var ownError = {
                uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
                parentUri: 'entities/eNt1',
                attributeTypeUri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
                message: 'Error!!!',
                type: 'invalid'
            };
            setUp({ props: { ownError: ownError } });
            expect(react_2.screen.getByRole('textbox')).toHaveValue('some string');
            expect(react_2.screen.getByTestId('error-message')).toHaveTextContent('Error!!!');
        });
        it('should not render delete button in case of missed DELETE permission', function () {
            var attributeType = __assign(__assign({}, defaultProps.attributeType), { access: ['UPDATE', 'CREATE', 'READ'] });
            setUp({ props: { attributeType: attributeType } });
            expect(react_2.screen.getByRole('textbox')).toHaveValue('some string');
            expect(react_2.screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
            expect(react_2.screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
        });
        it('should not render plus button in case of missed CREATE permission', function () {
            var attributeType = __assign(__assign({}, defaultProps.attributeType), { access: ['UPDATE', 'DELETE', 'READ'] });
            setUp({ props: { attributeType: attributeType } });
            expect(react_2.screen.getByRole('textbox')).toHaveValue('some string');
            expect(react_2.screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
            expect(react_2.screen.queryByTestId('reltio-add-one-more-simple-attribute-button')).not.toBeInTheDocument();
        });
        it('should call onChangeAttribute prop when input value changes', 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.type(react_2.screen.getByRole('textbox'), ' new{enter}')];
                    case 1:
                        _a.sent();
                        expect(defaultProps.onChangeAttribute).toHaveBeenCalledWith({
                            attributeType: {
                                access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
                                type: 'String',
                                uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
                            },
                            uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
                            value: 'some string new'
                        });
                        expect(defaultProps.onDeactivateError).not.toHaveBeenCalled();
                        return [2 /*return*/];
                }
            });
        }); });
        it('should deactivate error when input value changes', function () { return __awaiter(void 0, void 0, void 0, function () {
            var ownError, user;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        ownError = {
                            uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
                            parentUri: 'entities/eNt1',
                            attributeTypeUri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
                            message: 'Error!!!',
                            type: 'invalid'
                        };
                        user = setUp({ props: { ownError: ownError } }).user;
                        return [4 /*yield*/, user.type(react_2.screen.getByRole('textbox'), ' new{enter}')];
                    case 1:
                        _a.sent();
                        expect(defaultProps.onChangeAttribute).toHaveBeenCalledWith({
                            attributeType: {
                                access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
                                type: 'String',
                                uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
                            },
                            uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
                            value: 'some string new'
                        });
                        expect(defaultProps.onDeactivateError).toHaveBeenCalledWith('configuration/entityTypes/HCA/attributes/InternalCustomer-entities/eNt1/attributes/InternalCustomer/gd42423-entities/eNt1');
                        return [2 /*return*/];
                }
            });
        }); });
        it('should call onDeleteAttribute after click on delete button', 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(react_2.screen.getByTestId('reltio-delete-simple-attribute-button'))];
                    case 1:
                        _a.sent();
                        expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
                            attributeType: {
                                access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
                                type: 'String',
                                uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
                            },
                            uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
                        });
                        expect(defaultProps.onDeactivateError).not.toHaveBeenCalled();
                        return [2 /*return*/];
                }
            });
        }); });
        it('should call onAddOneMore on click on add more button', 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(react_2.screen.getByTestId('reltio-add-one-more-simple-attribute-button'))];
                    case 1:
                        _a.sent();
                        expect(defaultProps.onAddOneMore).toHaveBeenCalledTimes(1);
                        return [2 /*return*/];
                }
            });
        }); });
        it('should deactivate "invalid" error after click on delete button', function () { return __awaiter(void 0, void 0, void 0, function () {
            var ownError, user;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        ownError = {
                            uri: 'entities/eNt1/attributes/InternalCustomer/gd42423',
                            parentUri: 'entities/eNt1',
                            attributeTypeUri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
                            message: 'Error!!!',
                            type: 'invalid'
                        };
                        user = setUp({ props: { ownError: ownError } }).user;
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('reltio-delete-simple-attribute-button'))];
                    case 1:
                        _a.sent();
                        expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
                            attributeType: {
                                access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
                                type: 'String',
                                uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
                            },
                            uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
                        });
                        expect(defaultProps.onDeactivateError).toHaveBeenCalledWith('configuration/entityTypes/HCA/attributes/InternalCustomer-entities/eNt1/attributes/InternalCustomer/gd42423-entities/eNt1');
                        return [2 /*return*/];
                }
            });
        }); });
        it('should not deactivate "missed" error after click on delete button', function () { return __awaiter(void 0, void 0, void 0, function () {
            var ownError, user;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        ownError = {
                            uri: '',
                            parentUri: 'entities/eNt1',
                            attributeTypeUri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
                            message: 'Error!!!',
                            type: 'missed'
                        };
                        user = setUp({ props: { ownError: ownError } }).user;
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('reltio-delete-simple-attribute-button'))];
                    case 1:
                        _a.sent();
                        expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
                            attributeType: {
                                access: ['UPDATE', 'DELETE', 'CREATE', 'READ'],
                                type: 'String',
                                uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
                            },
                            uri: 'entities/eNt1/attributes/InternalCustomer/gd42423'
                        });
                        expect(defaultProps.onDeactivateError).not.toHaveBeenCalled();
                        return [2 /*return*/];
                }
            });
        }); });
        it('should be wrapped in withAsyncMount HOC', function () {
            setUp();
            expect(useAsyncMount_1.useAsyncMount).toHaveBeenCalled();
        });
        it('should render component in "deleted" state', function () {
            setUp({ props: { state: 'deleted' } });
            expect(react_2.screen.getByRole('textbox')).toBeDisabled();
            expect(react_2.screen.getByTestId('reltio-attribute-value')).toHaveClass('deleted');
            expect(react_2.screen.getAllByRole('button')).toHaveLength(1);
            expect(react_2.screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
            expect(react_2.screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
            expect(react_2.screen.getByTestId('reltio-attribute-actions')).toHaveTextContent('');
        });
        it('should render component in "edited" state', function () {
            setUp({ props: { state: 'edited' } });
            expect(react_2.screen.getByRole('textbox')).not.toBeDisabled();
            expect(react_2.screen.getByTestId('reltio-attribute-value')).not.toHaveClass('deleted');
            expect(react_2.screen.getAllByRole('button')).toHaveLength(2);
            expect(react_2.screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
            expect(react_2.screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
            expect(react_2.screen.getByTestId('reltio-attribute-actions')).toHaveTextContent('(edited)');
        });
    });
    describe('Dependent Lookup attribute', function () {
        beforeEach(function () {
            MdmModuleContext_1.useMdmDependentLookupEditorContext.mockReturnValue({});
            useAutopopulationContextValue_1.useAutopopulationContextValue.mockReturnValue({ autopopulationContextValue: null });
        });
        var attributeType = {
            type: 'String',
            uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer',
            dependentLookupCode: 'Code'
        };
        it('should call getDependentLookupEditorContext selector with correct arguments for profile perspective', function () { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        setUp({ props: { attributeType: attributeType }, isProfilePerspective: true });
                        return [4 /*yield*/, (0, react_2.act)(function () { return Promise.resolve(); })];
                    case 1:
                        _a.sent();
                        expect(MdmModuleContext_1.useMdmDependentLookupEditorContext).toHaveBeenCalledWith(defaultProps.attributeValue, attributeType);
                        expect(useAutopopulationContextValue_1.useAutopopulationContextValue).toHaveBeenCalledWith({
                            enabled: true,
                            attributeTypeUri: attributeType.uri,
                            valueUri: defaultProps.attributeValue.uri
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it('should call getDependentLookupEditorContext selector with correct arguments for authoring perspective', function () { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        setUp({ props: { attributeType: attributeType }, isAuthoringPerspective: true });
                        return [4 /*yield*/, (0, react_2.act)(function () { return Promise.resolve(); })];
                    case 1:
                        _a.sent();
                        expect(MdmModuleContext_1.useMdmDependentLookupEditorContext).toHaveBeenCalledWith(defaultProps.attributeValue, attributeType);
                        expect(useAutopopulationContextValue_1.useAutopopulationContextValue).toHaveBeenCalledWith({
                            enabled: true,
                            attributeTypeUri: attributeType.uri,
                            valueUri: defaultProps.attributeValue.uri
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it('should call useAutopopulationContextValue with enabled: false if component is outside of Profile perspective', function () { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        setUp({ props: { attributeType: attributeType }, isProfilePerspective: false });
                        return [4 /*yield*/, (0, react_2.act)(function () { return Promise.resolve(); })];
                    case 1:
                        _a.sent();
                        expect(useAutopopulationContextValue_1.useAutopopulationContextValue).toHaveBeenCalledWith({
                            enabled: false,
                            attributeTypeUri: attributeType.uri,
                            valueUri: defaultProps.attributeValue.uri
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it('should call useAutopopulationContextValue with enabled: false if component is outside of authoring perspective', function () { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        setUp({ props: { attributeType: attributeType }, isAuthoringPerspective: false });
                        return [4 /*yield*/, (0, react_2.act)(function () { return Promise.resolve(); })];
                    case 1:
                        _a.sent();
                        expect(useAutopopulationContextValue_1.useAutopopulationContextValue).toHaveBeenCalledWith({
                            enabled: false,
                            attributeTypeUri: attributeType.uri,
                            valueUri: defaultProps.attributeValue.uri
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it('should render dependent lookup editor with applied result of getDependentLookupEditorContext', function () { return __awaiter(void 0, void 0, void 0, function () {
            var dlEditorContext, input;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        dlEditorContext = {
                            parents: [
                                {
                                    codeValues: ['HOSP'],
                                    type: 'Use case 1 - Organization Type'
                                }
                            ],
                            disabled: true,
                            placeholder: 'Some placeholder',
                            value: null
                        };
                        MdmModuleContext_1.useMdmDependentLookupEditorContext.mockReturnValue(dlEditorContext);
                        setUp({ props: { attributeType: attributeType }, isProfilePerspective: true });
                        return [4 /*yield*/, (0, react_2.act)(function () { return Promise.resolve(); })];
                    case 1:
                        _a.sent();
                        expect(react_2.screen.getByText('Some placeholder')).toBeDefined();
                        input = react_2.screen.getByRole('combobox');
                        expect(input).toBeDefined();
                        expect(input.getAttribute('value')).toBe('');
                        expect(input.hasAttribute('disabled')).toBe(true);
                        expect(mdm_sdk_1.getDependentLookups).toHaveBeenCalledWith({
                            displayNamePrefix: '',
                            max: 51,
                            offset: 0,
                            parents: dlEditorContext.parents,
                            type: attributeType.dependentLookupCode
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it('should render dependent lookup editor with applied result of useAutopopulationContextValue', function () { return __awaiter(void 0, void 0, void 0, function () {
            var autopopulationContextValue, user, input;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        autopopulationContextValue = {
                            id: defaultProps.attributeValue.uri,
                            isTouched: true,
                            onTouch: jest.fn()
                        };
                        useAutopopulationContextValue_1.useAutopopulationContextValue.mockReturnValue({ autopopulationContextValue: autopopulationContextValue });
                        user = setUp({ props: { attributeType: attributeType }, isProfilePerspective: true }).user;
                        return [4 /*yield*/, (0, react_2.act)(function () { return Promise.resolve(); })];
                    case 1:
                        _a.sent();
                        input = react_2.screen.getByRole('combobox');
                        expect(input).toBeDefined();
                        return [4 /*yield*/, user.clear(input)];
                    case 2:
                        _a.sent();
                        expect(autopopulationContextValue.onTouch).toHaveBeenCalledWith(defaultProps.attributeValue.uri);
                        return [2 /*return*/];
                }
            });
        }); });
    });
    describe('useScrollToAttributeError tests', function () {
        var fullError = {
            type: 'invalid',
            attributeTypeUri: defaultProps.attributeType.uri,
            parentUri: defaultProps.attributeValue.uri,
            uri: 'someUrl',
            source: 'validationService',
            severity: 'ERROR'
        };
        it('should not highlight error if it have wrong uri', function () {
            setUp({ error: fullError });
            expect(react_2.screen.getByTestId('simple-attribute-editor')).not.toHaveClass('highlightError simpleAttribute');
            expect(useScrollToAttributeError_1.useScrollToAttributeError).toHaveBeenCalledWith({ highlightedError: null, isSimple: true });
        });
        it('should highlight error if it have right uri', function () {
            var error = __assign(__assign({}, fullError), { uri: defaultProps.attributeValue.uri });
            var scrollToElementContextValue = setUp({ error: error }).scrollToElementContextValue;
            expect(react_2.screen.getByTestId('simple-attribute-editor')).toHaveClass('highlightError simpleAttribute');
            expect(useScrollToAttributeError_1.useScrollToAttributeError).toHaveBeenCalledWith({
                highlightedError: scrollToElementContextValue,
                isSimple: true
            });
        });
    });
    describe('without permissions', function () {
        it('should render just text, if there is only READ permission', function () {
            var props = {
                attributeValue: {
                    value: 'some string',
                    uri: '1'
                },
                attributeType: {
                    access: ['READ'],
                    type: 'String',
                    uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
                }
            };
            setUp({ props: props });
            expect(react_2.screen.getByText('some string')).toBeInTheDocument();
            expect(react_2.screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
        });
        it('should render text and DELETE button, if there are only READ and DELETE permission', function () {
            var props = {
                attributeValue: {
                    value: 'some string',
                    uri: '1'
                },
                attributeType: {
                    access: ['READ', 'DELETE'],
                    type: 'String',
                    uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
                }
            };
            setUp({ props: props });
            expect(react_2.screen.getByText('some string')).toBeInTheDocument();
            expect(react_2.screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
        });
        it('should render always visible attribute  without value correct, if there are only READ permission', function () {
            var props = {
                attributeValue: {
                    uri: 'uri$$'
                },
                attributeType: {
                    access: ['READ'],
                    type: 'String',
                    uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
                }
            };
            setUp({ props: props, alwaysVisibleAttributes: ['configuration/entityTypes/HCA/attributes/InternalCustomer'] });
            expect(react_2.screen.queryByRole('textbox')).not.toBeInTheDocument();
            expect(react_2.screen.queryByTestId('reltio-delete-simple-attribute-button')).not.toBeInTheDocument();
        });
        it('should render always visible attribute  without value correct, if there are only READ and DELETE permission', function () {
            var props = {
                attributeValue: {
                    uri: 'uri$$'
                },
                attributeType: {
                    access: ['READ', 'DELETE'],
                    type: 'String',
                    uri: 'configuration/entityTypes/HCA/attributes/InternalCustomer'
                }
            };
            setUp({ props: props, alwaysVisibleAttributes: ['configuration/entityTypes/HCA/attributes/InternalCustomer'] });
            expect(react_2.screen.queryByRole('textbox')).not.toBeInTheDocument();
            expect(react_2.screen.getByTestId('reltio-delete-simple-attribute-button')).toBeInTheDocument();
        });
    });
});
