Add tests for toggleBlockFold

Change default key binding for folding
Get rid som some unnecessary waitForTimeout() calls
This commit is contained in:
Jonatan Heyman 2025-06-16 15:25:47 +02:00
parent 89002017c1
commit 85cfcc46fc
2 changed files with 102 additions and 11 deletions

View File

@ -62,8 +62,8 @@ export const DEFAULT_KEYMAP = [
cmd("Mod-Alt-ArrowUp", "newCursorAbove"), cmd("Mod-Alt-ArrowUp", "newCursorAbove"),
cmd("Mod-Shift-d", "deleteBlock"), cmd("Mod-Shift-d", "deleteBlock"),
cmd("Mod-d", "selectNextOccurrence"), cmd("Mod-d", "selectNextOccurrence"),
cmd(isMac ? "Cmd-Alt-[" : "Ctrl-Shift-[", "foldCode"), cmd(isMac ? "Cmd-Shift-[" : "Ctrl-Shift-[", "foldCode"),
cmd(isMac ? "Cmd-Alt-]" : "Ctrl-Shift-]", "unfoldCode"), cmd(isMac ? "Cmd-Shift-]" : "Ctrl-Shift-]", "unfoldCode"),
cmd("Mod-c", "copy"), cmd("Mod-c", "copy"),
cmd("Mod-v", "paste"), cmd("Mod-v", "paste"),
@ -96,9 +96,9 @@ export const DEFAULT_KEYMAP = [
cmd("Alt-Mod-]", "unfoldBlock"), cmd("Alt-Mod-]", "unfoldBlock"),
cmd("Alt-Mod-.", "toggleBlockFold") cmd("Alt-Mod-.", "toggleBlockFold")
] : [ ] : [
cmd("Ctrl-Shift-[", "foldBlock"), cmd("Alt-Ctrl-[", "foldBlock"),
cmd("Ctrl-Shift-]", "unfoldBlock"), cmd("Alt-Ctrl-]", "unfoldBlock"),
cmd("Ctrl-Shift-.", "toggleBlockFold") cmd("Alt-Ctrl-.", "toggleBlockFold")
]), ]),
// search // search

View File

@ -21,8 +21,7 @@ console.log("Block B")
let x = 42 let x = 42
return x * 2 return x * 2
text text
Block C Block C single line
Single line block
markdown markdown
# Block D # Block D
This is a markdown block This is a markdown block
@ -39,7 +38,6 @@ This is a markdown block
// Click on fold gutter to fold the block // Click on fold gutter to fold the block
await page.locator(".cm-foldGutter").first().click() await page.locator(".cm-foldGutter").first().click()
await page.waitForTimeout(100)
// Type a character - this should work if editor maintained focus // Type a character - this should work if editor maintained focus
await page.locator("body").pressSequentially("xyz yay") await page.locator("body").pressSequentially("xyz yay")
@ -56,7 +54,6 @@ This is a markdown block
// Click on line number gutter // Click on line number gutter
await page.locator(".cm-lineNumbers .cm-gutterElement:visible").first().click() await page.locator(".cm-lineNumbers .cm-gutterElement:visible").first().click()
await page.waitForTimeout(100)
// Type a character - this should work if editor maintained focus // Type a character - this should work if editor maintained focus
await page.locator("body").pressSequentially("abc test") await page.locator("body").pressSequentially("abc test")
@ -74,11 +71,105 @@ This is a markdown block
await expect(page.locator(".cm-foldPlaceholder")).not.toBeVisible() await expect(page.locator(".cm-foldPlaceholder")).not.toBeVisible()
// Fold block using keyboard shortcut // Fold block using keyboard shortcut
const foldKey = heynotePage.isMac ? "Alt+Meta+[" : "Ctrl+Shift+[" const foldKey = heynotePage.isMac ? "Alt+Meta+[" : "Alt+Ctrl+["
await page.locator("body").press(foldKey) await page.locator("body").press(foldKey)
await page.waitForTimeout(100)
// Verify block is folded by checking for fold placeholder // Verify block is folded by checking for fold placeholder
await expect(page.locator(".cm-foldPlaceholder")).toBeVisible() await expect(page.locator(".cm-foldPlaceholder")).toBeVisible()
}); });
test("multiple blocks can be folded and unfolded when selection overlaps multiple blocks", async ({ page }) => {
// Use Ctrl/Cmd+A twice to select all content across all blocks
await page.locator("body").press(heynotePage.agnosticKey("Mod+a")) // First press selects current block
await page.locator("body").press(heynotePage.agnosticKey("Mod+a")) // Second press selects entire buffer
// Verify no fold placeholders exist initially
await expect(page.locator(".cm-foldPlaceholder")).toHaveCount(0)
// Fold multiple blocks using keyboard shortcut
const foldKey = heynotePage.isMac ? "Alt+Meta+[" : "Alt+Ctrl+["
await page.locator("body").press(foldKey)
// Verify multiple blocks are folded (should see multiple fold placeholders)
const foldPlaceholders = page.locator(".cm-foldPlaceholder")
await expect(foldPlaceholders).toHaveCount(3) // Block A, B, and D should be folded (C is single line so won't fold)
// Unfold all blocks using keyboard shortcut
const unfoldKey = heynotePage.isMac ? "Alt+Meta+]" : "Alt+Ctrl+]"
await page.locator("body").press(unfoldKey)
// Verify all blocks are unfolded (no fold placeholders should remain)
await expect(page.locator(".cm-foldPlaceholder")).toHaveCount(0)
});
test("toggleBlockFold works on single block", async ({ page }) => {
// Position cursor in first block (which has multiple lines)
await heynotePage.setCursorPosition(20) // Middle of Block A
// Verify no fold placeholder exists initially
await expect(page.locator(".cm-foldPlaceholder")).toHaveCount(0)
// Toggle fold to fold the block
const toggleKey = heynotePage.isMac ? "Alt+Meta+." : "Alt+Ctrl+."
await page.locator("body").press(toggleKey)
// Verify block is folded
await expect(page.locator(".cm-foldPlaceholder")).toBeVisible()
// Toggle fold again to unfold the block
await page.locator("body").press(toggleKey)
// Verify block is unfolded
await expect(page.locator(".cm-foldPlaceholder")).toHaveCount(0)
});
test("toggleBlockFold works on multiple blocks", async ({ page }) => {
// Select all content across all blocks
await page.locator("body").press(heynotePage.agnosticKey("Mod+a")) // First press selects current block
await page.locator("body").press(heynotePage.agnosticKey("Mod+a")) // Second press selects entire buffer
// Verify no fold placeholders exist initially
await expect(page.locator(".cm-foldPlaceholder")).toHaveCount(0)
// Toggle fold to fold multiple blocks
const toggleKey = heynotePage.isMac ? "Alt+Meta+." : "Alt+Ctrl+."
await page.locator("body").press(toggleKey)
// Verify multiple blocks are folded
const foldPlaceholders = page.locator(".cm-foldPlaceholder")
await expect(foldPlaceholders).toHaveCount(3) // Block A, B, and D should be folded (C is single line)
// Toggle fold again to unfold all blocks
await page.locator("body").press(toggleKey)
// Verify all blocks are unfolded
await expect(page.locator(".cm-foldPlaceholder")).toHaveCount(0)
});
test("toggleBlockFold with mixed folded/unfolded state", async ({ page }) => {
// Fold Block A first
await heynotePage.setCursorPosition(20) // Middle of Block A
const foldKey = heynotePage.isMac ? "Alt+Meta+[" : "Alt+Ctrl+["
await page.locator("body").press(foldKey)
// Verify Block A is folded
await expect(page.locator(".cm-foldPlaceholder")).toHaveCount(1)
// Now select all blocks (some folded, some unfolded)
await page.locator("body").press(heynotePage.agnosticKey("Mod+a")) // First press selects current block
await page.locator("body").press(heynotePage.agnosticKey("Mod+a")) // Second press selects entire buffer
// Toggle fold on mixed state - should fold all unfolded blocks (since more are unfolded than folded)
const toggleKey = heynotePage.isMac ? "Alt+Meta+." : "Alt+Ctrl+."
await page.locator("body").press(toggleKey)
// Verify all foldable blocks are now folded (A was already folded, B and D should now be folded too)
await expect(page.locator(".cm-foldPlaceholder")).toHaveCount(3) // Block A, B, and D
// Toggle fold again - should unfold all blocks
await page.locator("body").press(toggleKey)
// Verify all blocks are now unfolded
await expect(page.locator(".cm-foldPlaceholder")).toHaveCount(0)
});
}); });