"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 ProfileActivity_1 = require("./ProfileActivity");
var defaultItems = [
    {
        id: '30Y8UsZr',
        timestamp: 1622096971385,
        objectUri: 'entities/k5nO0xA',
        objectType: 'configuration/entityTypes/HCP',
        objectLabel: 'item 1',
        data: { type: types_1.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: types_1.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: types_1.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_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(ProfileActivity_1.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: types_1.ActivityTypes.ENTITY_CHANGED }
                    }
                ], itemsTotal: 1 }) });
        setUp({ props: props });
        var title = react_2.screen.getByTestId('profile-activity-title');
        (0, react_2.within)(title).getByText('item 1');
        (0, react_2.within)(title).getByText('Profile 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('profile-activity-title');
        (0, react_2.within)(title).getByText('Profile updated');
        expect((0, react_2.within)(title).queryByText('item 1')).not.toBeInTheDocument();
        var record = react_2.screen.getByTestId('reltio-activity-log-record');
        (0, react_2.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 = react_2.screen.getByTestId('profile-activity-title');
        (0, react_2.within)(title).getByText('Profile updated');
        expect((0, react_2.within)(title).queryByText('item 1')).not.toBeInTheDocument();
        expect((0, react_2.within)(title).queryByText('item 2')).not.toBeInTheDocument();
        var records = react_2.screen.getAllByTestId('reltio-activity-log-record');
        (0, react_2.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');
        (0, react_2.within)(records[1]).getByText('item 2');
        expect(records[1]).toHaveTextContent('String:');
        expect(records[1]).toHaveTextContent('removed value');
        expect(records[1]).toHaveTextContent('deleted');
    });
});
