Add test for overriding one of the default key bindings

This commit is contained in:
Jonatan Heyman 2025-04-20 13:22:38 +02:00
parent 29ac62db01
commit a7a933c3ef
2 changed files with 24 additions and 0 deletions

View File

@ -25,6 +25,7 @@ test("add custom key binding", async ({page}) => {
await page.locator(".p-autocomplete-list li.p-autocomplete-option.p-focus").click() await page.locator(".p-autocomplete-list li.p-autocomplete-option.p-focus").click()
await page.locator("css=.settings .tab-content.tab-keyboard-bindings .add-key-binding-dialog .save").click() await page.locator("css=.settings .tab-content.tab-keyboard-bindings .add-key-binding-dialog .save").click()
await expect(page.locator("css=.settings .tab-content.tab-keyboard-bindings table tr.keybind-user")).toHaveCount(1) await expect(page.locator("css=.settings .tab-content.tab-keyboard-bindings table tr.keybind-user")).toHaveCount(1)
expect((await heynotePage.getSettings()).keyBindings).toEqual([{key:"Control-Shift-h", command:"openLanguageSelector"}])
await page.locator("css=.overlay .settings .dialog .bottom-bar .close").click() await page.locator("css=.overlay .settings .dialog .bottom-bar .close").click()
await page.locator("body").press("Control+Shift+H") await page.locator("body").press("Control+Shift+H")
await expect(page.locator("css=.language-selector .items > li.selected")).toBeVisible() await expect(page.locator("css=.language-selector .items > li.selected")).toBeVisible()
@ -43,6 +44,7 @@ test("delete custom key binding", async ({page}) => {
await page.locator(".p-autocomplete-list li.p-autocomplete-option.p-focus").click() await page.locator(".p-autocomplete-list li.p-autocomplete-option.p-focus").click()
await page.locator("css=.settings .tab-content.tab-keyboard-bindings .add-key-binding-dialog .save").click() await page.locator("css=.settings .tab-content.tab-keyboard-bindings .add-key-binding-dialog .save").click()
await expect(page.locator("css=.settings .tab-content.tab-keyboard-bindings table tr.keybind-user")).toHaveCount(1) await expect(page.locator("css=.settings .tab-content.tab-keyboard-bindings table tr.keybind-user")).toHaveCount(1)
expect((await heynotePage.getSettings()).keyBindings).toEqual([{key:"Control-Shift-h", command:"openLanguageSelector"}])
await page.locator("css=.overlay .settings .dialog .bottom-bar .close").click() await page.locator("css=.overlay .settings .dialog .bottom-bar .close").click()
await page.locator("body").press("Control+Shift+H") await page.locator("body").press("Control+Shift+H")
await expect(page.locator("css=.language-selector .items > li.selected")).toBeVisible() await expect(page.locator("css=.language-selector .items > li.selected")).toBeVisible()
@ -56,3 +58,15 @@ test("delete custom key binding", async ({page}) => {
await page.locator("body").press("Control+Shift+H") await page.locator("body").press("Control+Shift+H")
await expect(page.locator("css=.language-selector .items > li.selected")).toHaveCount(0) await expect(page.locator("css=.language-selector .items > li.selected")).toHaveCount(0)
}) })
test("disable default key binding", async ({page}) => {
await page.locator("body").press("Meta+L")
await expect(page.locator("css=.language-selector .items > li.selected")).toBeVisible()
await page.locator("body").press("Escape")
await expect(page.locator("css=.language-selector .items > li.selected")).toHaveCount(0)
const settings = await heynotePage.getSettings()
settings.keyBindings = [{key:"Meta-L", command:"nothing"}]
await heynotePage.setSettings(settings)
await page.locator("body").press("Meta+L")
await expect(page.locator("css=.language-selector .items > li.selected")).toHaveCount(0)
})

View File

@ -79,6 +79,16 @@ export class HeynotePage {
await this.page.evaluate(({path, content}) => window.heynote.buffer.save(path, content), {path, content:format.serialize()}) await this.page.evaluate(({path, content}) => window.heynote.buffer.save(path, content), {path, content:format.serialize()})
} }
async getSettings() {
return await this.page.evaluate(() => {
return JSON.parse(window.localStorage.getItem("settings") || "{}")
})
}
async setSettings(settings) {
await this.page.evaluate((settings) => window.heynote.setSettings(settings), settings)
}
agnosticKey(key) { agnosticKey(key) {
return key.replace("Mod", this.isMac ? "Meta" : "Control") return key.replace("Mod", this.isMac ? "Meta" : "Control")
} }