2023-12-25 17:41:15 +01:00
|
|
|
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())
|
|
|
|
}
|
2023-12-26 00:27:43 +01:00
|
|
|
|
2023-12-25 17:41:15 +01:00
|
|
|
async setContent(content) {
|
2023-12-29 10:47:02 +01:00
|
|
|
await expect(this.page.locator("css=.cm-editor")).toBeVisible()
|
2023-12-25 17:41:15 +01:00
|
|
|
await this.page.evaluate((content) => window._heynote_editor.setContent(content), content)
|
|
|
|
}
|
|
|
|
|
2024-01-04 16:11:26 +01:00
|
|
|
async getCursorPosition() {
|
|
|
|
return await this.page.evaluate(() => window._heynote_editor.getCursorPosition())
|
|
|
|
}
|
|
|
|
|
2023-12-25 17:41:15 +01:00
|
|
|
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)
|
|
|
|
}
|
2024-01-04 14:27:04 +01:00
|
|
|
|
|
|
|
async getStoredSettings() {
|
|
|
|
return await this.page.evaluate(() => JSON.parse(window.localStorage.getItem("settings")))
|
|
|
|
}
|
2023-12-25 17:41:15 +01:00
|
|
|
}
|