|
|
|
@ -1,5 +1,6 @@ |
|
|
|
import { act, cleanup, fireEvent, render, screen } from "@testing-library/react"; |
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
|
|
|
import { useEffect, useState } from "react"; |
|
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; |
|
|
|
import { I18nProvider } from "@/translations/provider"; |
|
|
|
import FindingMatchClient from "./finding-match-client"; |
|
|
|
@ -34,51 +35,6 @@ vi.mock("@/hooks/marriage/use-profile-main", () => ({ |
|
|
|
}), |
|
|
|
})); |
|
|
|
|
|
|
|
vi.mock("@/hooks/marriage/use-form-schema", () => ({ |
|
|
|
useFormOverviewQuery: () => ({ |
|
|
|
data: { |
|
|
|
sections: [ |
|
|
|
{ |
|
|
|
slug: "personal_identity", |
|
|
|
title: "Personal Identity", |
|
|
|
required: true, |
|
|
|
estimated_time_min: 3, |
|
|
|
is_completed: false, |
|
|
|
progress: { |
|
|
|
current_step: 0, |
|
|
|
completion_percent: 0, |
|
|
|
is_completed: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
}, |
|
|
|
isLoading: false, |
|
|
|
isFetched: true, |
|
|
|
isError: false, |
|
|
|
refetch: vi.fn(), |
|
|
|
}), |
|
|
|
getFormSection: vi.fn(), |
|
|
|
})); |
|
|
|
|
|
|
|
vi.mock("@/hooks/marriage/use-cattell", () => ({ |
|
|
|
useCattellResultQuery: () => ({ data: null }), |
|
|
|
getCattellQuestions: vi.fn(), |
|
|
|
})); |
|
|
|
|
|
|
|
vi.mock("@/hooks/marriage/use-glasser", () => ({ |
|
|
|
useGlasserResultQuery: () => ({ data: null }), |
|
|
|
getGlasserQuestions: vi.fn(), |
|
|
|
})); |
|
|
|
|
|
|
|
vi.mock("@/hooks/marriage/use-match-start", () => ({ |
|
|
|
useStartMarriageMatchMutation: () => ({ |
|
|
|
mutate: vi.fn(), |
|
|
|
isPending: false, |
|
|
|
isError: false, |
|
|
|
reset: vi.fn(), |
|
|
|
}), |
|
|
|
})); |
|
|
|
|
|
|
|
vi.mock("@/hooks/marriage/use-rejection-seen", () => ({ |
|
|
|
useRejectionSeenMutation: () => ({ |
|
|
|
mutate: vi.fn(), |
|
|
|
@ -95,6 +51,81 @@ vi.mock("@/hooks/marriage/use-marriage-advisors", () => ({ |
|
|
|
}), |
|
|
|
})); |
|
|
|
|
|
|
|
vi.mock("@/components/Componentes/questions-list-overlay", () => { |
|
|
|
let isQuestionsOpenGlobal = false; |
|
|
|
const listeners = new Set<() => void>(); |
|
|
|
|
|
|
|
return { |
|
|
|
useQuestionsListOverlay: () => { |
|
|
|
const [, setTick] = useState(0); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
const listener = () => setTick((t) => t + 1); |
|
|
|
listeners.add(listener); |
|
|
|
return () => { |
|
|
|
listeners.delete(listener); |
|
|
|
}; |
|
|
|
}, []); |
|
|
|
|
|
|
|
return { |
|
|
|
isQuestionsOpen: isQuestionsOpenGlobal, |
|
|
|
openQuestions: () => { |
|
|
|
isQuestionsOpenGlobal = true; |
|
|
|
listeners.forEach((l) => l()); |
|
|
|
}, |
|
|
|
closeQuestions: () => { |
|
|
|
isQuestionsOpenGlobal = false; |
|
|
|
listeners.forEach((l) => l()); |
|
|
|
}, |
|
|
|
}; |
|
|
|
}, |
|
|
|
QuestionsListOverlay: ({ |
|
|
|
open, |
|
|
|
onReady, |
|
|
|
}: { |
|
|
|
open: boolean; |
|
|
|
onReady?: () => void; |
|
|
|
}) => { |
|
|
|
useEffect(() => { |
|
|
|
onReady?.(); |
|
|
|
}, [onReady]); |
|
|
|
|
|
|
|
return open ? ( |
|
|
|
<aside |
|
|
|
role="dialog" |
|
|
|
data-slot="section-overlay" |
|
|
|
data-state="open" |
|
|
|
data-testid="questions-list-overlay" |
|
|
|
> |
|
|
|
<div>Questions List Overlay Content</div> |
|
|
|
</aside> |
|
|
|
) : null; |
|
|
|
}, |
|
|
|
default: ({ |
|
|
|
open, |
|
|
|
onReady, |
|
|
|
}: { |
|
|
|
open: boolean; |
|
|
|
onReady?: () => void; |
|
|
|
}) => { |
|
|
|
useEffect(() => { |
|
|
|
onReady?.(); |
|
|
|
}, [onReady]); |
|
|
|
|
|
|
|
return open ? ( |
|
|
|
<aside |
|
|
|
role="dialog" |
|
|
|
data-slot="section-overlay" |
|
|
|
data-state="open" |
|
|
|
data-testid="questions-list-overlay" |
|
|
|
> |
|
|
|
<div>Questions List Overlay Content</div> |
|
|
|
</aside> |
|
|
|
) : null; |
|
|
|
}, |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
function createWrapper() { |
|
|
|
const queryClient = new QueryClient({ |
|
|
|
defaultOptions: { |
|
|
|
@ -147,9 +178,8 @@ describe("FindingMatchClient", () => { |
|
|
|
|
|
|
|
it("opens questions list overlay when Edit Profile button is clicked", () => { |
|
|
|
const wrapper = createWrapper(); |
|
|
|
const { container } = render(<FindingMatchClient />, { wrapper }); |
|
|
|
render(<FindingMatchClient />, { wrapper }); |
|
|
|
|
|
|
|
// Initial render - overlay is pre-mounted offscreen
|
|
|
|
const editBtn = screen.getByRole("button", { name: /edit profile/i }); |
|
|
|
expect(editBtn).toBeInTheDocument(); |
|
|
|
|
|
|
|
@ -159,9 +189,7 @@ describe("FindingMatchClient", () => { |
|
|
|
vi.advanceTimersByTime(16); |
|
|
|
}); |
|
|
|
|
|
|
|
const overlay = container.querySelector('aside[data-slot="section-overlay"][data-state="open"]'); |
|
|
|
expect(overlay).toBeInTheDocument(); |
|
|
|
expect(document.body.classList.contains("section-overlay-open")).toBe(true); |
|
|
|
expect(screen.getByTestId("questions-list-overlay")).toBeInTheDocument(); |
|
|
|
}); |
|
|
|
|
|
|
|
it("renders locked state when can_edit_profile is false", () => { |
|
|
|
|