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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
    return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
import React from 'react';
import i18n from 'ui-i18n';
import { mockResizeObserver } from 'jsdom-testing-mocks';
import { render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MdmModuleProvider } from '../../../contexts/MdmModuleContext';
import { ActivityLog } from './ActivityLog';
describe('Activity log tests', function () {
    mockResizeObserver();
    var activities = [
        {
            uri: 'activities/de19-08e1-b220b95c',
            user: 'polina.arsenteva',
            label: 'USER_LOGIN',
            description: 'User polina.arsenteva was logged in',
            timestamp: 1622625987531,
            items: [
                {
                    id: '3Gme7xNf',
                    user: 'polina.arsenteva',
                    method: 'POST',
                    url: '/reltio/api/alenat/activities',
                    clientType: 'Reltio UI',
                    timestamp: 1622625987531
                }
            ],
            itemsTotal: 1
        },
        {
            uri: 'activities/6a7f-1247-7db88358',
            user: 'vyacheslav.kovyazin',
            label: 'USER_SEARCH',
            description: '{"activity":{"query":"filter=((equals(type%2C\'configuration%2FentityTypes%2FREGISTRY\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FDoctesting\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FPeople\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FHCP\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FAZGlobalLOV\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FSalesDept\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FTrial1\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FMine\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FDetailLoadTracker\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FProcessTracker\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FLocation\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FHCA\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FMarketingDept\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FETLLOV\')%20or%20equals(type%2C\'configuration%2FentityTypes%2FOMG\'))%20and%20exists(attributes.Commenters))","uiState":{"view":{"searchResultsMode":"list","entityTypeTab":"configuration/entityTypes/HCP","sortField":null,"sortOrder":null,"tabs":{"configuration/entityTypes/REGISTRY":[{"id":"label","label":"Profile","size":250},{"id":"entityId","label":"Entity ID","size":366.5},{"id":"scores","label":"Scores","size":366.5}],"configuration/entityTypes/Doctesting":[{"id":"label","label":"Profile","size":250},{"id":"entityId","label":"Entity ID","size":370.5},{"id":"scores","label":"Scores","size":370.5}],"configuration/entityTypes/People":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}],"configuration/entityTypes/HCP":[{"id":"label","label":"Profile","size":250},{"id":"entityId","label":"Entity ID","size":366.5},{"id":"scores","label":"Scores","size":366.5}],"configuration/entityTypes/AZGlobalLOV":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}],"configuration/entityTypes/SalesDept":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}],"configuration/entityTypes/Trial1":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}],"configuration/entityTypes/Mine":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}],"configuration/entityTypes/DetailLoadTracker":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}],"configuration/entityTypes/ProcessTracker":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}],"configuration/entityTypes/Location":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}],"configuration/entityTypes/HCA":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}],"configuration/entityTypes/MarketingDept":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}],"configuration/entityTypes/ETLLOV":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}],"configuration/entityTypes/OMG":[{"id":"label","label":"Profile"},{"id":"entityId","label":"Entity ID"},{"id":"scores","label":"Scores"}]},"previewPanelMode":null},"facets":{},"advanced":[{"attributes":[{"data":{"fieldName":"attributes.Commenters"},"operator":"and","filter":"exists","id":"U547D8x2M5bIjwofm3s6n","values":[]}],"operator":"or","entityTypes":[],"id":"Di2JkM2JryMZpOzjiN-U_"}],"searchOptions":{"searchByOv":false,"ovOnly":false},"keyword":null,"map":null,"version":"2.0","readableQuery":"Commenter exists"}},"version":"2.0"}',
            timestamp: 1622451175422,
            items: [
                {
                    id: '7G4iT0Rd',
                    user: 'vyacheslav.kovyazin',
                    method: 'POST',
                    url: '/reltio/api/alenat/activities',
                    clientType: 'Reltio UI',
                    timestamp: 1622451175422
                }
            ],
            itemsTotal: 1
        },
        {
            uri: 'activities/6a7f-1247-7db88358',
            user: 'vyacheslav.kovyazin',
            label: 'NOT_IMPLEMENTED_ACTIVITY',
            description: 'none',
            timestamp: 1622451175422,
            items: [
                {
                    id: '7G4iT0Rd',
                    user: 'vyacheslav.kovyazin',
                    method: 'POST',
                    url: '/reltio/api/alenat/activities',
                    clientType: 'Reltio UI',
                    timestamp: 1622451175422
                }
            ],
            itemsTotal: 1
        },
        {
            uri: 'activities/8debe08d-8602-42d6-9db6-9107bc44d4c6',
            user: 'olga.silina',
            timestamp: 1663335811251,
            items: [
                {
                    id: 'Hsj3l43',
                    user: 'olga.silina',
                    method: 'POST',
                    url: '/reltio/api/alenat/activities',
                    clientType: 'Reltio UI',
                    timestamp: 1663335811251,
                    objectUri: 'entities/11B3njW5',
                    objectType: 'configuration/entityTypes/HCP',
                    objectLabel: 'entity 1',
                    data: {
                        type: 'ENTITIES_MERGED_MANUALLY'
                    }
                },
                {
                    id: 'fjS339S',
                    user: 'olga.silina',
                    method: 'POST',
                    url: '/reltio/api/alenat/activities',
                    clientType: 'Reltio UI',
                    timestamp: 1663335812359,
                    data: {
                        type: 'NOT_IMPLEMENTED_ACTIVITY'
                    }
                },
                {
                    id: 'kL23s23',
                    user: 'olga.silina',
                    method: 'POST',
                    url: '/reltio/api/alenat/activities',
                    clientType: 'Reltio UI',
                    timestamp: 1663335810156,
                    objectUri: 'entities/8Nms3KlS',
                    objectType: 'configuration/entityTypes/HCP',
                    objectLabel: 'entity 2',
                    data: {
                        type: 'ENTITY_LOST_MERGE'
                    }
                }
            ],
            itemsTotal: 3
        },
        {
            uri: 'activities/ds31343-8602-43d7-9mnb6-2127lc45d4c6',
            user: 'alexander.kirsanov',
            timestamp: 1663335811280,
            items: [
                {
                    id: '0Ls3nm8J',
                    user: 'alexander.kirsanov',
                    method: 'POST',
                    url: '/reltio/api/alenat/activities',
                    clientType: 'Reltio UI',
                    timestamp: 1663335811280,
                    objectUri: 'entities/9MswQl71',
                    objectType: 'configuration/entityTypes/HCP',
                    objectLabel: 'entity 3',
                    data: {
                        type: 'ENTITIES_MERGED_MANUALLY'
                    }
                }
            ],
            itemsTotal: 1
        },
        {
            uri: 'activities/545aadab-31e2-4d74-9e70-9154c55e6b62',
            user: 'test@reltio.com',
            timestamp: 1750062462522,
            items: [
                {
                    id: '00000-00011DH',
                    user: 'test@reltio.com',
                    method: 'POST',
                    url: '/reltio/api/LocalTest/segments',
                    clientType: 'UNKNOWN',
                    timestamp: 1750062462522,
                    objectUri: 'segments/07byrT0',
                    objectLabel: 'Boolean test',
                    data: {
                        type: 'SEGMENT_UPDATE'
                    },
                    deltaCollection: {
                        delta: [
                            {
                                type: 'ATTRIBUTE_CHANGED',
                                attributeType: 'configuration/segments/attributes/rule',
                                newValue: {
                                    value: "(equals(entity.type,'configuration/entityTypes/Company') and equals(entity.attributes.Name,'New company name')) or (equals(entity.type,'configuration/entityTypes/Location') and (equals(interaction.type,'configuration/interactionTypes/Prescriptions') and equals(interaction.attributes.Medication,'New medication')))"
                                },
                                oldValue: {
                                    value: "(equals(entity.type,'configuration/entityTypes/Company') and equals(entity.attributes.Name,'Old company name')) or (equals(entity.type,'configuration/entityTypes/Location') and (equals(interaction.type,'configuration/interactionTypes/Prescriptions') and equals(interaction.attributes.Medication,'Old medication')))"
                                }
                            },
                            {
                                type: 'ATTRIBUTE_CHANGED',
                                attributeType: 'configuration/segments/attributes/status',
                                newValue: {
                                    value: 'submitted'
                                },
                                oldValue: {
                                    value: 'live'
                                }
                            },
                            {
                                type: 'ATTRIBUTE_CHANGED',
                                attributeType: 'configuration/segments/attributes/sharing',
                                newValue: {
                                    value: 'public'
                                },
                                oldValue: {
                                    value: 'private'
                                }
                            },
                            {
                                type: 'ATTRIBUTE_CHANGED',
                                attributeType: 'configuration/segments/attributes/schedule',
                                newValue: {
                                    value: {
                                        startTime: '2025-08-05T18:30:00Z',
                                        repeat: 'RRULE:INTERVAL=1;FREQ=DAILY;BYHOUR=8;BYMINUTE=35'
                                    }
                                },
                                oldValue: {
                                    value: {
                                        startTime: '2025-10-05T18:30:00Z',
                                        repeat: 'RRULE:INTERVAL=1;FREQ=DAILY;BYHOUR=8;BYMINUTE=35'
                                    }
                                }
                            },
                            {
                                type: 'ATTRIBUTE_CHANGED',
                                attributeType: 'configuration/segments/attributes/label',
                                newValue: {
                                    value: 'New name'
                                },
                                oldValue: {
                                    value: 'Old name'
                                }
                            },
                            {
                                type: 'ATTRIBUTE_ADDED',
                                attributeType: 'configuration/segments/attributes/description',
                                newValue: {
                                    value: 'Added description'
                                }
                            }
                        ]
                    },
                    eventId: '1750062462522_02DTzOy'
                }
            ],
            itemsTotal: 1
        },
        {
            uri: 'activities/545aadab-31e2-4d74-9e70-9154c55e6b63',
            user: 'test@reltio.com',
            timestamp: 1750062462522,
            items: [
                {
                    id: '00000-00011DH',
                    user: 'test@reltio.com',
                    method: 'POST',
                    url: '/reltio/api/LocalTest/segments',
                    clientType: 'UNKNOWN',
                    timestamp: 1750062462522,
                    objectUri: 'segments/07byrT0',
                    objectLabel: 'Boolean test',
                    data: {
                        type: 'SEGMENT_UPDATE'
                    },
                    deltaCollection: {
                        delta: [
                            {
                                type: 'ATTRIBUTE_REMOVED',
                                attributeType: 'configuration/segments/attributes/description',
                                oldValue: {
                                    value: 'Old removed description'
                                }
                            }
                        ]
                    },
                    eventId: '1750062462522_02DTzOy'
                }
            ],
            itemsTotal: 1
        },
        {
            uri: 'activities/545aadab-31e2-4d74-9e70-9154c55e6b61',
            user: 'test@reltio.com',
            timestamp: 1750062462522,
            items: [
                {
                    id: '00000-00011DH',
                    user: 'test@reltio.com',
                    method: 'POST',
                    url: '/reltio/api/LocalTest/segments',
                    clientType: 'UNKNOWN',
                    timestamp: 1750062462522,
                    objectUri: 'segments/07byrT0',
                    objectLabel: 'Boolean test',
                    data: {
                        type: 'SEGMENT_CREATE'
                    },
                    eventId: '1750062462522_02DTzOy'
                }
            ],
            itemsTotal: 1
        },
        {
            uri: 'activities/545aadab-31e2-4d74-9e70-9154c55e6b60',
            user: 'test@reltio.com',
            timestamp: 1750062462522,
            items: [
                {
                    id: '00000-00011DH',
                    user: 'test@reltio.com',
                    method: 'POST',
                    url: '/reltio/api/LocalTest/segments',
                    clientType: 'UNKNOWN',
                    timestamp: 1750062462522,
                    objectUri: 'segments/07byrT0',
                    objectLabel: 'Boolean test',
                    data: {
                        type: 'SEGMENT_DELETE'
                    },
                    eventId: '1750062462522_02DTzOy'
                }
            ],
            itemsTotal: 1
        }
    ];
    var defaultProps = {
        width: 500,
        height: 500,
        activities: activities,
        count: 10,
        page: 0,
        onChangePage: jest.fn(),
        rowsPerPage: 10,
        onChangeRowsPerPage: jest.fn(),
        rowsPerPageOptions: [10, 20, 30]
    };
    var setUp = function (props) {
        if (props === void 0) { props = {}; }
        var user = userEvent.setup();
        var metadata = { entityTypes: [] };
        var Providers = function (_a) {
            var children = _a.children;
            return (React.createElement(MdmModuleProvider, { values: { metadata: metadata } }, children));
        };
        return __assign({ user: user }, render(React.createElement(ActivityLog, __assign({}, defaultProps, props)), { wrapper: Providers }));
    };
    beforeEach(function () {
        jest.spyOn(console, 'warn').mockReturnValue();
        jest.spyOn(Date, 'now').mockReturnValue(1622625987531);
    });
    afterEach(function () {
        jest.resetAllMocks();
    });
    it('should render correctly', function () {
        setUp();
        var activityItems = screen.getAllByTestId('activity-log-item');
        var activityGroupItems = screen.getAllByTestId('activity-log-group-item');
        expect(activityItems).toHaveLength(8);
        expect(activityGroupItems).toHaveLength(4);
        within(activityGroupItems[0]).getByText('Today');
        within(activityItems[0]).getByText(activities[0].user);
        within(activityItems[0]).getByText(i18n.date(activities[0].timestamp, 'LT'));
        within(activityItems[0]).getByText('Logged in');
        within(activityGroupItems[1]).getByText(i18n.date(activities[1].timestamp, 'LL'));
        within(activityItems[1]).getByText(activities[1].user);
        within(activityItems[1]).getByText(i18n.date(activities[1].timestamp, 'LT'));
        within(activityItems[1]).getByText('Searched');
        within(activityItems[1]).getByText('Commenter exists');
        within(activityGroupItems[2]).getByText(i18n.date(activities[3].timestamp, 'LL'));
        within(activityItems[2]).getByText(activities[3].user);
        within(activityItems[2]).getByText(i18n.date(activities[3].timestamp, 'LT'));
        within(activityItems[2]).getByText('Profile merged manually');
        within(activityItems[2]).getByText('entity 1');
        within(activityItems[2]).getByText('Profile lost merge');
        within(activityItems[2]).getByText('entity 2');
        within(activityItems[3]).getByText(activities[4].user);
        within(activityItems[3]).getByText(i18n.date(activities[4].timestamp, 'LT'));
        within(activityItems[3]).getByText('Profile merged manually');
        within(activityItems[3]).getByText('entity 3');
        within(activityItems[4]).getByText(activities[5].user);
        within(activityItems[4]).getByText(i18n.date(activities[5].timestamp, 'LT'));
        within(activityItems[4]).getByText('Segment updated');
        within(activityItems[4]).getByText('Boolean test');
        within(activityItems[4]).getByText('Query:');
        within(activityItems[4]).getByText('Shared with:');
        within(activityItems[4]).getByText('private');
        within(activityItems[4]).getByText('public');
        within(activityItems[4]).getByText('3 more updates');
        within(activityItems[5]).getByText(activities[6].user);
        within(activityItems[5]).getByText(i18n.date(activities[6].timestamp, 'LT'));
        within(activityItems[5]).getByText('Segment updated');
        within(activityItems[5]).getByText('Boolean test');
        within(activityItems[5]).getByText('Description:');
        within(activityItems[5]).getByText('Old removed description');
        within(activityItems[6]).getByText(activities[7].user);
        within(activityItems[6]).getByText(i18n.date(activities[7].timestamp, 'LT'));
        within(activityItems[6]).getByText('Segment created');
        within(activityItems[6]).getByText('Boolean test');
        within(activityItems[7]).getByText(activities[8].user);
        within(activityItems[7]).getByText(i18n.date(activities[8].timestamp, 'LT'));
        within(activityItems[7]).getByText('Segment deleted');
        within(activityItems[7]).getByText('Boolean test');
        expect(console.warn).toHaveBeenCalledWith('Activities not implemented:', activities[2].items);
        expect(console.warn).toHaveBeenCalledWith('Activities not implemented:', [activities[3].items[1]]);
    });
    it('should toggle group item collapsed correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp().user;
                    screen.getAllByTestId('collapse-button');
                    expect(screen.getAllByTestId('activity-log-item')).toHaveLength(8);
                    return [4 /*yield*/, user.click(screen.getAllByTestId('collapse-button')[0])];
                case 1:
                    _a.sent();
                    expect(screen.getAllByTestId('activity-log-item')).toHaveLength(7);
                    return [4 /*yield*/, user.click(screen.getAllByTestId('collapse-button')[0])];
                case 2:
                    _a.sent();
                    expect(screen.getAllByTestId('activity-log-item')).toHaveLength(8);
                    return [2 /*return*/];
            }
        });
    }); });
    it('should not fail for activities without items', function () {
        var activitiesWithoutItems = [
            {
                uri: 'activities/6a7f-1247-7db88358',
                user: 'vyacheslav.kovyazin',
                label: 'NOT_IMPLEMENTED_ACTIVITY',
                description: 'none',
                timestamp: 1622451175422,
                itemsTotal: 0
            }
        ];
        setUp({ activities: activitiesWithoutItems });
        expect(screen.queryByTestId('activity-log-item')).not.toBeInTheDocument();
    });
    it('should not render value for schedule attribute when value is null', function () {
        var activitiesWithNullSchedule = [
            {
                uri: 'activities/1234-5678-91011',
                user: 'test@reltio.com',
                label: 'SEGMENT_UPDATE',
                description: 'Segment schedule updated',
                timestamp: 1750062462522,
                items: [
                    {
                        id: '00000-00011DH',
                        user: 'test@reltio.com',
                        method: 'POST',
                        url: '/reltio/api/LocalTest/segments',
                        clientType: 'UNKNOWN',
                        timestamp: 1750062462522,
                        objectUri: 'segments/07byrT0',
                        objectLabel: 'Boolean test',
                        data: {
                            type: 'SEGMENT_UPDATE'
                        },
                        deltaCollection: {
                            delta: [
                                {
                                    type: 'ATTRIBUTE_CHANGED',
                                    attributeType: 'configuration/segments/attributes/schedule',
                                    newValue: {
                                        value: null
                                    },
                                    oldValue: {
                                        value: null
                                    }
                                }
                            ]
                        },
                        eventId: '1750062462522_02DTzOy'
                    }
                ],
                itemsTotal: 1
            }
        ];
        setUp({ activities: activitiesWithNullSchedule });
        var activityItems = screen.getAllByTestId('activity-log-item');
        expect(activityItems).toHaveLength(1);
        expect(activityItems[0].querySelector('.firstLetterCapitalized')).not.toBeInTheDocument();
    });
});
