mirror of
https://github.com/heyman/heynote.git
synced 2024-12-01 04:14:24 +01:00
d0d8f872a6
* Add functionality to insert new block after the last block - Update key bindings in `initial-content.ts` to include `Alt + Enter` for adding a new block after the last block. - Implement `getLastNoteBlock` function in `block.js` to retrieve the last block in the note. - Add `addNewBlockAfterLast` command in `commands.js` to handle the insertion of a new block after the last one. - Integrate `addNewBlockAfterLast` command into the keymap in `keymap.js`. * Add block insertion before/after current, before first and after last. Also, tests. - Added `getFirstNoteBlock` in `block.js` for accessing the first text block. - Implemented new functions in `commands.js` like `addNewBlockBeforeCurrent` and `addNewBlockBeforeFirst`. - Updated `keymap.js` with new key bindings to facilitate block creation. - Introduced `block-creation.spec.js` for testing the new block manipulation features. * Fix visual bug when inserting new block at the top * Update help text and Readme * Fix wrong cursor position after inserting new blocks at the top of the buffer, when the previous first block's delimiter is long (e.g. Markdown) * Make RegEx more generic * Fix import * Auto-generate the README.md and initial-content documentation - Add a documentation generator - Add an option to force the initial content to be erased with an env variable * Add more specific tests * Fix Mod key on Mac in test --------- Co-authored-by: Jonatan Heyman <jonatan@heyman.info>
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
import { test, expect } from '@playwright/test';
|
|
|
|
export function pageErrorGetter(page) {
|
|
let messages = [];
|
|
page.on('pageerror', (error) => {
|
|
messages.push(`[${error.name}] ${error.message}`);
|
|
});
|
|
return () => messages;
|
|
}
|
|
|
|
|
|
export class HeynotePage {
|
|
constructor(page) {
|
|
this.page = page
|
|
this.getErrors = pageErrorGetter(page)
|
|
this.isMac = process.platform === "darwin"
|
|
}
|
|
|
|
async goto() {
|
|
await this.page.goto("/")
|
|
await expect(this.page).toHaveTitle(/Heynote/)
|
|
expect(this.getErrors()).toStrictEqual([])
|
|
}
|
|
|
|
async getBlocks() {
|
|
return await this.page.evaluate(() => window._heynote_editor.getBlocks())
|
|
}
|
|
|
|
async getContent() {
|
|
return await this.page.evaluate(() => window._heynote_editor.getContent())
|
|
}
|
|
|
|
async setContent(content) {
|
|
await expect(this.page.locator("css=.cm-editor")).toBeVisible()
|
|
await this.page.evaluate((content) => window._heynote_editor.setContent(content), content)
|
|
}
|
|
|
|
async getCursorPosition() {
|
|
return await this.page.evaluate(() => window._heynote_editor.getCursorPosition())
|
|
}
|
|
|
|
async getBlockContent(blockIndex) {
|
|
const blocks = await this.getBlocks()
|
|
const content = await this.getContent()
|
|
expect(blocks.length).toBeGreaterThan(blockIndex)
|
|
const block = blocks[blockIndex]
|
|
return content.slice(block.content.from, block.content.to)
|
|
}
|
|
|
|
async getStoredSettings() {
|
|
return await this.page.evaluate(() => JSON.parse(window.localStorage.getItem("settings")))
|
|
}
|
|
}
|