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);
};
import React from 'react';
import { render, screen } from '@testing-library/react';
import { MdmModuleProvider } from '../../../contexts/MdmModuleContext';
import { CollapsibleItemsProvider } from '../contexts/CollapsibleItemsContext';
import { ActivityTypes } from '../types';
import { RelationRecord } from './RelationRecord';
var defaultDeltaCollection = {
    ovChanged: true,
    delta: [
        {
            type: 'ATTRIBUTE_CHANGED',
            attributeType: 'configuration/relationTypes/HasAddress/attributes/TextField',
            newValue: { value: 'new value', ov: true, id: '3UIcE257b', sources: ['Reltio'] },
            oldValue: { value: 'old value', ov: true, id: '3UIcE257b', sources: ['Reltio'] }
        },
        {
            type: 'ATTRIBUTE_ADDED',
            attributeType: 'configuration/relationTypes/HasAddress/attributes/TextField',
            newValue: { value: 'added value', ov: true, id: 'Sdj23PaS', sources: ['Reltio'] }
        },
        {
            type: 'ATTRIBUTE_REMOVED',
            attributeType: 'configuration/relationTypes/HasAddress/attributes/TextField',
            oldValue: { value: 'removed value', ov: true, id: '9m2Nsm3Pa', sources: ['Reltio'] }
        }
    ]
};
var defaultItem = {
    id: '3vJgNLSN',
    timestamp: 1621847085259,
    objectUri: 'relations/edEnRRW',
    objectType: 'configuration/relationTypes/HasAddress',
    startObjectUri: 'entities/sOoSQYm',
    startObjectLabel: 'start object label',
    endObjectUri: 'entities/1BVkicLG',
    endObjectLabel: 'end object label',
    data: { type: ActivityTypes.RELATIONSHIP_CHANGED },
    deltaCollection: defaultDeltaCollection
};
var defaultProps = {
    item: defaultItem
};
var defaultMdmValues = {
    metadata: {
        entityTypes: [
            {
                uri: 'configuration/relationTypes/HasAddress',
                label: 'Has address',
                attributes: [
                    {
                        label: 'String',
                        name: 'TextField',
                        type: 'String',
                        uri: 'configuration/relationTypes/HasAddress/attributes/TextField'
                    }
                ]
            }
        ]
    },
    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.createElement(MdmModuleProvider, { values: mdmValues },
            React.createElement(CollapsibleItemsProvider, null, children)));
    };
    return render(React.createElement(RelationRecord, __assign({}, props)), { wrapper: Providers });
};
describe('Relation record tests', function () {
    it('should render correctly', function () {
        setUp();
        expect(screen.queryByText('Relationship updated')).not.toBeInTheDocument();
        screen.getByText('start object label');
        screen.getByText('end object label');
        var deltaFields = screen.getAllByTestId('delta-field');
        expect(deltaFields[0]).toHaveTextContent('String:');
        expect(deltaFields[0]).toHaveTextContent('old value');
        expect(deltaFields[0]).toHaveTextContent('new value');
        expect(deltaFields[0]).toHaveTextContent('edited');
        expect(deltaFields[1]).toHaveTextContent('String:');
        expect(deltaFields[1]).toHaveTextContent('added value');
        expect(deltaFields[1]).toHaveTextContent('added');
        expect(deltaFields[2]).toHaveTextContent('String:');
        expect(deltaFields[2]).toHaveTextContent('removed value');
        expect(deltaFields[2]).toHaveTextContent('deleted');
    });
    it('should render correctly without delta', function () {
        var props = __assign(__assign({}, defaultProps), { item: __assign(__assign({}, defaultItem), { deltaCollection: undefined }) });
        setUp({ props: props });
        screen.getByText('Relationship updated');
        screen.getByText('start object label');
        screen.getByText('end object label');
        expect(screen.queryByTestId('delta-field')).not.toBeInTheDocument();
    });
});
