mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 13:21:55 +00:00
test: strengthen getSectionContent recursive child section coverage
- Assert exact section count (2) instead of loose > 0 check - Verify section ordering: requested first, children after - Assert child sectionTitle matches mock data - Add negative test: children excluded when recursive=false
This commit is contained in:
@@ -99,13 +99,10 @@ describe("getSectionContent", () => {
|
|||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Should include at least the requested section
|
// sec-catch-clause has sec-try-statement as a child, so expect 2 sections
|
||||||
expect(result.sections.length).toBeGreaterThan(0);
|
expect(result.sections.length).toBe(2);
|
||||||
const requestedSection = result.sections.find(
|
expect(result.sections[0].sectionId).toBe("sec-catch-clause");
|
||||||
(s) => s.sectionId === "sec-catch-clause",
|
expect(result.sections[1].sectionId).toBe("sec-try-statement");
|
||||||
);
|
|
||||||
expect(requestedSection).toBeDefined();
|
|
||||||
expect(requestedSection?.found).toBe(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should include recursively fetched child sections in output", async () => {
|
test("should include recursively fetched child sections in output", async () => {
|
||||||
@@ -114,16 +111,36 @@ describe("getSectionContent", () => {
|
|||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// sec-catch-clause has sec-try-statement as a child in mock data
|
// Requested section should come first
|
||||||
|
expect(result.sections[0].sectionId).toBe("sec-catch-clause");
|
||||||
|
|
||||||
|
// Child section should be included after requested section
|
||||||
const childSection = result.sections.find(
|
const childSection = result.sections.find(
|
||||||
(s) => s.sectionId === "sec-try-statement",
|
(s) => s.sectionId === "sec-try-statement",
|
||||||
);
|
);
|
||||||
expect(childSection).toBeDefined();
|
expect(childSection).toBeDefined();
|
||||||
expect(childSection?.found).toBe(true);
|
expect(childSection?.found).toBe(true);
|
||||||
|
expect(childSection?.sectionTitle).toBe("The try Statement");
|
||||||
expect(childSection?.content).toBeString();
|
expect(childSection?.content).toBeString();
|
||||||
expect(childSection?.content.length).toBeGreaterThan(0);
|
expect(childSection?.content.length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("should not include children when recursive is false", async () => {
|
||||||
|
const result = await getContentTool({
|
||||||
|
sectionIds: ["sec-catch-clause"],
|
||||||
|
recursive: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Only the requested section, no children
|
||||||
|
expect(result.sections.length).toBe(1);
|
||||||
|
expect(result.sections[0].sectionId).toBe("sec-catch-clause");
|
||||||
|
|
||||||
|
const childSection = result.sections.find(
|
||||||
|
(s) => s.sectionId === "sec-try-statement",
|
||||||
|
);
|
||||||
|
expect(childSection).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
test("should preserve input order in output", async () => {
|
test("should preserve input order in output", async () => {
|
||||||
const sectionIds = ["sec-for-statement", "sec-if-statement"];
|
const sectionIds = ["sec-for-statement", "sec-if-statement"];
|
||||||
const result = await getContentTool({
|
const result = await getContentTool({
|
||||||
|
|||||||
Reference in New Issue
Block a user