@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
83 lines • 3.7 kB
JavaScript
;
/**
* @jest-environment jsdom
*/
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("@testing-library/react");
const constants_1 = require("../wallet-api/constants");
const featureFlags_1 = require("../featureFlags");
const useInternalAppIds_1 = require("./useInternalAppIds");
const useShowProviderLoadingTransition_1 = require("./useShowProviderLoadingTransition");
jest.mock("../featureFlags", () => ({
useFeature: jest.fn(),
}));
jest.mock("../wallet-api/constants", () => ({
INTERNAL_APP_IDS: ["internal-app-id-1", "internal-app-id-2"],
}));
jest.mock("./useInternalAppIds", () => ({
useInternalAppIds: jest.fn(),
}));
describe("useShowProviderLoadingTransition", () => {
const mockUseFeature = featureFlags_1.useFeature;
const mockUseInternalAppIds = useInternalAppIds_1.useInternalAppIds;
beforeEach(() => {
jest.clearAllMocks();
});
it("should return false when feature is disabled", () => {
mockUseFeature.mockReturnValue({ enabled: false, params: {} });
const { result } = (0, react_1.renderHook)(() => (0, useShowProviderLoadingTransition_1.useShowProviderLoadingTransition)({
manifest: { id: "test-app-id" },
isLoading: true,
}));
expect(result.current).toBe(false);
});
it("should return false for internal apps", () => {
mockUseFeature.mockReturnValue({ enabled: true, params: {} });
mockUseInternalAppIds.mockReturnValue(constants_1.INTERNAL_APP_IDS);
const { result } = (0, react_1.renderHook)(() => (0, useShowProviderLoadingTransition_1.useShowProviderLoadingTransition)({
manifest: { id: "internal-app-id-1" },
isLoading: true,
}));
expect(result.current).toBe(false);
});
it("should return true when loading and feature is enabled", () => {
mockUseFeature.mockReturnValue({ enabled: true, params: {} });
mockUseInternalAppIds.mockReturnValue([]);
const { result } = (0, react_1.renderHook)(() => (0, useShowProviderLoadingTransition_1.useShowProviderLoadingTransition)({
manifest: { id: "test-app-id" },
isLoading: true,
}));
expect(result.current).toBe(true);
});
it("should handle extended loading state", () => {
jest.useFakeTimers();
mockUseFeature.mockReturnValue({ enabled: true, params: { durationMs: 1000 } });
mockUseInternalAppIds.mockReturnValue([]);
const { result, rerender } = (0, react_1.renderHook)(({ isLoading }) => (0, useShowProviderLoadingTransition_1.useShowProviderLoadingTransition)({
manifest: { id: "test-app-id" },
isLoading,
}), {
initialProps: { isLoading: true },
});
expect(result.current).toBe(true);
// Simulate the timeout
jest.advanceTimersByTime(1000);
rerender({ isLoading: false });
expect(result.current).toBe(false);
jest.useRealTimers();
});
it("should clear timeout on unmount", () => {
jest.useFakeTimers();
mockUseFeature.mockReturnValue({ enabled: true, params: { durationMs: 1000 } });
mockUseInternalAppIds.mockReturnValue([]);
const { unmount } = (0, react_1.renderHook)(() => (0, useShowProviderLoadingTransition_1.useShowProviderLoadingTransition)({
manifest: { id: "test-app-id" },
isLoading: true,
}));
unmount();
// Advance timers to ensure no memory leaks
jest.advanceTimersByTime(1000);
jest.useRealTimers();
});
});
//# sourceMappingURL=useShowProviderLoadingTransition.test.js.map