test: fix e2e tests

This commit is contained in:
ycnmhd 2025-01-08 21:03:56 +01:00
parent 16b18f375f
commit 264ef7eab7
No known key found for this signature in database
GPG key ID: E38ED8B2B6559A4E
15 changed files with 67 additions and 28 deletions

View file

@ -1,7 +1,7 @@
import { ElementHandle } from '@playwright/test';
import invariant from 'tiny-invariant';
export const MARKDOWN_PREVIEW = '.preview-container';
export const MARKDOWN_PREVIEW = '.lng-prev';
export const getCardText = async (
card: ElementHandle<HTMLElement | SVGElement>,
) => {

View file

@ -17,4 +17,6 @@ export const deleteCardUsingButton = async () => {
invariant(button);
await button.click();
await delay(SHORT);
await button.click();
await delay(SHORT);
};

View file

@ -1,10 +1,17 @@
import { getCardsOfColumns } from '../../../getters/lineage-view/card/get-cards-of-columns';
import { delay, SHORT } from '../../../general/delay';
import { MARKDOWN_PREVIEW } from '../../../getters/lineage-view/card/get-card-text';
import { LINEAGE_INLINE_EDITOR } from '../../../getters/lineage-view/card/get-inline-editor';
export const selectCard = async (column: number, cardNumber: number) => {
export const selectCard = async (
column: number,
cardNumber: number,
mode: 'preview' | 'edit' = 'preview',
) => {
const card = (await getCardsOfColumns())[column][cardNumber];
await card.click();
await card.waitForSelector(MARKDOWN_PREVIEW);
await card.waitForSelector(
mode === 'preview' ? MARKDOWN_PREVIEW : LINEAGE_INLINE_EDITOR,
);
await delay(SHORT);
};

View file

@ -6,4 +6,6 @@ export const deleteCardUsingHotkey = async () => {
await __obsidian__.waitForSelector(LINEAGE_CARD_ACTIVE);
await __obsidian__.keyboard.press('Control+Backspace');
await delay(SHORT);
await __obsidian__.keyboard.press('Control+Backspace');
await delay(SHORT);
};

View file

@ -3,7 +3,7 @@ import { getActiveView } from '../../../getters/lineage-view/card/get-active-vie
import { delay, SHORT } from '../../../general/delay';
import { __obsidian__ } from '../../../getters/obsidian/load-obsidian';
export const SEL_SEARCH_INPUT = `input[aria-label="Search document"]`;
export const SEL_SEARCH_INPUT = `input.search-input-element`;
export const setSearchQuery = async (query: string) => {
const input = await getSearchInput();

View file

@ -1,7 +1,7 @@
import invariant from 'tiny-invariant';
import { getActiveView } from '../../../getters/lineage-view/card/get-active-view';
const SEL_SEARCH_TOGGLE = `button[aria-label${'Toggle search input'}]`;
const SEL_SEARCH_TOGGLE = `button[aria-label="${'Toggle search input'}"]`;
export const toggleSearchQuery = async () => {
const view = await getActiveView();

View file

@ -0,0 +1,11 @@
import invariant from 'tiny-invariant';
import { getActiveView } from '../../../getters/lineage-view/card/get-active-view';
const SELECTOR = `div[aria-label="${'Show all cards'}"]`;
export const toggleShowAllSearchResults = async () => {
const view = await getActiveView();
const button = await view.$(SELECTOR);
invariant(button);
await button.click();
};

View file

@ -19,6 +19,7 @@ import { toggleSearchUsingHotkey } from '../helpers/interactions/lineage-view/ho
import { setSearchQuery } from '../helpers/interactions/lineage-view/search/set-search-query';
import { getTextsOfColumns } from '../helpers/getters/lineage-view/card/get-texts-of-columns';
import { discardInputChanges } from '../helpers/interactions/lineage-view/hotkeys/discard-input-changes';
import { toggleShowAllSearchResults } from '../helpers/interactions/lineage-view/search/toggle-show-all-search-results';
test.describe('card hotkeys', () => {
test('save card, edit card and discard changes using hotkey', async () => {
@ -359,6 +360,7 @@ test.describe('card hotkeys', () => {
await toggleSearchUsingHotkey();
await setSearchQuery('4');
await toggleShowAllSearchResults();
expect(await getTextsOfColumns()).toEqual([[], [], [n4]]);

30
package-lock.json generated
View file

@ -21,7 +21,7 @@
"devDependencies": {
"@commitlint/cli": "17.4.0",
"@commitlint/config-conventional": "17.4.0",
"@playwright/test": "1.42.1",
"@playwright/test": "1.49.1",
"@tsconfig/svelte": "5.0.2",
"@types/diff": "5.2.1",
"@types/electron": "1.6.10",
@ -1243,18 +1243,18 @@
}
},
"node_modules/@playwright/test": {
"version": "1.42.1",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.42.1.tgz",
"integrity": "sha512-Gq9rmS54mjBL/7/MvBaNOBwbfnh7beHvS6oS4srqXFcQHpQCV1+c8JXWE8VLPyRDhgS3H8x8A7hztqI9VnwrAQ==",
"version": "1.49.1",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.49.1.tgz",
"integrity": "sha512-Ky+BVzPz8pL6PQxHqNRW1k3mIyv933LML7HktS8uik0bUXNCdPhoS/kLihiO1tMf/egaJb4IutXd7UywvXEW+g==",
"dev": true,
"dependencies": {
"playwright": "1.42.1"
"playwright": "1.49.1"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=16"
"node": ">=18"
}
},
"node_modules/@rollup/rollup-android-arm-eabi": {
@ -5526,33 +5526,33 @@
}
},
"node_modules/playwright": {
"version": "1.42.1",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.42.1.tgz",
"integrity": "sha512-PgwB03s2DZBcNRoW+1w9E+VkLBxweib6KTXM0M3tkiT4jVxKSi6PmVJ591J+0u10LUrgxB7dLRbiJqO5s2QPMg==",
"version": "1.49.1",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.49.1.tgz",
"integrity": "sha512-VYL8zLoNTBxVOrJBbDuRgDWa3i+mfQgDTrL8Ah9QXZ7ax4Dsj0MSq5bYgytRnDVVe+njoKnfsYkH3HzqVj5UZA==",
"dev": true,
"dependencies": {
"playwright-core": "1.42.1"
"playwright-core": "1.49.1"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=16"
"node": ">=18"
},
"optionalDependencies": {
"fsevents": "2.3.2"
}
},
"node_modules/playwright-core": {
"version": "1.42.1",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.42.1.tgz",
"integrity": "sha512-mxz6zclokgrke9p1vtdy/COWBH+eOZgYUVVU34C73M+4j4HLlQJHtfcqiqqxpP0o8HhMkflvfbquLX5dg6wlfA==",
"version": "1.49.1",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.49.1.tgz",
"integrity": "sha512-BzmpVcs4kE2CH15rWfzpjzVGhWERJfmnXmniSyKeRZUs9Ws65m+RGIi7mjJK/euCegfn3i7jvqWeWyHe9y3Vgg==",
"dev": true,
"bin": {
"playwright-core": "cli.js"
},
"engines": {
"node": ">=16"
"node": ">=18"
}
},
"node_modules/playwright/node_modules/fsevents": {

View file

@ -17,7 +17,7 @@
"devDependencies": {
"@commitlint/cli": "17.4.0",
"@commitlint/config-conventional": "17.4.0",
"@playwright/test": "1.42.1",
"@playwright/test": "1.49.1",
"@tsconfig/svelte": "5.0.2",
"@types/diff": "5.2.1",
"@types/electron": "1.6.10",

View file

@ -23,7 +23,7 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */
workers: 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
reporter: 'null',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */

View file

@ -120,7 +120,7 @@ export const lang = {
// undo
controls_history: 'History',
controls_history_undo: 'Undo change',
controls_history_undo: 'Undo',
controls_history_redo: 'Redo',
hk_undo_change: 'Undo change',
hk_redo_change: 'Redo change',

View file

@ -94,9 +94,25 @@ export class InlineEditor {
this.inlineView.editor.focus();
};
isCursorInRange = (cursor: EditorPosition): boolean => {
const docStart = { line: 0, ch: 0 };
const lastLine = this.inlineView.editor.lastLine();
const docEnd = {
line: lastLine,
ch: this.inlineView.editor.getLine(lastLine).length,
};
const isLineInRange =
cursor.line >= docStart.line && cursor.line <= docEnd.line;
const isChInRange =
(cursor.line === docStart.line ? cursor.ch >= docStart.ch : true) &&
(cursor.line === docEnd.line ? cursor.ch <= docEnd.ch : true);
return isLineInRange && isChInRange;
};
restoreCursor = () => {
const existingCursor = this.cursorPositions.get(this.nodeId!);
if (existingCursor) {
if (existingCursor && this.isCursorInRange(existingCursor)) {
this.setCursor(existingCursor);
} else {
const lastLine = this.inlineView.editor.lastLine();
@ -108,10 +124,10 @@ export class InlineEditor {
}
};
unloadNode(nodeId?: string) {
unloadNode(nodeId?: string, discardChanges = false) {
const currentNodeId = this.nodeId;
if (nodeId && nodeId !== currentNodeId) return;
if (currentNodeId) {
if (currentNodeId && !discardChanges) {
this.saveContent();
const cursor = this.getCursor();
this.cursorPositions.set(currentNodeId, cursor);

View file

@ -3,7 +3,7 @@ import { LineageView } from 'src/view/view';
export const cancelChanges = (view: LineageView) => {
const documentViewState = view.viewStore.getValue().document;
if (documentViewState.pendingConfirmation.disableEdit) {
view.inlineEditor.unloadNode();
view.inlineEditor.unloadNode(undefined, true);
if (documentViewState.editing.isInSidebar) {
view.viewStore.dispatch({
type: 'view/sidebar/disable-edit',

View file

@ -8,7 +8,6 @@
const viewStore = view.viewStore;
const search = searchStore(view);
let focusTimeout: ReturnType<typeof setTimeout>;
const onInput = (
// eslint-disable-next-line no-undef
e: Event & { currentTarget: EventTarget & HTMLInputElement },