"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 metadata_test_data_1 = require("./metadata.test-data");
var ReferenceAttributeEditor_1 = __importDefault(require("./ReferenceAttributeEditor"));
var ScrollToElementContext_1 = require("../contexts/ScrollToElementContext");
var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { typeAheadSearch: jest.fn() })); });
var highlightError = jest.fn();
var scrollIntoRef = jest.fn();
var defaultProps = {
    attributeType: metadata_test_data_1.referenceAttrType,
    attributeValue: {
        label: 'Reference attribute',
        uri: 'entities/0C30cfF/attributes/Contact/T79PZtL',
        value: {},
        refEntity: null,
        refRelation: null,
        relationshipLabel: 'Relationship label',
        startObjectCrosswalks: []
    },
    mode: mdm_sdk_1.Mode.Editing,
    metadata: metadata_test_data_1.metadata,
    onAddAttributes: jest.fn(),
    onDeleteAttribute: jest.fn(),
    onChangeAttribute: jest.fn(),
    additionalControlsRenderer: function () { return null; }
};
var mdmActions = {
    entityDeleted: jest.fn(),
    entityCreated: jest.fn(),
    errorDeactivated: jest.fn(),
    addAttributes: jest.fn(),
    removeAttribute: jest.fn(),
    modifyAttribute: jest.fn()
};
var defaultMdmValues = {
    metadata: metadata_test_data_1.metadata,
    modifiedEntities: {},
    dependentLookups: { editors: {}, structure: {}, initedTypeUris: [] }
};
var setUp = function (_a) {
    var _b = _a === void 0 ? {} : _a, _c = _b.props, props = _c === void 0 ? defaultProps : _c, _d = _b.mdmValues, mdmValues = _d === void 0 ? defaultMdmValues : _d, _e = _b.error, error = _e === void 0 ? null : _e;
    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, actions: mdmActions },
            react_1.default.createElement(ScrollToElementContext_1.ScrollToElementContext.Provider, { value: { element: error, highlightError: highlightError, scrollIntoRef: scrollIntoRef, type: ScrollToElementContext_1.ScrollType.Error } }, children)));
    };
    return __assign(__assign({}, (0, react_2.render)(react_1.default.createElement(ReferenceAttributeEditor_1.default, __assign({}, props)), { wrapper: Providers })), { user: user });
};
describe('Reference attribute editor tests', function () {
    beforeEach(function () {
        mdm_sdk_1.typeAheadSearch.mockResolvedValue([
            { type: 'configuration/entityTypes/Organization', label: 'organization entity 1', uri: 'entities/0C32GxR' },
            { type: 'configuration/entityTypes/Organization', label: 'organization entity 2', uri: 'entities/0G49Cnu' }
        ]);
    });
    afterEach(function () {
        jest.clearAllMocks();
    });
    it('should render reference attribute editor correctly without ref entity', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, menuItems;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp().user;
                    react_2.screen.getByText('Reference attribute');
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('arrow-expand-button'))];
                case 1:
                    _a.sent();
                    react_2.screen.getByText('Select Organization profile');
                    expect(react_2.screen.getByRole('combobox')).not.toBeDisabled();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('More attributes'))];
                case 2:
                    _a.sent();
                    menuItems = react_2.screen.getAllByRole('menuitem');
                    expect(menuItems).toHaveLength(3);
                    expect(menuItems[0]).toHaveTextContent('Affiliated with');
                    expect(menuItems[1]).toHaveTextContent('Title');
                    expect(menuItems[2]).toHaveTextContent('Status');
                    return [2 /*return*/];
            }
        });
    }); });
    it('should render reference attribute editor correctly with ref entity and values', function () { return __awaiter(void 0, void 0, void 0, function () {
        var props, user, entitySelector, labels, values;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    props = __assign(__assign({}, defaultProps), { attributeValue: __assign(__assign({}, defaultProps.attributeValue), { refEntity: [
                                {
                                    crosswalks: [],
                                    objectURI: 'entities/0C32GxR',
                                    type: 'configuration/entityTypes/Organization'
                                }
                            ], value: {
                                Name: [
                                    {
                                        type: 'configuration/entityTypes/Organization/attributes/Name',
                                        uri: 'entities/0C30cfF/attributes/Organization/T79PZtL/Name/1XEK3ixZ',
                                        ov: true,
                                        value: 'name value'
                                    }
                                ],
                                Title: [
                                    {
                                        type: 'configuration/relationTypes/affiliatedwith/attributes/Title',
                                        uri: 'entities/0C30cfF/attributes/Contact/T79PZtL/Title/1s0ncx5P',
                                        ov: true,
                                        value: 'title value'
                                    }
                                ]
                            } }) });
                    user = setUp({ props: props }).user;
                    react_2.screen.getByText('Reference attribute');
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('arrow-expand-button'))];
                case 1:
                    _a.sent();
                    entitySelector = react_2.screen.getByTestId('reltio-entity-selector');
                    (0, react_2.within)(entitySelector).getByText('Select Organization profile');
                    (0, react_2.within)(entitySelector).getByText('Reference attribute');
                    labels = react_2.screen.getAllByTestId('reltio-attribute-label');
                    values = react_2.screen.getAllByTestId('reltio-attribute-value');
                    expect(labels).toHaveLength(1);
                    expect(values).toHaveLength(1);
                    expect(labels[0]).toHaveTextContent('Title');
                    expect((0, react_2.within)(values[0]).getByRole('textbox')).toHaveValue('title value');
                    return [2 /*return*/];
            }
        });
    }); });
    it('should render reference attribute editor correctly with temporarty ref entity and values', function () { return __awaiter(void 0, void 0, void 0, function () {
        var refEntityUri, modifiedEntities, props, mdmValues, user, entitySelector, labels, values;
        var _a;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    refEntityUri = 'entities/uri$$JsO92Ns';
                    modifiedEntities = (_a = {},
                        _a[refEntityUri] = {
                            uri: refEntityUri,
                            type: 'configuration/entityTypes/Organization',
                            attributes: {
                                Name: [
                                    {
                                        uri: 'entities/uri$$JsO92Ns/attributes/Name/$uri7JsbN0l',
                                        type: 'configuration/entityTypes/Organization/attributes/Name',
                                        value: 'name value'
                                    }
                                ]
                            }
                        },
                        _a);
                    props = __assign(__assign({}, defaultProps), { attributeValue: __assign(__assign({}, defaultProps.attributeValue), { refEntity: [
                                {
                                    crosswalks: [],
                                    objectURI: refEntityUri,
                                    type: 'configuration/entityTypes/Organization'
                                }
                            ] }) });
                    mdmValues = __assign(__assign({}, defaultMdmValues), { modifiedEntities: modifiedEntities });
                    user = setUp({ props: props, mdmValues: mdmValues }).user;
                    react_2.screen.getByText('name value!');
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('arrow-expand-button'))];
                case 1:
                    _b.sent();
                    entitySelector = react_2.screen.getByTestId('reltio-entity-selector');
                    (0, react_2.within)(entitySelector).getByText('Select Organization profile');
                    (0, react_2.within)(entitySelector).getByText('New Organization will be created');
                    labels = react_2.screen.getAllByTestId('reltio-attribute-label');
                    values = react_2.screen.getAllByTestId('reltio-attribute-value');
                    expect(labels).toHaveLength(2);
                    expect(values).toHaveLength(2);
                    expect(labels[0]).toHaveTextContent('Nickname');
                    expect(labels[1]).toHaveTextContent('Name');
                    expect((0, react_2.within)(values[0]).getByRole('textbox')).toHaveValue('');
                    expect((0, react_2.within)(values[1]).getByRole('textbox')).toHaveValue('name value');
                    return [2 /*return*/];
            }
        });
    }); });
    it('should display missed referenced entity active error message for entity selector', function () { return __awaiter(void 0, void 0, void 0, function () {
        var props;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    props = __assign(__assign({}, defaultProps), { errors: [
                            {
                                parentUri: defaultProps.attributeValue.uri,
                                uri: '',
                                attributeTypeUri: metadata_test_data_1.referenceAttrType.uri,
                                message: 'Attribute is required',
                                type: mdm_sdk_1.ErrorType.missed
                            },
                            {
                                parentUri: defaultProps.attributeValue.uri,
                                uri: '',
                                attributeTypeUri: metadata_test_data_1.referenceAttrType.uri,
                                message: 'Entity is required - deactivated',
                                deactivated: true,
                                type: mdm_sdk_1.ErrorType.missedRefEntity
                            },
                            {
                                parentUri: defaultProps.attributeValue.uri,
                                uri: '',
                                attributeTypeUri: metadata_test_data_1.referenceAttrType.uri,
                                message: 'Entity is required!',
                                type: mdm_sdk_1.ErrorType.missedRefEntity
                            }
                        ] });
                    setUp({ props: props });
                    return [4 /*yield*/, (0, react_2.act)(function () { return __awaiter(void 0, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, Promise.resolve()];
                                    case 1:
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); })];
                case 1:
                    _a.sent();
                    react_2.screen.getByText('Entity is required!');
                    return [2 /*return*/];
            }
        });
    }); });
    it('should render <No label> in case of missing attribute label and modified entity prop', function () {
        var props = __assign(__assign({}, defaultProps), { attributeValue: __assign(__assign({}, defaultProps.attributeValue), { label: undefined }) });
        setUp({ props: props });
        react_2.screen.getByText('<No label>');
    });
    it('should disable entity selector if attribute type has not editing permission', function () { return __awaiter(void 0, void 0, void 0, function () {
        var attributeType, props, user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    attributeType = __assign(__assign({}, metadata_test_data_1.referenceAttrType), { access: ['READ'] });
                    props = __assign(__assign({}, defaultProps), { attributeType: attributeType });
                    user = setUp({ props: props }).user;
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('arrow-expand-button'))];
                case 1:
                    _a.sent();
                    expect(react_2.screen.getByRole('combobox')).toBeDisabled();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should load and select reference entities correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
        var globalFilter, activityFilter, searchOptions, mdmValues, user, options;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    globalFilter = { query: '', savedSearches: [], savedSearchesUris: [] };
                    activityFilter = mdm_sdk_1.ActivityFilter.ACTIVE_ONLY;
                    searchOptions = { searchByOv: true, ovOnly: true };
                    mdmValues = __assign(__assign({}, defaultMdmValues), { globalFilter: globalFilter, activityFilter: activityFilter, searchOptions: searchOptions });
                    user = setUp({ mdmValues: mdmValues }).user;
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('arrow-expand-button'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('select-dropdown-indicator'))];
                case 2:
                    _a.sent();
                    expect(mdm_sdk_1.typeAheadSearch).toHaveBeenCalledWith([metadata_test_data_1.metadata.entityTypes[1]], '', {
                        activityFilter: mdm_sdk_1.ActivityFilter.ACTIVE_ONLY,
                        globalFilter: '',
                        max: 20,
                        searchOptions: 'searchByOv',
                        sendMasked: false
                    });
                    options = react_2.screen.getAllByRole('option');
                    expect(options[0]).toHaveTextContent('organization entity 1');
                    expect(options[1]).toHaveTextContent('organization entity 2');
                    return [4 /*yield*/, user.click(options[1])];
                case 3:
                    _a.sent();
                    expect(defaultProps.onChangeAttribute).toHaveBeenCalledWith({
                        attributeType: defaultProps.attributeType,
                        uri: defaultProps.attributeValue.uri,
                        value: __assign(__assign({}, defaultProps.attributeValue), { label: 'organization entity 2', refEntity: [{ objectURI: 'entities/0G49Cnu', type: 'configuration/entityTypes/Organization' }], refRelation: [{ objectURI: 'relations/T79PZtL', type: 'configuration/sources/Reltio' }] })
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    describe('entity changing', function () {
        it('should deactivate referenced entity missed error if it is set', function () { return __awaiter(void 0, void 0, void 0, function () {
            var props, user;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        props = __assign(__assign({}, defaultProps), { errors: [
                                {
                                    parentUri: defaultProps.attributeValue.uri,
                                    uri: '',
                                    attributeTypeUri: metadata_test_data_1.referenceAttrType.uri,
                                    message: 'Entity is required',
                                    type: mdm_sdk_1.ErrorType.missedRefEntity
                                }
                            ] });
                        user = setUp({ props: props }).user;
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('select-dropdown-indicator'))];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByText('organization entity 1'))];
                    case 2:
                        _a.sent();
                        expect(mdmActions.errorDeactivated).toHaveBeenCalledWith('configuration/entityTypes/Contact/attributes/affiliatedwith--entities/0C30cfF/attributes/Contact/T79PZtL');
                        return [2 /*return*/];
                }
            });
        }); });
        it('should call onDeleteModifiedEntity prop before onChangeAttribute if modified entity prop is defined', function () { return __awaiter(void 0, void 0, void 0, function () {
            var refEntityUri, modifiedEntities, props, mdmValues, user;
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        refEntityUri = 'entities/uri$$JsO92Ns';
                        modifiedEntities = (_a = {},
                            _a[refEntityUri] = {
                                uri: refEntityUri,
                                type: 'configuration/entityTypes/Organization',
                                attributes: {
                                    Name: [
                                        {
                                            uri: 'entities/uri$$JsO92Ns/attributes/Name/$uri7JsbN0l',
                                            type: 'configuration/entityTypes/Organization/attributes/Name',
                                            value: 'name value'
                                        }
                                    ]
                                }
                            },
                            _a);
                        props = __assign(__assign({}, defaultProps), { attributeValue: __assign(__assign({}, defaultProps.attributeValue), { refEntity: [
                                    {
                                        crosswalks: [],
                                        objectURI: refEntityUri,
                                        type: 'configuration/entityTypes/Organization'
                                    }
                                ] }) });
                        mdmValues = __assign(__assign({}, defaultMdmValues), { modifiedEntities: modifiedEntities });
                        user = setUp({ props: props, mdmValues: mdmValues }).user;
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('arrow-expand-button'))];
                    case 1:
                        _b.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('select-dropdown-indicator'))];
                    case 2:
                        _b.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByText('organization entity 1'))];
                    case 3:
                        _b.sent();
                        expect(mdmActions.entityDeleted).toHaveBeenCalledWith(refEntityUri);
                        expect(props.onChangeAttribute).toHaveBeenCalledWith({
                            attributeType: props.attributeType,
                            uri: props.attributeValue.uri,
                            value: __assign(__assign({}, props.attributeValue), { label: 'organization entity 1', refEntity: [{ objectURI: 'entities/0C32GxR', type: 'configuration/entityTypes/Organization' }], refRelation: [{ objectURI: 'relations/T79PZtL', type: 'configuration/sources/Reltio' }] })
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it('should call onChangeAttribute prop with initial refEntity and refRelation if initial entity was selected', function () { return __awaiter(void 0, void 0, void 0, function () {
            var props, user;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        props = __assign(__assign({}, defaultProps), { attributeValue: __assign(__assign({}, defaultProps.attributeValue), { label: 'organization entity 1', refEntity: [
                                    {
                                        crosswalks: [],
                                        objectURI: 'entities/0C32GxR',
                                        type: 'configuration/entityTypes/Organization'
                                    }
                                ], refRelation: [
                                    {
                                        crosswalks: [],
                                        objectURI: 'relations/T79PZtL',
                                        type: 'configuration/sources/Reltio'
                                    }
                                ] }) });
                        user = setUp({ props: props }).user;
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('arrow-expand-button'))];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('select-dropdown-indicator'))];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByText('organization entity 2'))];
                    case 3:
                        _a.sent();
                        expect(mdmActions.entityDeleted).not.toHaveBeenCalled();
                        expect(props.onChangeAttribute).toHaveBeenCalledWith({
                            attributeType: props.attributeType,
                            uri: props.attributeValue.uri,
                            value: __assign(__assign({}, props.attributeValue), { label: 'organization entity 2', refEntity: [{ objectURI: 'entities/0G49Cnu', type: 'configuration/entityTypes/Organization' }], refRelation: [{ objectURI: 'relations/T79PZtL', type: 'configuration/sources/Reltio' }] })
                        });
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('select-dropdown-indicator'))];
                    case 4:
                        _a.sent();
                        return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByRole('tooltip')).getByText('organization entity 1'))];
                    case 5:
                        _a.sent();
                        expect(mdmActions.entityDeleted).not.toHaveBeenCalled();
                        expect(props.onChangeAttribute).toHaveBeenCalledWith({
                            attributeType: props.attributeType,
                            uri: props.attributeValue.uri,
                            value: props.attributeValue
                        });
                        return [2 /*return*/];
                }
            });
        }); });
    });
    describe('entity creating', function () {
        it('should create new entity, call onChangeAttribute prop and entityCreated mdm action correctly', 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('arrow-expand-button'))];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('select-dropdown-indicator'))];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByText('Create new Organization'))];
                    case 3:
                        _a.sent();
                        expect(defaultProps.onChangeAttribute).toHaveBeenCalledWith({
                            attributeType: defaultProps.attributeType,
                            uri: defaultProps.attributeValue.uri,
                            value: __assign(__assign({}, defaultProps.attributeValue), { label: undefined, refEntity: [{ objectURI: expect.any(String), type: 'configuration/entityTypes/Organization' }], refRelation: [{ objectURI: 'relations/T79PZtL', type: 'configuration/sources/Reltio' }] })
                        });
                        expect(mdmActions.entityCreated).toHaveBeenCalledWith({
                            attributes: {},
                            timestamp: expect.any(Number),
                            type: 'configuration/entityTypes/Organization',
                            uri: expect.any(String)
                        });
                        expect(mdmActions.entityDeleted).not.toHaveBeenCalled();
                        return [2 /*return*/];
                }
            });
        }); });
        it('should call entityDeleted mdm action before entityCreated/onChangeAttribute if modified entity prop is defined', function () { return __awaiter(void 0, void 0, void 0, function () {
            var refEntityUri, modifiedEntities, props, mdmValues, user;
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        refEntityUri = 'entities/uri$$JsO92Ns';
                        modifiedEntities = (_a = {},
                            _a[refEntityUri] = {
                                uri: refEntityUri,
                                type: 'configuration/entityTypes/Organization',
                                attributes: {
                                    Name: [
                                        {
                                            uri: 'entities/uri$$JsO92Ns/attributes/Name/$uri7JsbN0l',
                                            type: 'configuration/entityTypes/Organization/attributes/Name',
                                            value: 'name value'
                                        }
                                    ]
                                }
                            },
                            _a);
                        props = __assign(__assign({}, defaultProps), { attributeValue: __assign(__assign({}, defaultProps.attributeValue), { refEntity: [
                                    {
                                        crosswalks: [],
                                        objectURI: refEntityUri,
                                        type: 'configuration/entityTypes/Organization'
                                    }
                                ] }) });
                        mdmValues = __assign(__assign({}, defaultMdmValues), { modifiedEntities: modifiedEntities });
                        user = setUp({ props: props, mdmValues: mdmValues }).user;
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('arrow-expand-button'))];
                    case 1:
                        _b.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('select-dropdown-indicator'))];
                    case 2:
                        _b.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByText('Create new Organization'))];
                    case 3:
                        _b.sent();
                        expect(mdmActions.entityDeleted).toHaveBeenCalledWith(refEntityUri);
                        expect(mdmActions.entityCreated).toHaveBeenCalledWith({
                            attributes: {},
                            timestamp: expect.any(Number),
                            type: 'configuration/entityTypes/Organization',
                            uri: expect.any(String)
                        });
                        expect(props.onChangeAttribute).toHaveBeenCalledWith({
                            attributeType: props.attributeType,
                            uri: props.attributeValue.uri,
                            value: __assign(__assign({}, props.attributeValue), { label: undefined, refEntity: [{ objectURI: expect.any(String), type: 'configuration/entityTypes/Organization' }], refRelation: [{ objectURI: 'relations/T79PZtL', type: 'configuration/sources/Reltio' }] })
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it('should create new entity with init value when onCreate prop was called with initValue argument', function () { return __awaiter(void 0, void 0, void 0, function () {
            var props, user;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        props = __assign(__assign({}, defaultProps), { attributeValue: __assign(__assign({}, defaultProps.attributeValue), { label: 'organization entity 1', refEntity: [
                                    {
                                        crosswalks: [],
                                        objectURI: 'entities/0C32GxR',
                                        type: 'configuration/entityTypes/Organization'
                                    }
                                ], refRelation: [
                                    {
                                        crosswalks: [],
                                        objectURI: 'relations/T79PZtL',
                                        type: 'configuration/sources/Reltio'
                                    }
                                ] }) });
                        user = setUp({ props: props }).user;
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('arrow-expand-button'))];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('select-dropdown-indicator'))];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByText('Create new Organization'))];
                    case 3:
                        _a.sent();
                        expect(mdmActions.entityDeleted).not.toHaveBeenCalled();
                        expect(mdmActions.entityCreated).toHaveBeenCalledWith({
                            attributes: {},
                            timestamp: expect.any(Number),
                            type: 'configuration/entityTypes/Organization',
                            uri: expect.any(String)
                        });
                        expect(props.onChangeAttribute).toHaveBeenCalledWith({
                            attributeType: props.attributeType,
                            uri: props.attributeValue.uri,
                            value: __assign(__assign({}, props.attributeValue), { label: undefined, refEntity: [{ objectURI: expect.any(String), type: 'configuration/entityTypes/Organization' }], refRelation: [{ objectURI: 'relations/T79PZtL', type: 'configuration/sources/Reltio' }] })
                        });
                        return [2 /*return*/];
                }
            });
        }); });
    });
    describe('errors highlighting', function () {
        var fullError = {
            type: mdm_sdk_1.ErrorType.invalid,
            attributeTypeUri: defaultProps.attributeType.uri,
            parentUri: defaultProps.attributeValue.uri,
            uri: 'someUrl',
            source: mdm_sdk_1.ErrorSource.validationService,
            severity: mdm_sdk_1.ErrorSeverity.ERROR
        };
        it('should not highlight error if it have uri', function () {
            setUp({ error: fullError });
            expect(scrollIntoRef).not.toHaveBeenCalledWith();
        });
        it('should highlight error if it have same parent uri, empty uri, and attribute type uri', function () {
            var error = __assign(__assign({}, fullError), { uri: '' });
            setUp({ error: error });
            expect(scrollIntoRef).toHaveBeenCalled();
        });
    });
});
