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 { DndContext, useDndMonitor, useDroppable } from '@dnd-kit/core';
import { act, render, screen } from '@testing-library/react';
import { DndItemTypes } from '../../types';
import { TableRowWithDnd } from './TableRowWithDnd';
jest.mock('@dnd-kit/core', function () { return (__assign(__assign({}, jest.requireActual('@dnd-kit/core')), { useDndMonitor: jest.fn(), useDroppable: jest.fn().mockReturnValue({ setNodeRef: jest.fn() }) })); });
var defaultColumnsData = [
    { 'attributes.FirstName': 'FirstName1', isDraggable: false, id: 'entities/123' },
    { 'attributes.FirstName': 'FirstName2', isDraggable: true, id: 'entities/234' }
];
var defaultRowData = { id: 'attributes.FirstName', label: 'FirstName' };
var rowName = "".concat(defaultRowData.label, " ").concat(defaultColumnsData[0]['attributes.FirstName'], " ").concat(defaultColumnsData[1]['attributes.FirstName']);
var defaultProps = {
    columnsData: defaultColumnsData,
    rowData: defaultRowData,
    isMoveColumnEnabled: false,
    setHoveredColumn: jest.fn(),
    resetHoveredColumn: jest.fn()
};
var setUp = function (props) {
    if (props === void 0) { props = defaultProps; }
    var Providers = function (_a) {
        var children = _a.children;
        return (React.createElement(DndContext, null,
            React.createElement("table", null,
                React.createElement("tbody", null, children))));
    };
    return render(React.createElement(TableRowWithDnd, __assign({}, props)), { wrapper: Providers });
};
describe('TableRow tests', function () {
    it('should render TableHeadCell correctly', function () {
        setUp();
        expect(screen.getByText('FirstName1')).toBeInTheDocument();
        expect(screen.getByText('FirstName2')).toBeInTheDocument();
    });
    it('should add rowClassName to tr element', function () {
        var rowClassName = 'class1';
        setUp(__assign(__assign({}, defaultProps), { rowData: __assign(__assign({}, defaultRowData), { rowClassName: rowClassName }) }));
        expect(screen.getByRole('row', { name: rowName })).toHaveClass(rowClassName);
    });
    it('should set opacity correctly when dragging was start and dragging was end', function () {
        var onDragStart, onDragEnd;
        useDndMonitor.mockImplementation(function (listeners) {
            onDragStart = listeners.onDragStart;
            onDragEnd = listeners.onDragEnd;
        });
        setUp();
        var row = screen.getByRole('row', { name: rowName });
        expect(row).toHaveStyle({ opacity: 1 });
        act(function () {
            onDragStart({
                active: {
                    id: defaultProps.rowData.id,
                    data: {
                        current: {
                            type: DndItemTypes.Row
                        }
                    }
                }
            });
        });
        expect(row).toHaveStyle({ opacity: 0 });
        act(function () {
            onDragEnd();
        });
        expect(row).toHaveStyle({ opacity: 1 });
    });
    it('should should use TableCellWithDnd if isMoveColumnEnabled is true', function () {
        useDroppable.mockClear();
        setUp(__assign(__assign({}, defaultProps), { isMoveColumnEnabled: true }));
        expect(useDroppable).toHaveBeenCalledWith({ id: defaultColumnsData[0].id });
        expect(useDroppable).toHaveBeenCalledWith({ id: defaultColumnsData[1].id });
    });
});
