"use strict";
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 Highlighter_1 = require("./Highlighter");
describe('Highlighter tests', function () {
    it('should render text', function () {
        var text = 'Text to highlight';
        (0, react_2.render)(react_1.default.createElement(Highlighter_1.Highlighter, { text: text }));
        expect(react_2.screen.getByText(text)).toBeInTheDocument();
    });
    it('should not fail when text is undefined', function () {
        var container = (0, react_2.render)(react_1.default.createElement(Highlighter_1.Highlighter, null)).container;
        expect(container).toHaveTextContent('');
    });
    it('should render text with highlighted parts', function () {
        var text = 'Text to highlight';
        var highlight = 'i';
        var container = (0, react_2.render)(react_1.default.createElement(Highlighter_1.Highlighter, { text: text, highlight: highlight })).container;
        expect(container).toHaveTextContent(text);
        var highlightedParts = container.querySelectorAll('.highlight');
        expect(highlightedParts).toHaveLength(2);
        highlightedParts.forEach(function (highlightedPart) { return expect(highlightedPart.textContent).toBe(highlight); });
    });
    it('should render text with highlighted part when search value contains several ones and multiTerm off', function () {
        var text = 'o m ld Oo mo';
        var highlight = 'o M';
        var container = (0, react_2.render)(react_1.default.createElement(Highlighter_1.Highlighter, { text: text, highlight: highlight })).container;
        expect(container).toHaveTextContent(text);
        var highlightedParts = container.querySelectorAll('.highlight');
        expect(highlightedParts).toHaveLength(2);
        highlightedParts.forEach(function (highlightedPart) { var _a; return expect((_a = highlightedPart.textContent) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()).toBe(highlight.toLocaleLowerCase()); });
    });
    it('should highlight parts as a string not as a regExpression', function () {
        var text = '1.1 101';
        var highlight = '1.1';
        var container = (0, react_2.render)(react_1.default.createElement(Highlighter_1.Highlighter, { text: text, highlight: highlight })).container;
        expect(container).toHaveTextContent(text);
        var highlightedParts = container.querySelectorAll('.highlight');
        expect(highlightedParts).toHaveLength(1);
        expect(highlightedParts[0]).toHaveTextContent(highlight);
    });
    it('should highlight parts as a string not as a regExpression -', function () {
        var text = '[1[$2]?1-(*)[1-10|a]{a}+.(^3)#]';
        var highlight = '[1[$2]?1-(*)[1-10|a]{a}+.(^3)#]'; //[-[\]{}()*+?.,\\^$|#\s]
        var container = (0, react_2.render)(react_1.default.createElement(Highlighter_1.Highlighter, { text: text, highlight: highlight })).container;
        expect(container).toHaveTextContent(text);
        var highlightedParts = container.querySelectorAll('.highlight');
        expect(highlightedParts).toHaveLength(1);
        expect(highlightedParts[0]).toHaveTextContent(text);
    });
    it('should render text with highlighted parts with custom className', function () {
        var text = 'Text to highlight';
        var highlight = 'i';
        var container = (0, react_2.render)(react_1.default.createElement(Highlighter_1.Highlighter, { text: text, highlight: highlight, className: "customStyleToSelect" })).container;
        expect(container).toHaveTextContent(text);
        var highlightedParts = container.querySelectorAll('.highlight');
        expect(highlightedParts).toHaveLength(0);
        var customHighlightedParts = container.querySelectorAll('.customStyleToSelect');
        expect(customHighlightedParts).toHaveLength(2);
        customHighlightedParts.forEach(function (highlightedPart) { return expect(highlightedPart).toHaveTextContent(highlight); });
    });
    describe('provided with multiTerm property', function () {
        it('should render text with highlighted parts when search value contains several ones and multiTerm on', function () {
            var text = 'o m ld Oo mo';
            var highlight = 'o M';
            var container = (0, react_2.render)(react_1.default.createElement(Highlighter_1.Highlighter, { text: text, highlight: highlight, multiTerm: true })).container;
            expect(container).toHaveTextContent(text);
            var highlightedParts = container.querySelectorAll('.highlight');
            expect(highlightedParts).toHaveLength(6);
            highlightedParts.forEach(function (highlightedPart) { var _a; return expect(['o', 'm'].includes((_a = highlightedPart.textContent) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase())).toBeTruthy(); });
        });
        it('should highlight larger part first when search value contains several ones', function () {
            var text = '1014 104';
            var highlight = '1 14';
            var container = (0, react_2.render)(react_1.default.createElement(Highlighter_1.Highlighter, { text: text, highlight: highlight, multiTerm: true })).container;
            expect(container).toHaveTextContent(text);
            var highlightedParts = container.querySelectorAll('.highlight');
            expect(highlightedParts).toHaveLength(3);
            expect(highlightedParts[0]).toHaveTextContent('1');
            expect(highlightedParts[1]).toHaveTextContent('14');
            expect(highlightedParts[2]).toHaveTextContent('1');
        });
        it('should exclude spaces from searching value, uses only valuable strings', function () {
            var container = (0, react_2.render)(react_1.default.createElement(Highlighter_1.Highlighter, { text: '1   1', highlight: '0   2 1 ', multiTerm: true })).container;
            expect(container).toHaveTextContent('1 1');
            var highlightedParts = container.querySelectorAll('.highlight');
            expect(highlightedParts).toHaveLength(2);
            expect(highlightedParts[0]).toHaveTextContent('1');
            expect(highlightedParts[1]).toHaveTextContent('1');
        });
    });
});
