"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 react_2 = require("@testing-library/react");
var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
var DataTenantBadge_1 = require("./DataTenantBadge");
var defaultDataTenants = [
    {
        id: 'uitest3',
        name: 'DT_TEST',
        label: 'DT:TEST'
    },
    {
        id: 'hmcyo4cu',
        name: 'withoutPrefix',
        label: 'withoutPrefix'
    },
    {
        id: 'uitest2',
        name: 'DT_TEST'
    }
];
var defaultMdmValues = {
    dataTenantsWithIdBuilder: defaultDataTenants
};
var setUp = function (props, mdmValues) {
    if (mdmValues === void 0) { mdmValues = defaultMdmValues; }
    var Providers = function (_a) {
        var children = _a.children;
        return (react_1.default.createElement(MdmModuleContext_1.MdmModuleProvider, { values: mdmValues }, children));
    };
    return (0, react_2.render)(react_1.default.createElement(DataTenantBadge_1.DataTenantBadge, __assign({}, props)), { wrapper: Providers });
};
describe('DataTenantBadge tests', function () {
    it('should pass className to root element correctly', function () {
        setUp({ dataTenantId: 'uitest3', className: 'dataTenantBadge' });
        expect(react_2.screen.getByLabelText('DT:TEST')).toHaveClass('dataTenantBadge');
    });
    it('should render correct label if dataTenantId exists in dataTenants', function () {
        setUp({ dataTenantId: 'uitest3' });
        react_2.screen.getByText('DT:T');
    });
    it('should render correct label if dataTenants is not exists', function () {
        var mdmValues = { dataTenantsWithIdBuilder: [] };
        setUp({ dataTenantId: 'uitest3' }, mdmValues);
        react_2.screen.getByText('DT:');
    });
    it('should render correct label if dataTenantId does not exist in dataTenants', function () {
        setUp({ dataTenantId: 'notExistedTenantId' });
        react_2.screen.getByText('DT:');
    });
    it('should render correct label if data tenant name does not start with "DT:"', function () {
        setUp({ dataTenantId: 'hmcyo4cu' });
        react_2.screen.getByText('DT:W');
    });
    it('should render correct tooltip if dataTenantId has a label', function () {
        setUp({ dataTenantId: 'uitest3' });
        react_2.screen.getByLabelText('DT:TEST');
    });
    it('should not render tooltip if dataTenant does not have a label property', function () {
        setUp({ dataTenantId: 'uitest2' });
        expect(react_2.screen.queryByTestId('reltio-data-tenant-bage-tooltip')).not.toBeInTheDocument();
    });
    it('should not render tooltip if dataTenantId does not exist in dataTenants', function () {
        setUp({ dataTenantId: 'notExistedTenantId' });
        expect(react_2.screen.queryByTestId('reltio-data-tenant-bage-tooltip')).not.toBeInTheDocument();
    });
});
