"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 __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 };
    }
};
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 user_event_1 = __importDefault(require("@testing-library/user-event"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var errors_1 = require("../../../helpers/errors");
var MdmModuleContext_1 = require("../../../contexts/MdmModuleContext");
var types_1 = require("../types");
var ActivityLogFilter_1 = require("./ActivityLogFilter");
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { exportActivities: jest.fn(), getAllUsersForTenant: jest.fn() })); });
jest.mock('../../../helpers/errors', function () { return (__assign(__assign({}, jest.requireActual('../../../helpers/errors')), { showErrorMessage: jest.fn() })); });
var defaultMetadata = {
    entityTypes: [
        {
            uri: 'configuration/entityTypes/HCO',
            label: 'HCO',
            attributes: [
                {
                    label: 'Name',
                    name: 'Name',
                    type: 'String',
                    uri: 'configuration/entityTypes/HCO/attributes/Name'
                },
                {
                    label: 'Status',
                    name: 'Status',
                    type: 'String',
                    uri: 'configuration/entityTypes/HCO/attributes/Status'
                }
            ]
        },
        {
            uri: 'configuration/entityTypes/Company',
            label: 'Company',
            attributes: []
        },
        {
            uri: 'configuration/entityTypes/HCP',
            label: 'HCP',
            attributes: [
                {
                    label: 'Boolean',
                    name: 'Boolean',
                    type: 'Boolean',
                    uri: 'configuration/entityTypes/HCP/attributes/Boolean'
                },
                {
                    label: 'Number',
                    name: 'Number',
                    type: 'Number',
                    uri: 'configuration/entityTypes/HCP/attributes/Number'
                },
                {
                    label: 'First Name',
                    name: 'FirstName',
                    type: 'String',
                    uri: 'configuration/entityTypes/HCP/attributes/FirstName'
                },
                {
                    label: 'Last Name',
                    name: 'LastName',
                    type: 'String',
                    uri: 'configuration/entityTypes/HCP/attributes/LastName'
                }
            ]
        }
    ],
    sources: [
        {
            uri: 'configuration/sources/IMS',
            label: 'IMS',
            icon: 'source/xyz.png',
            abbreviation: 'IMS'
        },
        {
            uri: 'configuration/sources/MUI',
            label: 'MUI',
            icon: 'source/xyz.png',
            abbreviation: 'MUI'
        },
        {
            uri: 'configuration/sources/MDS',
            label: 'MDS',
            icon: 'source/xyz.png',
            abbreviation: 'MDS'
        },
        {
            uri: 'configuration/sources/SAC',
            label: 'SAC',
            icon: 'source/xyz.png',
            abbreviation: 'SAC'
        },
        {
            uri: 'configuration/sources/SEED',
            label: 'SEED',
            icon: 'source/xyz.png',
            abbreviation: 'SEED'
        }
    ]
};
var defaultMdmValues = {
    tenant: { id: 'alenat', name: 'alenat' },
    user: {
        serviceId: 'export',
        resourcePath: ['data', 'activities'],
        userPermissions: {
            permissions: { 'export:data.activities': { EXECUTE: ['alenat'] } },
            permissionsByService: {},
            roles: {}
        }
    },
    metadata: defaultMetadata,
    exportPath: '/nui/export'
};
var mdmModuleActions = { openConsoleApp: jest.fn() };
var defaultValue = {
    users: [],
    activities: [],
    dateRange: { type: mdm_sdk_1.DateRangeTypes.WITHIN, period: [4, 'months'] }
};
var defaultProps = {
    value: defaultValue,
    entityType: (0, mdm_sdk_1.getEntityType)(defaultMetadata, 'configuration/entityTypes/HCO'),
    onChange: jest.fn(),
    exportTypes: ['json', 'csv'],
    entityUri: 'entities/7Jsn1POn6'
};
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 user = user_event_1.default.setup();
    var Providers = function (_a) {
        var children = _a.children;
        return (react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues, actions: mdmModuleActions }, children));
    };
    var result = (0, react_2.render)(react_1.default.createElement(ActivityLogFilter_1.ActivityLogFilter, __assign({}, props)), { wrapper: Providers });
    var rerender = function (props) { return result.rerender(react_1.default.createElement(ActivityLogFilter_1.ActivityLogFilter, __assign({}, defaultProps, props))); };
    return __assign(__assign({}, result), { user: user, rerender: rerender });
};
describe('Activity log filter tests', function () {
    beforeEach(function () {
        jest.spyOn(Date, 'now').mockReturnValue(1636703406900);
        mdm_sdk_1.exportActivities.mockResolvedValue({ status: 'scheduled' });
        mdm_sdk_1.getAllUsersForTenant.mockResolvedValue([
            { email: 'alexey.nikonov@reltio.com', username: 'alexey.nikonov' },
            { email: 'fedor.petrov@reltio.com', username: 'fedor.petrov' },
            { email: 'ivan.ivanov@reltio.com', username: 'ivan.ivanov' }
        ]);
    });
    afterEach(function () {
        jest.clearAllMocks();
    });
    it('should render filter label 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;
                    expect(react_2.screen.queryByRole('tooltip')).not.toBeInTheDocument();
                    return [4 /*yield*/, user.hover(react_2.screen.getByText('Within 4 months'))];
                case 1:
                    _a.sent();
                    react_2.screen.getByRole('tooltip', { name: 'Within 4 months' });
                    return [4 /*yield*/, user.hover(react_2.screen.getByText('Filter:'))];
                case 2:
                    _a.sent();
                    expect(react_2.screen.queryByRole('tooltip')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should not render export button if there is no CAN_EXPORT_ACTIVITIES permission', function () {
        var mdmValues = __assign(__assign({}, defaultMdmValues), { user: __assign(__assign({}, defaultMdmValues.user), { userPermissions: { permissions: {}, permissionsByService: {}, roles: {} } }) });
        setUp({ mdmValues: mdmValues });
        expect(react_2.screen.queryByLabelText('Export')).not.toBeInTheDocument();
    });
    it('should show tooltip on export button hover 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;
                    expect(react_2.screen.queryByRole('tooltip')).not.toBeInTheDocument();
                    return [4 /*yield*/, user.hover(react_2.screen.getByLabelText('Export'))];
                case 1:
                    _a.sent();
                    react_2.screen.getByRole('tooltip', { name: 'Export' });
                    return [4 /*yield*/, user.hover(react_2.screen.getByText('Filter:'))];
                case 2:
                    _a.sent();
                    expect(react_2.screen.queryByRole('tooltip')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should show dropdown menu on export button click correctly if exportTypes is not empty', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, menuItems;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp().user;
                    expect(react_2.screen.queryByRole('presentation')).not.toBeInTheDocument();
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Export'))];
                case 1:
                    _a.sent();
                    menuItems = (0, react_2.within)(react_2.screen.getByRole('presentation')).getAllByRole('menuitem');
                    expect(menuItems).toHaveLength(2);
                    expect(menuItems[0]).toHaveTextContent('JSON');
                    expect(menuItems[1]).toHaveTextContent('CSV');
                    return [4 /*yield*/, user.keyboard('{Escape}')];
                case 2:
                    _a.sent();
                    expect(react_2.screen.queryByRole('presentation')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should export activities on export button click correctly if exportTypes is empty', function () { return __awaiter(void 0, void 0, void 0, function () {
        var props, user, alert;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    props = __assign(__assign({}, defaultProps), { exportTypes: [] });
                    user = setUp({ props: props }).user;
                    expect(react_2.screen.queryByRole('alert')).not.toBeInTheDocument();
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Export'))];
                case 1:
                    _a.sent();
                    expect(mdm_sdk_1.exportActivities).toHaveBeenCalledWith({
                        exportPath: '/nui/export',
                        options: {
                            fileFormat: undefined
                        },
                        tenant: 'alenat',
                        filter: "(gte(timestamp, 1626076206900)) and (equals(items.objectUri, 'entities/7Jsn1POn6') or equals(items.startObjectUri, 'entities/7Jsn1POn6') or equals(items.endObjectUri, 'entities/7Jsn1POn6')) and (not equals(user, 'collaboration-service'))"
                    });
                    alert = react_2.screen.getByRole('alert');
                    (0, react_2.within)(alert).getByText('Export operation is currently in progress. You will receive an email notification once completed. Go to Export Application to view the status.');
                    return [4 /*yield*/, user.click((0, react_2.within)(alert).getByText('Export application'))];
                case 2:
                    _a.sent();
                    expect(mdmModuleActions.openConsoleApp).toHaveBeenCalledWith('Export');
                    return [2 /*return*/];
            }
        });
    }); });
    it('should export activities on export item click correctly if exportTypes is not empty', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, alert;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp().user;
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Export'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('JSON'))];
                case 2:
                    _a.sent();
                    expect(mdm_sdk_1.exportActivities).toHaveBeenCalledWith({
                        exportPath: '/nui/export',
                        options: {
                            fileFormat: 'json'
                        },
                        tenant: 'alenat',
                        filter: "(gte(timestamp, 1626076206900)) and (equals(items.objectUri, 'entities/7Jsn1POn6') or equals(items.startObjectUri, 'entities/7Jsn1POn6') or equals(items.endObjectUri, 'entities/7Jsn1POn6')) and (not equals(user, 'collaboration-service'))"
                    });
                    alert = react_2.screen.getByRole('alert');
                    (0, react_2.within)(alert).getByText('Export operation is currently in progress. You will receive an email notification once completed. Go to Export Application to view the status.');
                    (0, react_2.within)(alert).getByText('Export application');
                    return [2 /*return*/];
            }
        });
    }); });
    it('should show error message instead of snackbar on export item click if request has been rejected', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    mdm_sdk_1.exportActivities.mockRejectedValue({ errorMessage: 'Something went wrong' });
                    user = setUp().user;
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Export'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('CSV'))];
                case 2:
                    _a.sent();
                    expect(mdm_sdk_1.exportActivities).toHaveBeenCalledWith({
                        exportPath: '/nui/export',
                        options: {
                            fileFormat: 'csv'
                        },
                        tenant: 'alenat',
                        filter: "(gte(timestamp, 1626076206900)) and (equals(items.objectUri, 'entities/7Jsn1POn6') or equals(items.startObjectUri, 'entities/7Jsn1POn6') or equals(items.endObjectUri, 'entities/7Jsn1POn6')) and (not equals(user, 'collaboration-service'))"
                    });
                    expect(errors_1.showErrorMessage).toHaveBeenCalledWith({ errorMessage: 'Something went wrong' }, { defaultMessage: "Can't export activities", title: 'Error' });
                    expect(react_2.screen.queryByRole('alert')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('activity selector should work correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
        var hintText, user, activitySelector, options;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    hintText = 'One at a time! Select a single Activity and any of its filters -OR- multiple Activities with no filters.';
                    user = setUp().user;
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Filter'))];
                case 1:
                    _a.sent();
                    expect(react_2.screen.queryByText(hintText)).not.toBeInTheDocument();
                    activitySelector = (0, react_2.within)(react_2.screen.getByTestId('activity-selector')).getByRole('combobox');
                    return [4 /*yield*/, user.click(activitySelector)];
                case 2:
                    _a.sent();
                    options = react_2.screen.getAllByRole('option');
                    expect(options).toHaveLength(15);
                    expect(options[0]).toHaveTextContent('Attribute unmasked');
                    expect(options[1]).toHaveTextContent('Not matches reset');
                    expect(options[2]).toHaveTextContent('Not matches set');
                    expect(options[3]).toHaveTextContent('Potential matches found');
                    expect(options[4]).toHaveTextContent('Potential matches removed');
                    expect(options[5]).toHaveTextContent('Profile created');
                    expect(options[6]).toHaveTextContent('Profile lost merge');
                    expect(options[7]).toHaveTextContent('Profile merged');
                    expect(options[8]).toHaveTextContent('Profile merged manually');
                    expect(options[9]).toHaveTextContent('Profile merged on the fly');
                    expect(options[10]).toHaveTextContent('Profile un-merged');
                    expect(options[11]).toHaveTextContent('Profile updated');
                    expect(options[12]).toHaveTextContent('Relationship created');
                    expect(options[13]).toHaveTextContent('Relationship removed');
                    expect(options[14]).toHaveTextContent('Relationship updated');
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Potential matches found'))];
                case 3:
                    _a.sent();
                    expect(react_2.screen.queryByText(hintText)).not.toBeInTheDocument();
                    return [4 /*yield*/, user.click(activitySelector)];
                case 4:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Profile created'))];
                case 5:
                    _a.sent();
                    expect(react_2.screen.queryByText(hintText)).not.toBeInTheDocument();
                    return [4 /*yield*/, user.click(activitySelector)];
                case 6:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Profile updated'))];
                case 7:
                    _a.sent();
                    react_2.screen.getByText(hintText);
                    return [2 /*return*/];
            }
        });
    }); });
    it('should render correct additional selectors for "Profile updated" activity if entityType is passed', 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;
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Filter'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('activity-selector')).getByRole('combobox'))];
                case 2:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Profile updated'))];
                case 3:
                    _a.sent();
                    react_2.screen.getByTestId('attribute-selector');
                    react_2.screen.getByTestId('source-selector');
                    expect(react_2.screen.queryByTestId('entity-types-selector')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should render correct additional selectors for "Profile updated" activity if entityType is not passed', function () { return __awaiter(void 0, void 0, void 0, function () {
        var props, user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    props = __assign(__assign({}, defaultProps), { entityType: null });
                    user = setUp({ props: props }).user;
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Filter'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('activity-selector')).getByRole('combobox'))];
                case 2:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Profile updated'))];
                case 3:
                    _a.sent();
                    react_2.screen.getByTestId('attribute-selector');
                    react_2.screen.getByTestId('source-selector');
                    react_2.screen.getByTestId('entity-types-selector');
                    return [2 /*return*/];
            }
        });
    }); });
    it('should fill filter editor and apply it correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
        var props, _a, user, rerender, filterButton, popover, entityTypesOptions, attributesOptions, sourcesOptions, _b, dateIntervalSelector, usersOptions, newFilters;
        return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    props = __assign(__assign({}, defaultProps), { entityType: null });
                    _a = setUp({ props: props }), user = _a.user, rerender = _a.rerender;
                    filterButton = react_2.screen.getByLabelText('Filter');
                    expect(filterButton).not.toHaveClass('activeIcon');
                    return [4 /*yield*/, user.click(filterButton)];
                case 1:
                    _c.sent();
                    popover = react_2.screen.getByRole('presentation');
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('activity-selector')).getByRole('combobox'))];
                case 2:
                    _c.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Profile updated'))];
                case 3:
                    _c.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('entity-types-selector')).getByRole('combobox'))];
                case 4:
                    _c.sent();
                    entityTypesOptions = react_2.screen.getAllByRole('option');
                    expect(entityTypesOptions).toHaveLength(3);
                    expect(entityTypesOptions[0]).toHaveTextContent('Company');
                    expect(entityTypesOptions[1]).toHaveTextContent('HCO');
                    expect(entityTypesOptions[2]).toHaveTextContent('HCP');
                    return [4 /*yield*/, user.click(react_2.screen.getByText('HCP'))];
                case 5:
                    _c.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('attribute-selector')).getByRole('combobox'))];
                case 6:
                    _c.sent();
                    attributesOptions = react_2.screen.getAllByRole('option');
                    expect(attributesOptions).toHaveLength(4);
                    expect(attributesOptions[0]).toHaveTextContent('Boolean');
                    expect(attributesOptions[1]).toHaveTextContent('Number');
                    expect(attributesOptions[2]).toHaveTextContent('First Name');
                    expect(attributesOptions[3]).toHaveTextContent('Last Name');
                    return [4 /*yield*/, user.click(react_2.screen.getByText('First Name'))];
                case 7:
                    _c.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('source-selector')).getByRole('combobox'))];
                case 8:
                    _c.sent();
                    sourcesOptions = react_2.screen.getAllByRole('option');
                    expect(sourcesOptions).toHaveLength(5);
                    expect(sourcesOptions[0]).toHaveTextContent('IMS');
                    expect(sourcesOptions[1]).toHaveTextContent('MDS');
                    expect(sourcesOptions[2]).toHaveTextContent('MUI');
                    expect(sourcesOptions[3]).toHaveTextContent('SAC');
                    expect(sourcesOptions[4]).toHaveTextContent('SEED');
                    return [4 /*yield*/, user.click(react_2.screen.getByText('MUI'))];
                case 9:
                    _c.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('More than'))];
                case 10:
                    _c.sent();
                    _b = react_2.screen.getAllByTestId('date-interval-selector'), dateIntervalSelector = _b[1];
                    return [4 /*yield*/, user.type((0, react_2.within)(dateIntervalSelector).getByRole('spinbutton'), '10')];
                case 11:
                    _c.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(dateIntervalSelector).getByRole('combobox'))];
                case 12:
                    _c.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Days'))];
                case 13:
                    _c.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('user-selector')).getByRole('combobox'))];
                case 14:
                    _c.sent();
                    usersOptions = react_2.screen.getAllByRole('option');
                    expect(usersOptions).toHaveLength(3);
                    expect(usersOptions[0]).toHaveTextContent('alexey.nikonov');
                    expect(usersOptions[1]).toHaveTextContent('fedor.petrov');
                    expect(usersOptions[2]).toHaveTextContent('ivan.ivanov');
                    return [4 /*yield*/, user.click(react_2.screen.getByText('fedor.petrov'))];
                case 15:
                    _c.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Apply'))];
                case 16:
                    _c.sent();
                    newFilters = {
                        activities: [types_1.ActivityTypes.ENTITY_CHANGED],
                        attributes: [
                            {
                                attrType: {
                                    label: 'First Name',
                                    name: 'FirstName',
                                    type: 'String',
                                    uri: 'configuration/entityTypes/HCP/attributes/FirstName'
                                },
                                chipLabel: 'First Name',
                                label: 'First Name',
                                level: 0,
                                value: 'configuration/entityTypes/HCP/attributes/FirstName'
                            }
                        ],
                        dateRange: { period: [10, 'days'], type: mdm_sdk_1.DateRangeTypes.AGO },
                        entityTypes: [
                            {
                                attributes: [
                                    {
                                        label: 'Boolean',
                                        name: 'Boolean',
                                        type: 'Boolean',
                                        uri: 'configuration/entityTypes/HCP/attributes/Boolean'
                                    },
                                    {
                                        label: 'Number',
                                        name: 'Number',
                                        type: 'Number',
                                        uri: 'configuration/entityTypes/HCP/attributes/Number'
                                    },
                                    {
                                        label: 'First Name',
                                        name: 'FirstName',
                                        type: 'String',
                                        uri: 'configuration/entityTypes/HCP/attributes/FirstName'
                                    },
                                    {
                                        label: 'Last Name',
                                        name: 'LastName',
                                        type: 'String',
                                        uri: 'configuration/entityTypes/HCP/attributes/LastName'
                                    }
                                ],
                                label: 'HCP',
                                uri: 'configuration/entityTypes/HCP'
                            }
                        ],
                        sources: [{ abbreviation: 'MUI', icon: 'source/xyz.png', label: 'MUI', uri: 'configuration/sources/MUI' }],
                        users: ['fedor.petrov']
                    };
                    expect(props.onChange).toHaveBeenCalledWith(newFilters);
                    expect(popover).not.toBeInTheDocument();
                    rerender({ value: newFilters });
                    react_2.screen.getByText('Profile updated | HCP | First Name | MUI | More than 10 days ago | fedor.petrov');
                    expect(filterButton).toHaveClass('activeIcon');
                    return [2 /*return*/];
            }
        });
    }); });
    it('should use entity type from entityType prop if it is passed', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, attributesOptions;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp().user;
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Filter'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('activity-selector')).getByRole('combobox'))];
                case 2:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Profile updated'))];
                case 3:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('attribute-selector')).getByRole('combobox'))];
                case 4:
                    _a.sent();
                    attributesOptions = react_2.screen.getAllByRole('option');
                    expect(attributesOptions).toHaveLength(2);
                    expect(attributesOptions[0]).toHaveTextContent('Name');
                    expect(attributesOptions[1]).toHaveTextContent('Status');
                    return [2 /*return*/];
            }
        });
    }); });
    it('should clear filters correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, activitySelector, userSelector;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp().user;
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Filter'))];
                case 1:
                    _a.sent();
                    activitySelector = react_2.screen.getByTestId('activity-selector');
                    userSelector = react_2.screen.getByTestId('user-selector');
                    return [4 /*yield*/, user.click((0, react_2.within)(activitySelector).getByRole('combobox'))];
                case 2:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Profile created'))];
                case 3:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(userSelector).getByRole('combobox'))];
                case 4:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('fedor.petrov'))];
                case 5:
                    _a.sent();
                    (0, react_2.within)(activitySelector).getByText('Profile created');
                    (0, react_2.within)(userSelector).getByText('fedor.petrov');
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Clear all'))];
                case 6:
                    _a.sent();
                    expect((0, react_2.within)(activitySelector).queryByRole('button')).not.toBeInTheDocument();
                    expect((0, react_2.within)(userSelector).queryByRole('button')).not.toBeInTheDocument();
                    expect(defaultProps.onChange).toHaveBeenCalledWith({
                        activities: [],
                        dateRange: { period: [4, 'months'], type: 'within' },
                        users: []
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should apply previous date range value if current value is not valid', 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;
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Filter'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('activity-selector')).getByRole('combobox'))];
                case 2:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Profile created'))];
                case 3:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('More than'))];
                case 4:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Apply'))];
                case 5:
                    _a.sent();
                    expect(defaultProps.onChange).toHaveBeenCalledWith({
                        activities: ['ENTITY_CREATED'],
                        attributes: [],
                        dateRange: { period: [4, 'months'], type: 'within' },
                        entityTypes: [],
                        sources: [],
                        users: []
                    });
                    return [2 /*return*/];
            }
        });
    }); });
    it('should clear attribute filter on change entity type', function () { return __awaiter(void 0, void 0, void 0, function () {
        var props, user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    props = __assign(__assign({}, defaultProps), { entityType: null });
                    user = setUp({ props: props }).user;
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Filter'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('activity-selector')).getByRole('combobox'))];
                case 2:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Profile updated'))];
                case 3:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('entity-types-selector')).getByRole('combobox'))];
                case 4:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('HCP'))];
                case 5:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('attribute-selector')).getByRole('combobox'))];
                case 6:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Boolean'))];
                case 7:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('entity-types-selector')).getByRole('combobox'))];
                case 8:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('HCO'))];
                case 9:
                    _a.sent();
                    expect((0, react_2.within)(react_2.screen.getByTestId('attribute-selector')).queryByRole('button')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should clear entity types, attribute and source filters on change activities', function () { return __awaiter(void 0, void 0, void 0, function () {
        var props, user;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    props = __assign(__assign({}, defaultProps), { entityType: null });
                    user = setUp({ props: props }).user;
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Filter'))];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('activity-selector')).getByRole('combobox'))];
                case 2:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Profile updated'))];
                case 3:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('entity-types-selector')).getByRole('combobox'))];
                case 4:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('HCP'))];
                case 5:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('attribute-selector')).getByRole('combobox'))];
                case 6:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Boolean'))];
                case 7:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('source-selector')).getByRole('combobox'))];
                case 8:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('IMS'))];
                case 9:
                    _a.sent();
                    return [4 /*yield*/, user.click((0, react_2.within)(react_2.screen.getByTestId('activity-selector')).getByRole('combobox'))];
                case 10:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Profile created'))];
                case 11:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Apply'))];
                case 12:
                    _a.sent();
                    expect(props.onChange).toHaveBeenCalledWith({
                        activities: [types_1.ActivityTypes.ENTITY_CHANGED, types_1.ActivityTypes.ENTITY_CREATED],
                        attributes: [],
                        dateRange: { period: [4, 'months'], type: mdm_sdk_1.DateRangeTypes.WITHIN },
                        entityTypes: [],
                        sources: [],
                        users: []
                    });
                    return [2 /*return*/];
            }
        });
    }); });
});
