import { describe, beforeEach, it, expect, vi } from "vitest";
import { renderHook } from "@testing-library/react";
import { useFilteredSchools } from "./index";
import { useSchools } from "~/features/clientLibrary/useSchools";
const schoolsData = {
    primary_schools: [
        {
            name: "Académie Beyachad, Campus Pour Garçons",
            address: "6508, avenue Durocher",
            city: "Montreal",
            province: "QC",
            postalcode: "H2V 3Z3",
            country: "Canada",
            lat: 45.5256,
            lng: -73.614869,
            url: "http://www.yaldei.org/",
            proximity: {
                linear_distance: 1442.78325493,
            },
            school_attributes: {
                levels: ["elementary"],
                grades: "K-6",
                types: ["private"],
            },
            school_board_attributes: {},
        },
    ],
    high_schools: [
        {
            name: "Collège Français, Campus Montaigne",
            address: "172, avenue Fairmount Ouest",
            city: "Montreal",
            province: "QC",
            postalcode: "H2T 1E2",
            country: "Canada",
            lat: 45.521451,
            lng: -73.596282,
            proximity: {
                linear_distance: 254.95667664,
            },
            school_attributes: {
                levels: ["secondary"],
                grades: "7-11",
                types: ["private"],
            },
            school_board_attributes: {},
        },
        {
            name: "Édu2",
            address: "5800, boulevard Saint-Laurent",
            city: "Montreal",
            province: "QC",
            postalcode: "H2T 1T3",
            country: "Canada",
            lat: 45.527232,
            lng: -73.602526,
            url: "http://edu2.ca/",
            proximity: {
                linear_distance: 604.93638816,
            },
            school_attributes: {
                levels: ["secondary", "elementary"],
                grades: "K-11",
                types: ["public"],
            },
            school_board_attributes: {},
        },
    ],
};
vi.mock("~/features/clientLibrary/useSchools", () => ({
    useSchools: vi.fn(() => ({
        isLoading: false,
        data: schoolsData,
    })),
}));
describe("useFilteredSchools", () => {
    beforeEach(() => {
        vi.clearAllMocks();
    });
    it("should return the correct initial state", () => {
        var _a;
        const { result } = renderHook(() => useFilteredSchools({
            geogId: "g10_f25dvr2f",
            country: "CAN",
            filterLevel: undefined,
            filterType: undefined,
        }));
        expect(useSchools).toHaveBeenCalledWith({
            geogId: "g10_f25dvr2f",
            include: ["schools"],
            radius: 2000,
            limit: 30,
            buffer: 250,
        });
        expect(result.current.isLoading).toBe(false);
        expect(result.current.schools).toHaveLength(3);
        expect(result.current.filteredSchools).toHaveLength(3);
        expect((_a = result.current.filteredSchools) === null || _a === void 0 ? void 0 : _a.map((school) => school.name)).toEqual([
            "Académie Beyachad, Campus Pour Garçons",
            "Collège Français, Campus Montaigne",
            "Édu2",
        ]);
        expect(result.current.schoolLevels).toEqual(["elementary", "secondary"]);
        expect(result.current.schoolTypes).toEqual(["private", "public"]);
        expect(result.current.hasCategories).toBe(false);
    });
    it("should filter schools based on level", () => {
        var _a;
        const { result, rerender } = renderHook((props) => useFilteredSchools(props), {
            initialProps: {
                geogId: "g10_f25dvr2f",
                country: "CAN",
                filterLevel: undefined,
                filterType: undefined,
            },
        });
        // Filter by level
        rerender({
            geogId: "g10_f25dvr2f",
            country: "CAN",
            filterLevel: "elementary",
            filterType: undefined,
        });
        expect(result.current.filteredSchools).toHaveLength(2);
        expect((_a = result.current.filteredSchools) === null || _a === void 0 ? void 0 : _a.map((school) => school.name)).toEqual(["Académie Beyachad, Campus Pour Garçons", "Édu2"]);
    });
    it("should filter schools based on type", () => {
        var _a;
        const { result, rerender } = renderHook((props) => useFilteredSchools(props), {
            initialProps: {
                geogId: "g10_f25dvr2f",
                country: "CAN",
                filterLevel: undefined,
                filterType: undefined,
            },
        });
        // Filter by type
        rerender({
            geogId: "g10_f25dvr2f",
            country: "CAN",
            filterLevel: undefined,
            filterType: "private",
        });
        expect(result.current.filteredSchools).toHaveLength(2);
        expect((_a = result.current.filteredSchools) === null || _a === void 0 ? void 0 : _a.map((school) => school.name)).toEqual([
            "Académie Beyachad, Campus Pour Garçons",
            "Collège Français, Campus Montaigne",
        ]);
    });
    it("should filter schools based on level and type", () => {
        var _a;
        const { result, rerender } = renderHook((props) => useFilteredSchools(props), {
            initialProps: {
                geogId: "g10_f25dvr2f",
                country: "CAN",
                filterLevel: undefined,
                filterType: undefined,
            },
        });
        // Filter by level and type
        rerender({
            geogId: "g10_f25dvr2f",
            country: "CAN",
            filterLevel: "secondary",
            filterType: "public",
        });
        expect(result.current.filteredSchools).toHaveLength(1);
        expect((_a = result.current.filteredSchools) === null || _a === void 0 ? void 0 : _a.map((school) => school.name)).toEqual(["Édu2"]);
    });
});
//# sourceMappingURL=index.test.js.map