"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 core_1 = require("@dnd-kit/core");
var react_2 = require("@testing-library/react");
var types_1 = require("../../types");
var TableRowWithDnd_1 = require("./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_1.default.createElement(core_1.DndContext, null,
            react_1.default.createElement("table", null,
                react_1.default.createElement("tbody", null, children))));
    };
    return (0, react_2.render)(react_1.default.createElement(TableRowWithDnd_1.TableRowWithDnd, __assign({}, props)), { wrapper: Providers });
};
describe('TableRow tests', function () {
    it('should render TableHeadCell correctly', function () {
        setUp();
        expect(react_2.screen.getByText('FirstName1')).toBeInTheDocument();
        expect(react_2.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(react_2.screen.getByRole('row', { name: rowName })).toHaveClass(rowClassName);
    });
    it('should set opacity correctly when dragging was start and dragging was end', function () {
        var onDragStart, onDragEnd;
        core_1.useDndMonitor.mockImplementation(function (listeners) {
            onDragStart = listeners.onDragStart;
            onDragEnd = listeners.onDragEnd;
        });
        setUp();
        var row = react_2.screen.getByRole('row', { name: rowName });
        expect(row).toHaveStyle({ opacity: 1 });
        (0, react_2.act)(function () {
            onDragStart({
                active: {
                    id: defaultProps.rowData.id,
                    data: {
                        current: {
                            type: types_1.DndItemTypes.Row
                        }
                    }
                }
            });
        });
        expect(row).toHaveStyle({ opacity: 0 });
        (0, react_2.act)(function () {
            onDragEnd();
        });
        expect(row).toHaveStyle({ opacity: 1 });
    });
    it('should should use TableCellWithDnd if isMoveColumnEnabled is true', function () {
        core_1.useDroppable.mockClear();
        setUp(__assign(__assign({}, defaultProps), { isMoveColumnEnabled: true }));
        expect(core_1.useDroppable).toHaveBeenCalledWith({ id: defaultColumnsData[0].id });
        expect(core_1.useDroppable).toHaveBeenCalledWith({ id: defaultColumnsData[1].id });
    });
});
