"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("@testing-library/react");
var PerspectivesSettingsContext = __importStar(require("../../../contexts/PerspectivesSettingsContext"));
var useHistoryEnabled_1 = require("./useHistoryEnabled");
describe('useHistoryEnabled behaviour', function () {
    var profileEntity = {
        uri: 'entities/1',
        type: 'configuration/entityTypes/HCP'
    };
    var nextProfileEntity = {
        uri: 'entities/2',
        type: 'configuration/entityTypes/HCP'
    };
    var tempProfileEntity = {
        uri: 'entities/uri$$tempentities',
        type: 'configuration/entityTypes/HCP'
    };
    var dataTenantProfileEntity = {
        uri: 'entity/2',
        dataTenant: 'data'
    };
    beforeAll(function () {
        var perspectiveSettings = {
            perspectiveSettings: {
                active: 1
            },
            updatePerspectiveSettings: function () { return null; }
        };
        jest.spyOn(PerspectivesSettingsContext, 'usePerspectivesSettings').mockReturnValue(perspectiveSettings);
    });
    var getHistoryEnabled = function (initialProps) {
        var _a = (0, react_1.renderHook)(function (props) { return (0, useHistoryEnabled_1.useHistoryEnabled)(props); }, { initialProps: initialProps }), result = _a.result, rerender = _a.rerender;
        return { result: result, rerender: rerender };
    };
    it('should return false (isHistoryEnabled) if historyTab is not active', function () {
        var props = {
            entity: undefined,
            perspectiveId: 'profile',
            historyButtonId: 0
        };
        var result = getHistoryEnabled(props).result;
        expect(result.current.isHistoryEnabled).toEqual(false);
        expect(result.current.isProfilePersisted).toEqual(undefined);
    });
    it('should return true (isHistoryEnabled) if entity is changed and history tab is active', function () {
        var props = {
            entity: profileEntity,
            perspectiveId: 'profile',
            historyButtonId: 1
        };
        var _a = getHistoryEnabled(props), result = _a.result, rerender = _a.rerender;
        expect(result.current.isHistoryEnabled).toEqual(true);
        expect(result.current.isProfilePersisted).toEqual(true);
        rerender({
            entity: nextProfileEntity,
            perspectiveId: 'profile',
            historyButtonId: 1
        });
        expect(result.current.isHistoryEnabled).toEqual(true);
        expect(result.current.isProfilePersisted).toEqual(true);
    });
    it('should return false (isHistoryEnabled, isProfilePersisted) if entity is temporary', function () {
        var props = {
            entity: tempProfileEntity,
            perspectiveId: 'profile',
            historyButtonId: 1
        };
        var result = getHistoryEnabled(props).result;
        expect(result.current.isHistoryEnabled).toEqual(false);
        expect(result.current.isProfilePersisted).toEqual(false);
    });
    it('should return false (isHistoryEnabled, isProfilePersisted) if entity is DataTenantEntity', function () {
        var props = {
            entity: dataTenantProfileEntity,
            perspectiveId: 'profile',
            historyButtonId: 1
        };
        var result = getHistoryEnabled(props).result;
        expect(result.current.isHistoryEnabled).toEqual(false);
        expect(result.current.isProfilePersisted).toEqual(false);
    });
});
