"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 __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 NestedAttributeEditor_1 = require("./NestedAttributeEditor");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { evaluateDeepEntityLabel: jest.fn(), getLabel: jest.fn() })); });
var mdmValues = {
    dependentLookups: { editors: {}, structure: {}, initedTypeUris: [] }
};
var setUp = function (props) {
    var Providers = function (_a) {
        var children = _a.children;
        return (react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues }, children));
    };
    return (0, react_2.render)(react_1.default.createElement(NestedAttributeEditor_1.NestedAttributeEditor, __assign({}, props)), { wrapper: Providers });
};
describe('Nested attribute editor tests', function () {
    it('should render correctly with attributes', function () {
        var attributeType = {
            uri: 'configuration/entityTypes/HCP/attributes/NestedTest',
            type: 'Nested',
            name: 'NestedTest',
            label: 'Nested Test',
            attributes: [
                {
                    uri: 'configuration/entityTypes/HCP/attributes/NestedTest/attributes/FirstName',
                    type: 'String',
                    name: 'FirstName',
                    label: 'First Name'
                }
            ]
        };
        var props = {
            mode: mdm_sdk_1.Mode.Editing,
            expanded: true,
            metadata: {
                entityTypes: [{ uri: 'configuration/entityTypes/HCP', label: 'HCP', attributes: [attributeType] }]
            },
            onAddAttributes: jest.fn(),
            onDeleteAttribute: jest.fn(),
            onChangeAttribute: jest.fn(),
            additionalControlsRenderer: function () { return null; },
            attributeValue: {
                uri: 'entities/rhW31Ms7/attributes/NestedTest/72NsbAsm9',
                type: 'configuration/entityTypes/HCP/attributes/NestedTest',
                value: {
                    FirstName: [
                        {
                            uri: 'entities/rhW31Ms7/attributes/NestedTest/72NsbAsm9/FirstName/91NsaK26',
                            value: 'first name value'
                        }
                    ]
                }
            },
            attributeType: attributeType
        };
        setUp(props);
        react_2.screen.getByText('More attributes');
        react_2.screen.getByText('First Name');
        expect(react_2.screen.getByRole('textbox')).toHaveValue('first name value');
    });
    it('should render correctly with analytics attributes', function () {
        var attributeType = {
            uri: 'configuration/entityTypes/HCP/analyticsAttributes/IQ',
            type: 'Nested',
            name: 'IQ',
            label: 'IQ',
            analyticsAttributes: [
                {
                    uri: 'configuration/entityTypes/HCP/analyticsAttributes/IQ/analyticsAttributes/score',
                    type: 'Int',
                    name: 'score',
                    label: 'IQ Score'
                }
            ]
        };
        var props = {
            mode: mdm_sdk_1.Mode.Editing,
            expanded: true,
            metadata: {
                entityTypes: [
                    { uri: 'configuration/entityTypes/HCP', label: 'HCP', analyticsAttributes: [attributeType] }
                ]
            },
            onAddAttributes: jest.fn(),
            onDeleteAttribute: jest.fn(),
            onChangeAttribute: jest.fn(),
            additionalControlsRenderer: function () { return null; },
            attributeValue: {
                uri: 'entities/rhW31Ms7/analyticsAttributes/IQ/72NsbAsm9',
                type: 'configuration/entityTypes/HCP/attributes/IQ',
                value: {
                    score: [
                        {
                            uri: 'entities/rhW31Ms7/attributes/IQ/72NsbAsm9/score/91NsaK26',
                            value: 100
                        }
                    ]
                }
            },
            attributeType: attributeType
        };
        setUp(props);
        expect(react_2.screen.queryByText('More attributes')).not.toBeInTheDocument();
        react_2.screen.getByText('IQ Score');
        react_2.screen.getByText('100');
    });
});
