heynote/tests/delete-block.spec.js
Jonatan Heyman 52a6c444eb Position the cursor at the beginning of the next block when a block is deleted
This also changes the behavior when blocks are moved.
Add tests for the deleteBlock command.
2025-01-09 14:16:20 +01:00

45 lines
1.3 KiB
JavaScript

import {expect, test} from "@playwright/test";
import {HeynotePage} from "./test-utils.js";
import { AUTO_SAVE_INTERVAL } from "../src/common/constants.js"
import { NoteFormat } from "../src/common/note-format.js"
let heynotePage
test.beforeEach(async ({page}) => {
heynotePage = new HeynotePage(page)
await heynotePage.goto()
expect((await heynotePage.getBlocks()).length).toBe(1)
await heynotePage.setContent(`
∞∞∞text
Block A
∞∞∞markdown
Block B
∞∞∞text
Block C`)
await page.waitForTimeout(100)
})
test("delete first block", async ({page}) => {
await heynotePage.setCursorPosition(10)
await page.locator("body").press(heynotePage.agnosticKey("Mod+Shift+D"))
await page.waitForTimeout(50)
expect(await heynotePage.getCursorPosition()).toBe(13)
})
test("delete middle block", async ({page}) => {
await heynotePage.setCursorPosition(32)
await page.locator("body").press(heynotePage.agnosticKey("Mod+Shift+D"))
await page.waitForTimeout(50)
expect(await heynotePage.getCursorPosition()).toBe(25)
})
test("delete last block", async ({page}) => {
await heynotePage.setCursorPosition(52)
await page.locator("body").press(heynotePage.agnosticKey("Mod+Shift+D"))
await page.waitForTimeout(50)
expect(await heynotePage.getCursorPosition()).toBe(36)
})