Spaces:
Sleeping
Sleeping
File size: 1,900 Bytes
097eaf0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import { WebCrawler } from "../crawler";
describe("WebCrawler - noSections", () => {
let crawler: WebCrawler;
beforeEach(() => {
crawler = new WebCrawler({
jobId: "test-job",
initialUrl: "https://example.com",
baseUrl: "https://example.com",
includes: [],
excludes: [],
});
});
describe("noSections method", () => {
it("should return true for URLs without hash fragments", () => {
expect(crawler["noSections"]("https://example.com/page")).toBe(true);
expect(crawler["noSections"]("https://example.com/blog/post")).toBe(true);
expect(crawler["noSections"]("https://example.com")).toBe(true);
});
it("should return false for simple anchor links", () => {
expect(crawler["noSections"]("https://example.com/page#section")).toBe(
false,
);
expect(crawler["noSections"]("https://example.com/page#top")).toBe(false);
expect(crawler["noSections"]("https://example.com/page#")).toBe(false);
expect(crawler["noSections"]("https://example.com/page#a")).toBe(false);
});
it("should return true for hash fragments that look like routes", () => {
expect(crawler["noSections"]("https://example.com/app#/dashboard")).toBe(
true,
);
expect(
crawler["noSections"]("https://example.com/spa#/user/profile"),
).toBe(true);
expect(
crawler["noSections"]("https://example.com/page#/settings/account"),
).toBe(true);
});
it("should return false for short hash fragments even with slashes", () => {
expect(crawler["noSections"]("https://example.com/page#/")).toBe(false);
});
it("should handle edge cases", () => {
expect(crawler["noSections"]("https://example.com/page#ab")).toBe(false);
expect(crawler["noSections"]("https://example.com/page#abc/def")).toBe(
true,
);
});
});
});
|