"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 ramda_1 = require("ramda");
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 MdmModuleContext_1 = require("../contexts/MdmModuleContext");
var ImageAttributesGallery_1 = require("./ImageAttributesGallery");
var generateAttributeValues = function (count) {
    return (0, ramda_1.range)(0, count).map(function (i) { return ({
        label: 'image/jpeg',
        value: {
            UrlThumbnail: [
                {
                    type: 'configuration/entityTypes/Series/attributes/ImageGallery/attributes/UrlThumbnail',
                    ov: true,
                    value: "./image".concat(i, "Thumbnail.jpg"),
                    uri: "entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ".concat(i, "/UrlThumbnail/39V5GWWM").concat(i)
                }
            ],
            Url: [
                {
                    type: 'configuration/entityTypes/Series/attributes/ImageGallery/attributes/Url',
                    ov: true,
                    value: "./image".concat(i, ".jpg"),
                    uri: "entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ".concat(i, "/Url/39V5GWWM").concat(i)
                }
            ]
        },
        ov: true,
        uri: "entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ".concat(i)
    }); });
};
var defaultMdmValues = {
    mode: mdm_sdk_1.Mode.Viewing,
    entity: {},
    modifiedEntities: {},
    imageAttributesFieldsOrder: {}
};
var defaultProps = {
    attributeValues: generateAttributeValues(3),
    open: true,
    onClose: jest.fn(),
    setCurrentAttributeValueUri: jest.fn(),
    attributeType: {
        attributes: [],
        name: 'ImageGallery',
        type: 'Image',
        uri: 'configuration/entityTypes/Employee/attributes/ImageGallery'
    },
    onUpload: jest.fn(),
    onDownload: jest.fn(),
    onShareLink: jest.fn(),
    onSetAsDefault: jest.fn(),
    onDeleteAttribute: jest.fn()
};
var setUp = function (_a) {
    var _b = _a === void 0 ? {} : _a, _c = _b.props, props = _c === void 0 ? {} : _c, _d = _b.mdmValues, mdmValues = _d === void 0 ? defaultMdmValues : _d;
    var user = user_event_1.default.setup({ skipHover: true });
    var Providers = function (_a) {
        var children = _a.children;
        return (react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues }, children));
    };
    return __assign({ user: user }, (0, react_2.render)(react_1.default.createElement(ImageAttributesGallery_1.ImageAttributesGallery, __assign({}, defaultProps, props)), { wrapper: Providers }));
};
describe('ImageAttributesGallery tests', function () {
    afterEach(function () {
        jest.clearAllMocks();
    });
    it('should render main parts', function () {
        setUp();
        var images = react_2.screen.getAllByRole('img');
        expect(images).toHaveLength(3);
        expect(react_2.screen.getByLabelText('Close')).toBeInTheDocument();
        expect(react_2.screen.getByTestId('reltio-search-mode-gallery')).toHaveClass('current');
        expect(react_2.screen.getByTestId('reltio-search-mode-details')).not.toHaveClass('current');
    });
    it('should select and deselect items', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, images, checkButton, checkedButtons;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp().user;
                    images = react_2.screen.getAllByRole('img');
                    images.forEach(function (image) {
                        react_2.fireEvent.load(image);
                    });
                    expect(react_2.screen.queryByTestId('checked-button')).not.toBeInTheDocument();
                    return [4 /*yield*/, user.hover(react_2.screen.getAllByTestId('image-actions-overlay')[0])];
                case 1:
                    _a.sent();
                    checkButton = react_2.screen.getByTestId('checked-button');
                    expect(checkButton).toHaveAttribute('data-testid', 'RadioButtonUncheckedIcon');
                    expect(react_2.screen.queryByText('Deselect')).not.toBeInTheDocument();
                    expect(react_2.screen.queryByText('Select all images')).not.toBeInTheDocument();
                    expect(react_2.screen.queryByLabelText('Download selected items')).not.toBeInTheDocument();
                    return [4 /*yield*/, user.click(checkButton)];
                case 2:
                    _a.sent();
                    expect(react_2.screen.getByText('Deselect')).toBeInTheDocument();
                    expect(react_2.screen.getByText('Select all images')).toBeInTheDocument();
                    expect(react_2.screen.getByLabelText('Download selected items')).toBeInTheDocument();
                    checkedButtons = react_2.screen.getAllByTestId('checked-button');
                    expect(checkedButtons).toHaveLength(3);
                    expect(checkedButtons[0]).toHaveAttribute('data-testid', 'CheckCircleIcon');
                    expect(checkedButtons[1]).toHaveAttribute('data-testid', 'RadioButtonUncheckedIcon');
                    expect(checkedButtons[2]).toHaveAttribute('data-testid', 'RadioButtonUncheckedIcon');
                    return [4 /*yield*/, user.click(checkedButtons[1])];
                case 3:
                    _a.sent();
                    expect(react_2.screen.getAllByText('Deselect')).toHaveLength(2);
                    expect(react_2.screen.getAllByTestId('checked-button')[1]).toHaveAttribute('data-testid', 'CheckCircleIcon');
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Download selected items'))];
                case 4:
                    _a.sent();
                    expect(defaultProps.onDownload).toHaveBeenCalledWith(['./image0.jpg', './image1.jpg']);
                    return [4 /*yield*/, user.click(react_2.screen.getAllByText('Deselect')[0])];
                case 5:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getAllByTestId('checked-button')[1])];
                case 6:
                    _a.sent();
                    expect(react_2.screen.queryByText('Deselect')).not.toBeInTheDocument();
                    expect(react_2.screen.queryByText('Select all images')).not.toBeInTheDocument();
                    expect(react_2.screen.queryByLabelText('Download selected items')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should select all and deselect all items', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, images, checkedButtons;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp().user;
                    images = react_2.screen.getAllByRole('img');
                    images.forEach(function (image) {
                        react_2.fireEvent.load(image);
                    });
                    expect(react_2.screen.queryByTestId('checked-button')).not.toBeInTheDocument();
                    return [4 /*yield*/, user.hover(react_2.screen.getAllByTestId('image-actions-overlay')[0])];
                case 1:
                    _a.sent();
                    expect(react_2.screen.queryByText('Deselect')).not.toBeInTheDocument();
                    expect(react_2.screen.queryByText('Select all images')).not.toBeInTheDocument();
                    expect(react_2.screen.queryByLabelText('Download selected items')).not.toBeInTheDocument();
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('checked-button'))];
                case 2:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Select all images'))];
                case 3:
                    _a.sent();
                    expect(react_2.screen.getAllByText('Deselect')).toHaveLength(3);
                    checkedButtons = react_2.screen.getAllByTestId('checked-button');
                    expect(checkedButtons).toHaveLength(3);
                    expect(checkedButtons[0]).toHaveAttribute('data-testid', 'CheckCircleIcon');
                    expect(checkedButtons[1]).toHaveAttribute('data-testid', 'CheckCircleIcon');
                    expect(checkedButtons[2]).toHaveAttribute('data-testid', 'CheckCircleIcon');
                    return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Download selected items'))];
                case 4:
                    _a.sent();
                    expect(defaultProps.onDownload).toHaveBeenCalledWith(['./image0.jpg', './image1.jpg', './image2.jpg']);
                    return [4 /*yield*/, user.click(react_2.screen.getByText('Clear selection'))];
                case 5:
                    _a.sent();
                    expect(react_2.screen.queryByText('Deselect')).not.toBeInTheDocument();
                    expect(react_2.screen.queryByText('Select all images')).not.toBeInTheDocument();
                    expect(react_2.screen.queryByLabelText('Download selected items')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should close gallery', 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('Close'))];
                case 1:
                    _a.sent();
                    expect(defaultProps.onClose).toHaveBeenCalled();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should not provide onDelete if viewing mode', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, images;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp({ mdmValues: __assign(__assign({}, defaultMdmValues), { mode: mdm_sdk_1.Mode.Viewing }) }).user;
                    images = react_2.screen.getAllByRole('img');
                    react_2.fireEvent.load(images[0]);
                    return [4 /*yield*/, user.hover(react_2.screen.getAllByTestId('image-actions-overlay')[0])];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('image-overlay-actions'))];
                case 2:
                    _a.sent();
                    expect(react_2.screen.queryByText('Delete')).not.toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('should provide onDelete if editing mode', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, images;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp({ mdmValues: __assign(__assign({}, defaultMdmValues), { mode: mdm_sdk_1.Mode.Editing }) }).user;
                    images = react_2.screen.getAllByRole('img');
                    react_2.fireEvent.load(images[0]);
                    return [4 /*yield*/, user.hover(react_2.screen.getAllByTestId('image-actions-overlay')[0])];
                case 1:
                    _a.sent();
                    return [4 /*yield*/, user.click(react_2.screen.getByTestId('image-overlay-actions'))];
                case 2:
                    _a.sent();
                    expect(react_2.screen.queryByText('Delete')).toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    it('handleClickByImage', function () { return __awaiter(void 0, void 0, void 0, function () {
        var user, images;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    user = setUp().user;
                    images = react_2.screen.getAllByRole('img');
                    images.forEach(function (image) {
                        react_2.fireEvent.load(image);
                    });
                    expect(react_2.screen.getByTestId('reltio-search-mode-gallery')).toHaveClass('current');
                    expect(react_2.screen.getByTestId('reltio-search-mode-details')).not.toHaveClass('current');
                    return [4 /*yield*/, user.click(images[0])];
                case 1:
                    _a.sent();
                    expect(react_2.screen.getByTestId('reltio-search-mode-gallery')).not.toHaveClass('current');
                    expect(react_2.screen.getByTestId('reltio-search-mode-details')).toHaveClass('current');
                    expect(defaultProps.setCurrentAttributeValueUri).toHaveBeenCalledWith('entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0');
                    expect(react_2.screen.getByText('Meta info')).toBeInTheDocument();
                    return [2 /*return*/];
            }
        });
    }); });
    describe('share link', function () {
        it('action for GalleryView', function () { return __awaiter(void 0, void 0, void 0, function () {
            var user, images;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        user = setUp().user;
                        images = react_2.screen.getAllByRole('img');
                        images.forEach(function (image) {
                            react_2.fireEvent.load(image);
                        });
                        return [4 /*yield*/, user.hover(react_2.screen.getAllByTestId('image-actions-overlay')[0])];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('image-overlay-actions'))];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByText('Share link'))];
                    case 3:
                        _a.sent();
                        expect(defaultProps.onShareLink).toHaveBeenCalledWith('./image0.jpg');
                        return [2 /*return*/];
                }
            });
        }); });
        it('action for HeaderRight', function () { return __awaiter(void 0, void 0, void 0, function () {
            var user, images;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        user = setUp({
                            props: { currentAttributeValueUri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0' }
                        }).user;
                        images = react_2.screen.getAllByRole('img');
                        images.forEach(function (image) {
                            react_2.fireEvent.load(image);
                        });
                        return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Copy link'))];
                    case 1:
                        _a.sent();
                        expect(defaultProps.onShareLink).toHaveBeenCalledWith('./image0.jpg');
                        return [2 /*return*/];
                }
            });
        }); });
    });
    describe('set as default', function () {
        var result = {
            label: 'image/jpeg',
            ov: true,
            uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0',
            value: {
                Url: [
                    {
                        ov: true,
                        type: 'configuration/entityTypes/Series/attributes/ImageGallery/attributes/Url',
                        uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0/Url/39V5GWWM0',
                        value: './image0.jpg'
                    }
                ],
                UrlThumbnail: [
                    {
                        ov: true,
                        type: 'configuration/entityTypes/Series/attributes/ImageGallery/attributes/UrlThumbnail',
                        uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0/UrlThumbnail/39V5GWWM0',
                        value: './image0Thumbnail.jpg'
                    }
                ]
            }
        };
        it('should be called from GalleryView', function () { return __awaiter(void 0, void 0, void 0, function () {
            var user, images;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        user = setUp().user;
                        images = react_2.screen.getAllByRole('img');
                        images.forEach(function (image) {
                            react_2.fireEvent.load(image);
                        });
                        return [4 /*yield*/, user.hover(react_2.screen.getAllByTestId('image-actions-overlay')[0])];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('image-overlay-actions'))];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByText('Set as default'))];
                    case 3:
                        _a.sent();
                        expect(defaultProps.onSetAsDefault).toHaveBeenCalledWith(result);
                        return [2 /*return*/];
                }
            });
        }); });
        it('should be called from ImageDetailsView', function () { return __awaiter(void 0, void 0, void 0, function () {
            var user, images;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        user = setUp({
                            props: { currentAttributeValueUri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0' }
                        }).user;
                        images = react_2.screen.getAllByRole('img');
                        images.forEach(function (image) {
                            react_2.fireEvent.load(image);
                        });
                        return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Set as default'))];
                    case 1:
                        _a.sent();
                        expect(defaultProps.onSetAsDefault).toHaveBeenCalledWith(result);
                        return [2 /*return*/];
                }
            });
        }); });
    });
    describe('download images', function () {
        it('should call download prop for selected images', function () { return __awaiter(void 0, void 0, void 0, function () {
            var user, images;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        user = setUp().user;
                        images = react_2.screen.getAllByRole('img');
                        images.forEach(function (image) {
                            react_2.fireEvent.load(image);
                        });
                        return [4 /*yield*/, user.hover(react_2.screen.getAllByTestId('image-actions-overlay')[0])];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('checked-button'))];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getAllByTestId('checked-button')[1])];
                    case 3:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Download selected items'))];
                    case 4:
                        _a.sent();
                        expect(defaultProps.onDownload).toHaveBeenCalledWith(['./image0.jpg', './image1.jpg']);
                        return [2 /*return*/];
                }
            });
        }); });
        it('should call download prop for opened image in details mode', function () { return __awaiter(void 0, void 0, void 0, function () {
            var user, images;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        user = setUp({
                            props: { currentAttributeValueUri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0' }
                        }).user;
                        images = react_2.screen.getAllByRole('img');
                        images.forEach(function (image) {
                            react_2.fireEvent.load(image);
                        });
                        return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Download selected items'))];
                    case 1:
                        _a.sent();
                        expect(defaultProps.onDownload).toHaveBeenCalledWith(['./image0.jpg']);
                        return [2 /*return*/];
                }
            });
        }); });
    });
    describe('deleting images', function () {
        it('should delete image in details mode', function () { return __awaiter(void 0, void 0, void 0, function () {
            var user, images;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        user = setUp({
                            props: { currentAttributeValueUri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0' },
                            mdmValues: __assign(__assign({}, defaultMdmValues), { mode: mdm_sdk_1.Mode.Editing })
                        }).user;
                        images = react_2.screen.getAllByRole('img');
                        images.forEach(function (image) {
                            react_2.fireEvent.load(image);
                        });
                        return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Delete selected items'))];
                    case 1:
                        _a.sent();
                        expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
                            uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0',
                            attributeType: defaultProps.attributeType
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it('should delete image in gallery mode', function () { return __awaiter(void 0, void 0, void 0, function () {
            var user, images;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        user = setUp({ mdmValues: __assign(__assign({}, defaultMdmValues), { mode: mdm_sdk_1.Mode.Editing }) }).user;
                        images = react_2.screen.getAllByRole('img');
                        images.forEach(function (image) {
                            react_2.fireEvent.load(image);
                        });
                        return [4 /*yield*/, user.hover(react_2.screen.getAllByTestId('image-actions-overlay')[0])];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('image-overlay-actions'))];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByText('Delete'))];
                    case 3:
                        _a.sent();
                        expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
                            uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0',
                            attributeType: defaultProps.attributeType
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it('should delete image in gallery mode by clicking onDelete at GalleryView', function () { return __awaiter(void 0, void 0, void 0, function () {
            var user, images;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        user = setUp({ mdmValues: __assign(__assign({}, defaultMdmValues), { mode: mdm_sdk_1.Mode.Editing }) }).user;
                        images = react_2.screen.getAllByRole('img');
                        images.forEach(function (image) {
                            react_2.fireEvent.load(image);
                        });
                        return [4 /*yield*/, user.hover(react_2.screen.getAllByTestId('image-actions-overlay')[0])];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('checked-button'))];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Delete selected items'))];
                    case 3:
                        _a.sent();
                        expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
                            uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0',
                            attributeType: defaultProps.attributeType
                        });
                        return [2 /*return*/];
                }
            });
        }); });
        it('should delete few images in gallery mode', function () { return __awaiter(void 0, void 0, void 0, function () {
            var user, images;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        user = setUp({ mdmValues: __assign(__assign({}, defaultMdmValues), { mode: mdm_sdk_1.Mode.Editing }) }).user;
                        images = react_2.screen.getAllByRole('img');
                        images.forEach(function (image) {
                            react_2.fireEvent.load(image);
                        });
                        return [4 /*yield*/, user.hover(react_2.screen.getAllByTestId('image-actions-overlay')[0])];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('checked-button'))];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByText('Select all images'))];
                    case 3:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByLabelText('Delete selected items'))];
                    case 4:
                        _a.sent();
                        expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
                            uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ0',
                            attributeType: defaultProps.attributeType
                        });
                        expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
                            uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ1',
                            attributeType: defaultProps.attributeType
                        });
                        expect(defaultProps.onDeleteAttribute).toHaveBeenCalledWith({
                            uri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ2',
                            attributeType: defaultProps.attributeType
                        });
                        return [2 /*return*/];
                }
            });
        }); });
    });
    describe('HeaderRight rendering cases', function () {
        it('should show delete, download, copy link, upload buttons in details view', function () { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                setUp({
                    mdmValues: { mode: mdm_sdk_1.Mode.Editing },
                    props: {
                        currentAttributeValueUri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ1'
                    }
                });
                expect(react_2.screen.getByLabelText('Delete selected items')).toBeInTheDocument();
                expect(react_2.screen.getByLabelText('Download selected items')).toBeInTheDocument();
                expect(react_2.screen.getByLabelText('Copy link')).toBeInTheDocument();
                expect(react_2.screen.getByText('Upload')).toBeInTheDocument();
                return [2 /*return*/];
            });
        }); });
        it('should not show upload button in details view it onUpload is not defined', function () { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                setUp({
                    mdmValues: { mode: mdm_sdk_1.Mode.Editing },
                    props: {
                        currentAttributeValueUri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ1',
                        onUpload: undefined
                    }
                });
                expect(react_2.screen.getByLabelText('Delete selected items')).toBeInTheDocument();
                expect(react_2.screen.getByLabelText('Download selected items')).toBeInTheDocument();
                expect(react_2.screen.getByLabelText('Copy link')).toBeInTheDocument();
                expect(react_2.screen.queryByText('Upload')).not.toBeInTheDocument();
                return [2 /*return*/];
            });
        }); });
        it('should show only download and delete button in Gallery mode with selected items and in edit mode', function () { return __awaiter(void 0, void 0, void 0, function () {
            var user, images;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        user = setUp({ mdmValues: { mode: mdm_sdk_1.Mode.Editing } }).user;
                        images = react_2.screen.getAllByRole('img');
                        images.forEach(function (image) {
                            react_2.fireEvent.load(image);
                        });
                        return [4 /*yield*/, user.hover(react_2.screen.getAllByTestId('image-actions-overlay')[0])];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, user.click(react_2.screen.getByTestId('checked-button'))];
                    case 2:
                        _a.sent();
                        expect(react_2.screen.getByLabelText('Download selected items')).toBeInTheDocument();
                        expect(react_2.screen.getByLabelText('Delete selected items')).toBeInTheDocument();
                        expect(react_2.screen.queryByLabelText('Copy link')).not.toBeInTheDocument();
                        expect(react_2.screen.queryByText('Upload')).not.toBeInTheDocument();
                        return [2 /*return*/];
                }
            });
        }); });
        it('should show only upload button in gallery edit mode without selected items', function () {
            setUp({ mdmValues: { mode: mdm_sdk_1.Mode.Editing } });
            expect(react_2.screen.queryByLabelText('Delete selected items')).not.toBeInTheDocument();
            expect(react_2.screen.queryByLabelText('Download selected items')).not.toBeInTheDocument();
            expect(react_2.screen.queryByLabelText('Copy link')).not.toBeInTheDocument();
            expect(react_2.screen.getByText('Upload')).toBeInTheDocument();
        });
        it('should not show buttons in viewing mode with non selected items', function () {
            setUp({ mdmValues: { mode: mdm_sdk_1.Mode.Viewing } });
            expect(react_2.screen.queryByLabelText('Delete selected items')).not.toBeInTheDocument();
            expect(react_2.screen.queryByLabelText('Download selected items')).not.toBeInTheDocument();
            expect(react_2.screen.queryByLabelText('Copy link')).not.toBeInTheDocument();
            expect(react_2.screen.queryByText('Upload')).not.toBeInTheDocument();
        });
        it('should show only copy link and download in details view for viewing mode', function () {
            setUp({
                mdmValues: { mode: mdm_sdk_1.Mode.Viewing },
                props: {
                    currentAttributeValueUri: 'entities/1Rd2I9Mt/attributes/ImageGallery/39V5GWJZ1'
                }
            });
            expect(react_2.screen.getByLabelText('Download selected items')).toBeInTheDocument();
            expect(react_2.screen.getByLabelText('Copy link')).toBeInTheDocument();
            expect(react_2.screen.queryByLabelText('Delete selected items')).not.toBeInTheDocument();
            expect(react_2.screen.queryByText('Upload')).not.toBeInTheDocument();
        });
    });
});
