"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * @jest-environment jsdom
 */
const react_1 = require("@testing-library/react");
const useToggleOnboardingEarlyChecks_1 = require("./useToggleOnboardingEarlyChecks");
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
jest.useFakeTimers();
const mockedToggleOnboardingEarlyCheckAction = jest.fn();
describe("useToggleOnboardingEarlyCheck", () => {
    beforeEach(() => {
        mockedToggleOnboardingEarlyCheckAction.mockClear();
    });
    it("should return a success state when the toggle action is successful", async () => {
        mockedToggleOnboardingEarlyCheckAction.mockReturnValue((0, rxjs_1.of)({ toggleStatus: "success" }));
        const { result } = (0, react_1.renderHook)(() => (0, useToggleOnboardingEarlyChecks_1.useToggleOnboardingEarlyCheck)({
            toggleOnboardingEarlyCheckAction: mockedToggleOnboardingEarlyCheckAction,
            deviceId: "",
            toggleType: "enter",
        }));
        await (0, react_1.act)(async () => {
            jest.advanceTimersByTime(1);
        });
        expect(result.current.state).toEqual({
            toggleStatus: "success",
        });
    });
    it("should return a state initialized and reset at null when successively triggering the hook", async () => {
        const delayMs = 1000;
        mockedToggleOnboardingEarlyCheckAction.mockReturnValue((0, rxjs_1.of)({ toggleStatus: "success" }).pipe((0, operators_1.delay)(delayMs)));
        // Step 1: enter
        let toggleType = "enter";
        const { result, rerender } = (0, react_1.renderHook)(() => (0, useToggleOnboardingEarlyChecks_1.useToggleOnboardingEarlyCheck)({
            toggleOnboardingEarlyCheckAction: mockedToggleOnboardingEarlyCheckAction,
            deviceId: "",
            toggleType,
        }));
        // No response for now from the action -> reset to `none` value
        expect(result.current.state).toEqual(expect.objectContaining({
            toggleStatus: "none",
        }));
        await (0, react_1.act)(async () => {
            jest.advanceTimersByTime(delayMs);
        });
        expect(result.current.state).toEqual({
            toggleStatus: "success",
        });
        // Step 2: exit
        toggleType = "exit";
        rerender();
        // No response for now from the action -> reset to `none` value
        expect(result.current.state).toEqual(expect.objectContaining({
            toggleStatus: "none",
        }));
        await (0, react_1.act)(async () => {
            jest.advanceTimersByTime(delayMs);
        });
        expect(result.current.state).toEqual({
            toggleStatus: "success",
        });
        // Step 3: consumer reset manually with a `null` value
        toggleType = null;
        rerender();
        await (0, react_1.act)(async () => {
            jest.advanceTimersByTime(1);
        });
        expect(result.current.state).toEqual(expect.objectContaining({
            toggleStatus: "none",
        }));
        // Step 4: again an enter
        toggleType = "enter";
        rerender();
        // No response for now from the action -> reset to `none` value
        expect(result.current.state).toEqual(expect.objectContaining({
            toggleStatus: "none",
        }));
        await (0, react_1.act)(async () => {
            jest.advanceTimersByTime(delayMs);
        });
        expect(result.current.state).toEqual({
            toggleStatus: "success",
        });
    });
});
//# sourceMappingURL=useToggleOnboardingEarlyChecks.test.js.map