"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 sanitize_html_1 = __importDefault(require("sanitize-html"));
var react_1 = require("@testing-library/react");
var helpers_1 = require("./helpers");
var useHtmlSanitizer_1 = require("./useHtmlSanitizer");
var getHookResult = function () {
    var result = (0, react_1.renderHook)(useHtmlSanitizer_1.useHtmlSanitizer).result;
    return result.current;
};
jest.mock('sanitize-html', function () {
    var sanitizeMock = jest.fn().mockImplementation(jest.requireActual('sanitize-html'));
    sanitizeMock.defaults =
        jest.requireActual('sanitize-html').defaults;
    return sanitizeMock;
});
describe('useHtmlSanitizer behavior', function () {
    var _a = sanitize_html_1.default.defaults, allowedAttributes = _a.allowedAttributes, allowedTags = _a.allowedTags;
    var attributes = helpers_1.sanitizerOptions.attributes, tags = helpers_1.sanitizerOptions.tags;
    it('should call sanitizeHtml with correct args', function () {
        var htmlSanitizer = getHookResult();
        htmlSanitizer('html');
        expect(sanitize_html_1.default).toHaveBeenCalledWith('html', {
            allowedTags: allowedTags.concat(tags),
            allowedAttributes: __assign(__assign({}, allowedAttributes), attributes),
            allowVulnerableTags: true
        });
    });
    it('should clear unsupported attributes', function () {
        var htmlSanitizer = getHookResult();
        var sanitizedHtml = htmlSanitizer('<div onmouseover=alert("XSS testing!") a="1" b="2">html</div>');
        expect(sanitizedHtml).toBe('<div>html</div>');
    });
    it('should clear unsupported tags', function () {
        var htmlSanitizer = getHookResult();
        var sanitizedHtml = htmlSanitizer('<form></form>');
        expect(sanitizedHtml).toBe('');
    });
    it('should clear src attribute for script tag', function () {
        var htmlSanitizer = getHookResult();
        var sanitizedHtml = htmlSanitizer('<script src="https://www.safe.authorized.com/lib.js"></script>');
        expect(sanitizedHtml).toBe('<script></script>');
    });
    it('should allow to use reltio attributes for every tag', function () {
        var htmlSanitizer = getHookResult();
        expect(htmlSanitizer('<button ui-actions="click" ui-tooltip="tooltip"></button>')).toBe('<button ui-actions="click" ui-tooltip="tooltip"></button>');
        expect(htmlSanitizer('<link ui-actions="click" ui-tooltip="tooltip"></link>')).toBe('<link ui-actions="click" ui-tooltip="tooltip" />');
        expect(htmlSanitizer('<a ui-actions="click" ui-tooltip="tooltip"></a>')).toBe('<a ui-actions="click" ui-tooltip="tooltip"></a>');
        expect(htmlSanitizer('<img ui-actions="click" ui-tooltip="tooltip"></img>')).toBe('<img ui-actions="click" ui-tooltip="tooltip" />');
        expect(htmlSanitizer('<div ui-actions="click" ui-tooltip="tooltip"></div>')).toBe('<div ui-actions="click" ui-tooltip="tooltip"></div>');
    });
    it('should allow to use special attributes for some tags', function () {
        var htmlSanitizer = getHookResult();
        expect(htmlSanitizer('<iframe src="https://test.com"/>')).toBe('<iframe src="https://test.com"></iframe>');
        expect(htmlSanitizer('<a href="https://test.com"/>')).toBe('<a href="https://test.com"></a>');
        expect(htmlSanitizer('<link href="https://test.com" rel="stylesheet"/>')).toBe('<link href="https://test.com" rel="stylesheet" />');
        expect(htmlSanitizer('<img src="https://test.com" srcset="https://test.com" alt="alt" title="title" loading="lazy"/>')).toBe('<img src="https://test.com" srcset="https://test.com" alt="alt" title="title" loading="lazy" />');
    });
});
