"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 MdmModuleContext_1 = require("../../../../../contexts/MdmModuleContext");
var types_1 = require("../../../types");
var CollapsibleItemsContext_1 = require("../../../contexts/CollapsibleItemsContext");
var RelationActivity_1 = require("./RelationActivity");
var defaultItems = [
    {
        id: '89tO5c5G',
        timestamp: 1621250955807,
        objectUri: 'relations/edEoxDC',
        objectType: 'configuration/relationTypes/HasAddress',
        startObjectUri: 'entities/10hy6j0b',
        startObjectLabel: 'item 1 start object label',
        endObjectUri: 'entities/1BVkicLG',
        endObjectLabel: 'item 1 end object label',
        data: { type: types_1.ActivityTypes.RELATIONSHIP_CHANGED },
        deltaCollection: {
            ovChanged: true,
            delta: [
                {
                    type: 'ATTRIBUTE_CHANGED',
                    attributeType: 'configuration/relationTypes/HasAddress/attributes/AddressType',
                    newValue: { value: 'CLIN', ov: true, id: 'yTn28IobS', sources: ['Reltio'] },
                    oldValue: { value: 'BUSI', ov: true, id: 'yTn28IobS', sources: ['Reltio'] }
                }
            ]
        }
    },
    {
        id: '473Jsm3S',
        timestamp: 1621250955807,
        objectUri: 'relations/dK321SxZ',
        objectType: 'configuration/relationTypes/HasAddress',
        startObjectUri: 'entities/l28Nd2Zx',
        startObjectLabel: 'item 2 start object label',
        endObjectUri: 'entities/oP23Nsm3',
        endObjectLabel: 'item 2 end object label',
        data: { type: types_1.ActivityTypes.RELATIONSHIP_CHANGED },
        deltaCollection: {
            ovChanged: true,
            delta: [
                {
                    type: 'ATTRIBUTE_CHANGED',
                    attributeType: 'configuration/relationTypes/HasAddress/attributes/AddressType',
                    newValue: { value: 'CLINS', ov: true, id: '2BY80NuxW', sources: ['Reltio'] },
                    oldValue: { value: 'BUSIQ', ov: true, id: '2BY80NuxW', sources: ['Reltio'] }
                }
            ]
        }
    }
];
var defaultData = {
    uri: 'activities/f0efd6b4-129b-4379-a37c-ac2c08e3f2a5',
    user: 'alexander.kirsanov',
    timestamp: 1622096971385,
    items: defaultItems,
    itemsTotal: 2
};
var defaultProps = {
    data: defaultData,
    type: types_1.ActivityTypes.RELATIONSHIP_CHANGED
};
var defaultMdmValues = {
    metadata: {
        entityTypes: [],
        relationTypes: [
            {
                uri: 'configuration/relationTypes/HasAddress',
                label: 'Has address',
                attributes: [
                    {
                        label: 'Address type',
                        name: 'AddressType',
                        type: 'String',
                        uri: 'configuration/relationTypes/HasAddress/attributes/AddressType'
                    }
                ]
            }
        ]
    },
    uiPath: 'https://reltio.com/nui'
};
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;
    var Providers = function (_a) {
        var children = _a.children;
        return (react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues },
            react_1.default.createElement(CollapsibleItemsContext_1.CollapsibleItemsProvider, null, children)));
    };
    return (0, react_2.render)(react_1.default.createElement(RelationActivity_1.RelationActivity, __assign({}, props)), { wrapper: Providers });
};
describe('Relation activity tests', function () {
    it('should render minimized if itemsTotal is 1 and there is not delta field', function () {
        var props = __assign(__assign({}, defaultProps), { data: __assign(__assign({}, defaultData), { items: [__assign(__assign({}, defaultItems[0]), { deltaCollection: undefined })], itemsTotal: 1 }) });
        setUp({ props: props });
        var title = react_2.screen.getByTestId('relation-activity-title');
        (0, react_2.within)(title).getByText('item 1 start object label');
        (0, react_2.within)(title).getByText('item 1 end object label');
        (0, react_2.within)(title).getByText('Relationship updated');
        expect(react_2.screen.queryByTestId('reltio-activity-log-record')).not.toBeInTheDocument();
    });
    it('should render maximized if itemsTotal is 1 but there is delta field', function () {
        var props = __assign(__assign({}, defaultProps), { data: __assign(__assign({}, defaultData), { items: defaultItems.slice(0, 1), itemsTotal: 1 }) });
        setUp({ props: props });
        var title = react_2.screen.getByTestId('relation-activity-title');
        (0, react_2.within)(title).getByText('Relationship updated');
        expect((0, react_2.within)(title).queryByText('item 1 start object label')).not.toBeInTheDocument();
        expect((0, react_2.within)(title).queryByText('item 1 end object label')).not.toBeInTheDocument();
        var record = react_2.screen.getByTestId('reltio-activity-log-record');
        (0, react_2.within)(record).getByText('item 1 start object label');
        (0, react_2.within)(record).getByText('item 1 end object label');
        expect(record).toHaveTextContent('Address type:');
        expect(record).toHaveTextContent('BUSI');
        expect(record).toHaveTextContent('CLIN');
        expect(record).toHaveTextContent('edited');
    });
    it('should render maximized if itemsTotal is not 1', function () {
        setUp();
        var title = react_2.screen.getByTestId('relation-activity-title');
        (0, react_2.within)(title).getByText('Relationship updated');
        expect((0, react_2.within)(title).queryByText('item 1 start object label')).not.toBeInTheDocument();
        expect((0, react_2.within)(title).queryByText('item 1 end object label')).not.toBeInTheDocument();
        expect((0, react_2.within)(title).queryByText('item 2 start object label')).not.toBeInTheDocument();
        expect((0, react_2.within)(title).queryByText('item 2 end object label')).not.toBeInTheDocument();
        var records = react_2.screen.getAllByTestId('reltio-activity-log-record');
        (0, react_2.within)(records[0]).getByText('item 1 start object label');
        (0, react_2.within)(records[0]).getByText('item 1 end object label');
        expect(records[0]).toHaveTextContent('Address type:');
        expect(records[0]).toHaveTextContent('BUSI');
        expect(records[0]).toHaveTextContent('CLIN');
        expect(records[0]).toHaveTextContent('edited');
        (0, react_2.within)(records[1]).getByText('item 2 start object label');
        (0, react_2.within)(records[1]).getByText('item 2 end object label');
        expect(records[1]).toHaveTextContent('Address type:');
        expect(records[1]).toHaveTextContent('BUSIQ');
        expect(records[1]).toHaveTextContent('CLINS');
        expect(records[1]).toHaveTextContent('edited');
    });
});
