import { renderHook } from '@testing-library/react-hooks';
import * as PerspectivesSettingsContext from '../../../contexts/PerspectivesSettingsContext';
import { useHistoryEnabled } from './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 = renderHook(function (props) { return 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);
    });
});
