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, within } from '@testing-library/react';
import { MdmModuleProvider } from '../../../../../contexts/MdmModuleContext';
import { ActivityTypes } from '../../../types';
import { CollapsibleItemsProvider } from '../../../contexts/CollapsibleItemsContext';
import { ProfileActivity } from './ProfileActivity';
var defaultItems = [
    {
        id: '30Y8UsZr',
        timestamp: 1622096971385,
        objectUri: 'entities/k5nO0xA',
        objectType: 'configuration/entityTypes/HCP',
        objectLabel: 'item 1',
        data: { type: ActivityTypes.ENTITY_CHANGED },
        deltaCollection: {
            ovChanged: true,
            delta: [
                {
                    type: 'ATTRIBUTE_CHANGED',
                    attributeType: 'configuration/entityTypes/HCP/attributes/TextField',
                    newValue: { value: 'new value', ov: true, id: '3UIcE257b', sources: ['Reltio'] },
                    oldValue: { value: 'old value', ov: true, id: '3UIcE257b', sources: ['Reltio'] }
                }
            ]
        }
    },
    {
        id: 'o8NMgwA3',
        timestamp: 1622096971385,
        objectUri: 'entities/jD9maD2',
        objectType: 'configuration/entityTypes/HCP',
        objectLabel: 'item 2',
        data: { type: ActivityTypes.ENTITY_CHANGED },
        deltaCollection: {
            ovChanged: true,
            delta: [
                {
                    type: 'ATTRIBUTE_REMOVED',
                    attributeType: 'configuration/entityTypes/HCP/attributes/TextField',
                    oldValue: { value: 'removed value', ov: true, id: 'jd9SamA', 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: ActivityTypes.ENTITY_CHANGED
};
var defaultMdmValues = {
    metadata: {
        entityTypes: [
            {
                uri: 'configuration/entityTypes/HCP',
                label: 'HCP',
                attributes: [
                    {
                        label: 'String',
                        name: 'TextField',
                        type: 'String',
                        uri: 'configuration/entityTypes/HCP/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(ProfileActivity, __assign({}, props)), { wrapper: Providers });
};
describe('Profile 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: [
                    {
                        id: '30Y8UsZr',
                        timestamp: 1622096971385,
                        objectUri: 'entities/k5nO0xA',
                        objectType: 'configuration/entityTypes/HCP',
                        objectLabel: 'item 1',
                        data: { type: ActivityTypes.ENTITY_CHANGED }
                    }
                ], itemsTotal: 1 }) });
        setUp({ props: props });
        var title = screen.getByTestId('profile-activity-title');
        within(title).getByText('item 1');
        within(title).getByText('Profile updated');
        expect(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 = screen.getByTestId('profile-activity-title');
        within(title).getByText('Profile updated');
        expect(within(title).queryByText('item 1')).not.toBeInTheDocument();
        var record = screen.getByTestId('reltio-activity-log-record');
        within(record).getByText('item 1');
        expect(record).toHaveTextContent('String:');
        expect(record).toHaveTextContent('old value');
        expect(record).toHaveTextContent('new value');
        expect(record).toHaveTextContent('edited');
    });
    it('should render maximized if itemsTotal is not 1', function () {
        setUp();
        var title = screen.getByTestId('profile-activity-title');
        within(title).getByText('Profile updated');
        expect(within(title).queryByText('item 1')).not.toBeInTheDocument();
        expect(within(title).queryByText('item 2')).not.toBeInTheDocument();
        var records = screen.getAllByTestId('reltio-activity-log-record');
        within(records[0]).getByText('item 1');
        expect(records[0]).toHaveTextContent('String:');
        expect(records[0]).toHaveTextContent('old value');
        expect(records[0]).toHaveTextContent('new value');
        expect(records[0]).toHaveTextContent('edited');
        within(records[1]).getByText('item 2');
        expect(records[1]).toHaveTextContent('String:');
        expect(records[1]).toHaveTextContent('removed value');
        expect(records[1]).toHaveTextContent('deleted');
    });
});
