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);
};
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import Image from './Image';
var setUp = function (props) {
    if (props === void 0) { props = {}; }
    return render(React.createElement(Image, __assign({ src: 'path' }, props)));
};
describe('Image tests', function () {
    it('should render main parts', function () {
        setUp();
        expect(screen.getByRole('img')).toBeInTheDocument();
    });
    it('should render default image', function () {
        setUp({ src: '' });
        expect(screen.queryByRole('img')).not.toBeInTheDocument();
        expect(screen.getByTestId('SvgDefaultImage')).toBeInTheDocument();
    });
    it('should reset "default image" state after src prop changing', function () {
        var rerender = setUp({ src: '' }).rerender;
        expect(screen.queryByRole('img')).not.toBeInTheDocument();
        expect(screen.getByTestId('SvgDefaultImage')).toBeInTheDocument();
        rerender(React.createElement(Image, { src: '123' }));
        var image = screen.getByRole('img');
        expect(image).toBeInTheDocument();
        expect(image).toHaveClass('hideImage');
        fireEvent.load(image);
        expect(screen.queryByTestId('default-container')).not.toBeInTheDocument();
    });
    it('should reset "default image" state when image loading was unsuccessful', function () {
        setUp({ src: '123' });
        var image = screen.getByRole('img');
        expect(image).toBeInTheDocument();
        expect(image).toHaveClass('hideImage');
        expect(screen.getByTestId('SvgDefaultImage')).toBeInTheDocument();
        expect(screen.queryByTestId('not-available-image')).not.toBeInTheDocument();
        fireEvent.error(image);
        expect(screen.queryByRole('img')).not.toBeInTheDocument();
        expect(screen.getByTestId('not-available-image')).toBeInTheDocument();
        expect(screen.queryByTestId('SvgDefaultImage')).not.toBeInTheDocument();
    });
    it('should render overlay if image is loaded', function () {
        var overlay = React.createElement("div", { "data-reltio-id": "overlay" });
        setUp({ src: '123', overlay: overlay });
        expect(screen.queryByTestId('overlay')).not.toBeInTheDocument();
        var image = screen.getByRole('img');
        fireEvent.load(image);
        expect(screen.getByTestId('overlay')).toBeInTheDocument();
    });
});
