mirror of
https://github.com/heyman/heynote.git
synced 2025-06-28 13:31:38 +02:00
Add tests for creating new Note buffers
This commit is contained in:
parent
fb58bb6f36
commit
d54a3ba633
@ -1 +1,2 @@
|
|||||||
export const SCRATCH_FILE_NAME = "scratch.txt"
|
export const SCRATCH_FILE_NAME = "scratch.txt"
|
||||||
|
export const AUTO_SAVE_INTERVAL = 2000
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { EditorSelection, Transaction } from "@codemirror/state"
|
import { EditorSelection, Transaction } from "@codemirror/state"
|
||||||
|
|
||||||
import { heynoteEvent, LANGUAGE_CHANGE, CURRENCIES_LOADED, ADD_NEW_BLOCK, DELETE_BLOCK } from "../annotation.js";
|
import { heynoteEvent, LANGUAGE_CHANGE, CURRENCIES_LOADED, ADD_NEW_BLOCK, DELETE_BLOCK } from "../annotation.js";
|
||||||
import { blockState, getActiveNoteBlock, getFirstNoteBlock, getLastNoteBlock, getNoteBlockFromPos } from "./block"
|
import { blockState, getActiveNoteBlock, getFirstNoteBlock, getLastNoteBlock, getNoteBlockFromPos } from "./block"
|
||||||
import { moveLineDown, moveLineUp } from "./move-lines.js";
|
import { moveLineDown, moveLineUp } from "./move-lines.js";
|
||||||
|
@ -22,6 +22,7 @@ import { autoSaveContent } from "./save.js"
|
|||||||
import { todoCheckboxPlugin} from "./todo-checkbox.ts"
|
import { todoCheckboxPlugin} from "./todo-checkbox.ts"
|
||||||
import { links } from "./links.js"
|
import { links } from "./links.js"
|
||||||
import { NoteFormat } from "../common/note-format.js"
|
import { NoteFormat } from "../common/note-format.js"
|
||||||
|
import { AUTO_SAVE_INTERVAL } from "../common/constants.js"
|
||||||
import { useNotesStore } from "../stores/notes-store.js";
|
import { useNotesStore } from "../stores/notes-store.js";
|
||||||
import { useErrorStore } from "../stores/error-store.js";
|
import { useErrorStore } from "../stores/error-store.js";
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ export class HeynoteEditor {
|
|||||||
return {class: view.state.facet(EditorView.darkTheme) ? "dark-theme" : "light-theme"}
|
return {class: view.state.facet(EditorView.darkTheme) ? "dark-theme" : "light-theme"}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
autoSaveContent(this, 2000),
|
autoSaveContent(this, AUTO_SAVE_INTERVAL),
|
||||||
|
|
||||||
todoCheckboxPlugin,
|
todoCheckboxPlugin,
|
||||||
markdown(),
|
markdown(),
|
||||||
|
69
tests/buffer-creation.spec.js
Normal file
69
tests/buffer-creation.spec.js
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
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"
|
||||||
|
import exp from "constants";
|
||||||
|
|
||||||
|
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
|
||||||
|
∞∞∞text
|
||||||
|
Block B
|
||||||
|
∞∞∞text
|
||||||
|
Block C`)
|
||||||
|
await page.waitForTimeout(100);
|
||||||
|
// check that blocks are created
|
||||||
|
expect((await heynotePage.getBlocks()).length).toBe(3)
|
||||||
|
|
||||||
|
// check that visual block layers are created
|
||||||
|
await expect(page.locator("css=.heynote-blocks-layer > div")).toHaveCount(3)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test("default buffer saved", async ({page}) => {
|
||||||
|
// make some change and make sure content is auto saved in default scratch buffer
|
||||||
|
await page.locator("body").pressSequentially("YAY")
|
||||||
|
await page.waitForTimeout(AUTO_SAVE_INTERVAL + 50);
|
||||||
|
const bufferList = await heynotePage.getStoredBufferList()
|
||||||
|
expect(Object.keys(bufferList).length).toBe(1)
|
||||||
|
expect(bufferList["scratch.txt"]).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
test("create new buffer from block", async ({page}) => {
|
||||||
|
await page.locator("body").press(heynotePage.agnosticKey("Mod+S"))
|
||||||
|
await page.waitForTimeout(50)
|
||||||
|
await page.locator("body").pressSequentially("My New Buffer")
|
||||||
|
await page.locator("body").press("Enter")
|
||||||
|
await page.waitForTimeout(50)
|
||||||
|
await page.locator("body").press("Enter")
|
||||||
|
await page.locator("body").pressSequentially("New buffer content")
|
||||||
|
await page.waitForTimeout(AUTO_SAVE_INTERVAL + 50);
|
||||||
|
|
||||||
|
const buffers = Object.keys(await heynotePage.getStoredBufferList())
|
||||||
|
expect(buffers).toContain("scratch.txt")
|
||||||
|
expect(buffers).toContain("my-new-buffer.txt")
|
||||||
|
|
||||||
|
const defaultBuffer = NoteFormat.load(await heynotePage.getStoredBuffer("scratch.txt"))
|
||||||
|
const newBuffer = NoteFormat.load(await heynotePage.getStoredBuffer("my-new-buffer.txt"))
|
||||||
|
|
||||||
|
|
||||||
|
expect(defaultBuffer.content).toBe(`
|
||||||
|
∞∞∞text
|
||||||
|
Block A
|
||||||
|
∞∞∞text
|
||||||
|
Block B`)
|
||||||
|
|
||||||
|
expect(newBuffer.content).toBe(`
|
||||||
|
∞∞∞text
|
||||||
|
Block C
|
||||||
|
New buffer content`)
|
||||||
|
|
||||||
|
})
|
@ -56,4 +56,16 @@ export class HeynotePage {
|
|||||||
async getStoredSettings() {
|
async getStoredSettings() {
|
||||||
return await this.page.evaluate(() => JSON.parse(window.localStorage.getItem("settings")))
|
return await this.page.evaluate(() => JSON.parse(window.localStorage.getItem("settings")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getStoredBufferList() {
|
||||||
|
return await this.page.evaluate(() => window.heynote.buffer.getList())
|
||||||
|
}
|
||||||
|
|
||||||
|
async getStoredBuffer(path) {
|
||||||
|
return await this.page.evaluate((path) => window.heynote.buffer.load(path), path)
|
||||||
|
}
|
||||||
|
|
||||||
|
agnosticKey(key) {
|
||||||
|
return key.replace("Mod", this.isMac ? "Meta" : "Control")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ import { Exception } from "sass";
|
|||||||
import { SETTINGS_CHANGE_EVENT, OPEN_SETTINGS_EVENT } from "../electron/constants";
|
import { SETTINGS_CHANGE_EVENT, OPEN_SETTINGS_EVENT } from "../electron/constants";
|
||||||
import { NoteFormat } from "../src/common/note-format";
|
import { NoteFormat } from "../src/common/note-format";
|
||||||
|
|
||||||
|
const NOTE_KEY_PREFIX = "heynote-library__"
|
||||||
|
|
||||||
const mediaMatch = window.matchMedia('(prefers-color-scheme: dark)')
|
const mediaMatch = window.matchMedia('(prefers-color-scheme: dark)')
|
||||||
let themeCallback = null
|
let themeCallback = null
|
||||||
mediaMatch.addEventListener("change", async (event) => {
|
mediaMatch.addEventListener("change", async (event) => {
|
||||||
@ -75,9 +77,6 @@ if (settingsData !== null) {
|
|||||||
initialSettings = Object.assign(initialSettings, JSON.parse(settingsData))
|
initialSettings = Object.assign(initialSettings, JSON.parse(settingsData))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const NOTE_KEY_PREFIX = "heynote-library__"
|
|
||||||
|
|
||||||
function noteKey(path) {
|
function noteKey(path) {
|
||||||
return NOTE_KEY_PREFIX + path
|
return NOTE_KEY_PREFIX + path
|
||||||
}
|
}
|
||||||
@ -161,7 +160,7 @@ const Heynote = {
|
|||||||
return localStorage.getItem(noteKey(path)) !== null
|
return localStorage.getItem(noteKey(path)) !== null
|
||||||
},
|
},
|
||||||
|
|
||||||
async getList(path) {
|
async getList() {
|
||||||
//return {"scratch.txt": {name:"Scratch"}}
|
//return {"scratch.txt": {name:"Scratch"}}
|
||||||
const notes = {}
|
const notes = {}
|
||||||
for (let [key, content] of Object.entries(localStorage)) {
|
for (let [key, content] of Object.entries(localStorage)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user