import { RouteService } from "../../partial-src/service/routeService"
export function run() {
    const interval = 500
    describe("Test route service", () => {
        it("Basic test", () => {
            let service = new RouteService()
            let visited = false
            service.route("/debug/:id/:name", (params: { id: string, name: string }) => {
                if (params.id !== "id" || params.name !== "name") {
                    throw new Error("invalid route service")
                }
                visited = true
            })
            service.goto("/debug/id/name")
            setTimeout(() => {
                if (!visited) throw new Error("Invalid route service")
                visited = false
                service.events.once("unhandledUrl", () => {
                    visited = true
                })
                // fake handle url
                service.handle("/QAQ")
                if (!visited) throw new Error("Invalided unhandled url")
                window.history.back()
            }, interval)
        })

    })
}
