"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var react_2 = require("@testing-library/react");
var Image_1 = __importDefault(require("./Image"));
var setUp = function (props) {
    if (props === void 0) { props = {}; }
    return (0, react_2.render)(react_1.default.createElement(Image_1.default, __assign({ src: 'path' }, props)));
};
describe('Image tests', function () {
    it('should render main parts', function () {
        setUp();
        expect(react_2.screen.getByRole('img')).toBeInTheDocument();
    });
    it('should render default image', function () {
        setUp({ src: '' });
        expect(react_2.screen.queryByRole('img')).not.toBeInTheDocument();
        expect(react_2.screen.getByTestId('SvgDefaultImage')).toBeInTheDocument();
    });
    it('should reset "default image" state after src prop changing', function () {
        var rerender = setUp({ src: '' }).rerender;
        expect(react_2.screen.queryByRole('img')).not.toBeInTheDocument();
        expect(react_2.screen.getByTestId('SvgDefaultImage')).toBeInTheDocument();
        rerender(react_1.default.createElement(Image_1.default, { src: '123' }));
        var image = react_2.screen.getByRole('img');
        expect(image).toBeInTheDocument();
        expect(image).toHaveClass('hideImage');
        react_2.fireEvent.load(image);
        expect(react_2.screen.queryByTestId('default-container')).not.toBeInTheDocument();
    });
    it('should reset "default image" state when image loading was unsuccessful', function () {
        setUp({ src: '123' });
        var image = react_2.screen.getByRole('img');
        expect(image).toBeInTheDocument();
        expect(image).toHaveClass('hideImage');
        expect(react_2.screen.getByTestId('SvgDefaultImage')).toBeInTheDocument();
        expect(react_2.screen.queryByTestId('not-available-image')).not.toBeInTheDocument();
        react_2.fireEvent.error(image);
        expect(react_2.screen.queryByRole('img')).not.toBeInTheDocument();
        expect(react_2.screen.getByTestId('not-available-image')).toBeInTheDocument();
        expect(react_2.screen.queryByTestId('SvgDefaultImage')).not.toBeInTheDocument();
    });
    it('should render overlay if image is loaded', function () {
        var overlay = react_1.default.createElement("div", { "data-reltio-id": "overlay" });
        setUp({ src: '123', overlay: overlay });
        expect(react_2.screen.queryByTestId('overlay')).not.toBeInTheDocument();
        var image = react_2.screen.getByRole('img');
        react_2.fireEvent.load(image);
        expect(react_2.screen.getByTestId('overlay')).toBeInTheDocument();
    });
});
