UNPKG

@ledgerhq/live-common

Version:
63 lines 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * @jest-environment jsdom */ const react_1 = require("@testing-library/react"); const featureFlags_1 = require("../../../../featureFlags"); const useIsSwapLiveApp_1 = require("./useIsSwapLiveApp"); // Mock dependencies. jest.mock("../../../../featureFlags"); const useMockFeature = featureFlags_1.useFeature; describe("useIsSwapLiveApp hook", () => { afterEach(() => { jest.clearAllMocks(); }); it("returns the enabled flag when currencyFrom is not defined", () => { // Set up the mock to return different values based on input useMockFeature.mockImplementation(flagName => { if (flagName === "ptxSwapLiveApp") { return { enabled: false }; } }); const { result } = (0, react_1.renderHook)(() => (0, useIsSwapLiveApp_1.useIsSwapLiveApp)()); expect(result.current.enabled).toBe(true); }); it("returns the enabled flag when families and currencies are not defined", () => { useMockFeature.mockImplementation(flagName => { if (flagName === "ptxSwapLiveApp") { return { enabled: false }; } }); const { result } = (0, react_1.renderHook)(() => (0, useIsSwapLiveApp_1.useIsSwapLiveApp)()); expect(result.current.enabled).toBe(true); }); it("returns true when currencyFrom family is in families array and feature is enabled", () => { useMockFeature.mockImplementation(flagName => { if (flagName === "ptxSwapLiveApp") { return { enabled: false }; } }); const { result } = (0, react_1.renderHook)(() => (0, useIsSwapLiveApp_1.useIsSwapLiveApp)()); expect(result.current.enabled).toBe(true); }); it("returns true when currencyFrom is in currencies array and feature is enabled", () => { useMockFeature.mockImplementation(flagName => { if (flagName === "ptxSwapLiveApp") { return { enabled: false }; } }); const { result } = (0, react_1.renderHook)(() => (0, useIsSwapLiveApp_1.useIsSwapLiveApp)()); expect(result.current.enabled).toBe(true); }); it("returns enabled flag if both families and currencies are empty arrays", () => { useMockFeature.mockImplementation(flagName => { if (flagName === "ptxSwapLiveApp") { return { enabled: false }; } }); const { result } = (0, react_1.renderHook)(() => (0, useIsSwapLiveApp_1.useIsSwapLiveApp)()); expect(result.current.enabled).toBe(true); }); }); //# sourceMappingURL=useIsSwapLiveApp.test.js.map