Skip to content

Commit 00e6259

Browse files
committed
fix: shared textarea ref
1 parent 5baa643 commit 00e6259

48 files changed

Lines changed: 802 additions & 457 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

e2e/helpers/consts/commands.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const CMD_CREATE_FILE = 'Lineage Dev: Create new file';
2+
export const CMD_CLOSE_OTHER_TABS = 'Close all other tabs';
3+
4+
export const CMD_CLOSE_CURRENT_TAB = 'Close current tab';
5+
6+
export const CMD_UNDO_CLOSE_TAB = 'Undo close tab';
7+
export const CMD_GO_TO_PREVIOUS_TAB = 'Go to previous tab';
8+
export const CMD_GO_TO_NEXT_TAB = 'Go to next tab';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ export const LINEAGE_CARD = '.lineage__card';
66

77
export const MARKDOWN_PREVIEW = '.content';
88

9+
export const LINEAGE_TEXTAREA = '.lineage__card textarea';
10+
911
export const COLUMN = '.column';
12+
13+
export const SEL_ACTIVE_LEAF = '.workspace-leaf.mod-active';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ElementHandle, Page } from '@playwright/test';
2+
import {
3+
LINEAGE_CARD,
4+
LINEAGE_TEXTAREA,
5+
LINEAGE_VIEW,
6+
MARKDOWN_PREVIEW,
7+
} from '../consts/selectors';
8+
import invariant from 'tiny-invariant';
9+
import { getLeaf } from './obsidian';
10+
11+
const getView = async (obsidian: Page) => {
12+
const leaf = await getLeaf(obsidian);
13+
const view = await leaf.$(LINEAGE_VIEW);
14+
invariant(view);
15+
return view;
16+
};
17+
18+
export const getCard = async (obsidian: Page) => {
19+
const view = await getView(obsidian);
20+
const card = await view.$(LINEAGE_CARD);
21+
invariant(card);
22+
return card;
23+
};
24+
25+
export const getTextArea = async (obsidian: Page) => {
26+
const view = await getView(obsidian);
27+
const textArea = await view.$(LINEAGE_TEXTAREA);
28+
invariant(textArea);
29+
return textArea;
30+
};
31+
export const getCardText = async (
32+
card: ElementHandle<HTMLElement | SVGElement>,
33+
) => {
34+
const content = await card.$(MARKDOWN_PREVIEW);
35+
if (!content) throw new Error('content is undefined');
36+
return content.textContent();
37+
};

e2e/helpers/getters/obsidian.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { _electron as electron } from 'playwright-core';
2+
import { Page } from '@playwright/test';
3+
import { SEL_ACTIVE_LEAF } from '../consts/selectors';
4+
import invariant from 'tiny-invariant';
5+
import { delay } from '../general/delay';
6+
7+
const __obsidianInstance__: { current: Page | null } = {
8+
current: null,
9+
};
10+
11+
export const closeObsidian = async () => {
12+
if (__obsidianInstance__.current) {
13+
await __obsidianInstance__.current.close();
14+
await delay(1000);
15+
}
16+
};
17+
18+
export const getObsidian = async () => {
19+
const electronApp = await electron.launch({
20+
executablePath: process.env.OBSIDIAN_EXECUTABLE_PATH,
21+
});
22+
const obsidian = await electronApp.firstWindow();
23+
__obsidianInstance__.current = obsidian;
24+
return obsidian;
25+
};
26+
export const getLeaf = async (obsidian: Page) => {
27+
const leaf = await obsidian.$(SEL_ACTIVE_LEAF);
28+
invariant(leaf);
29+
return leaf;
30+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Page } from '@playwright/test';
2+
import { runCommand } from './run-command';
3+
import { CMD_CREATE_FILE } from '../consts/commands';
4+
import { LINEAGE_VIEW } from '../consts/selectors';
5+
6+
export const createNewLineageFile = async (obsidian: Page) => {
7+
await runCommand(obsidian, CMD_CREATE_FILE);
8+
await obsidian.focus(LINEAGE_VIEW);
9+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Page } from '@playwright/test';
2+
import { delay } from '../general/delay';
3+
import { getTextArea } from '../getters/lineage-view';
4+
5+
export const moveCardRight = async (obsidian: Page) => {
6+
await obsidian.keyboard.press('Shift+Alt+ArrowRight');
7+
await delay(200);
8+
};
9+
export const createCardBelow = async (obsidian: Page) => {
10+
await obsidian.keyboard.press('Control+J');
11+
await delay(200);
12+
};
13+
14+
export const saveCard = async (obsidian: Page) => {
15+
const textArea = await getTextArea(obsidian);
16+
await textArea.click();
17+
await obsidian.keyboard.press('Control+Shift+Enter');
18+
await delay(200);
19+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Page } from '@playwright/test';
2+
import { runCommand } from './run-command';
3+
import { CMD_CLOSE_OTHER_TABS } from '../consts/commands';
4+
import { LINEAGE_VIEW } from '../consts/selectors';
5+
6+
export const closeOtherTabs = async (obsidian: Page) => {
7+
await runCommand(obsidian, CMD_CLOSE_OTHER_TABS, false);
8+
await obsidian.focus(LINEAGE_VIEW);
9+
};

src/e2e/helpers/interactions/run-command.ts renamed to e2e/helpers/interactions/run-command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Page } from '@playwright/test';
22
import { PROMPT_INPUT } from '../consts/selectors';
3-
import { delay } from 'src/e2e/helpers/general/delay';
3+
import { delay } from '../general/delay';
44
import invariant from 'tiny-invariant';
55

66
const SEL_PALETTE_RESULTS = '.prompt-results';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, test } from '@playwright/test';
2+
import { LINEAGE_CARD } from '../helpers/consts/selectors';
3+
import { getCard, getCardText } from '../helpers/getters/lineage-view';
4+
import { closeObsidian, getObsidian } from '../helpers/getters/obsidian';
5+
import { createNewLineageFile } from '../helpers/interactions/lineage-commands';
6+
import { closeOtherTabs } from '../helpers/interactions/obsidian-commands';
7+
8+
test('should discard changes when user presses escape', async ({ page }) => {
9+
const obsidian = await getObsidian();
10+
11+
// create file 1
12+
await createNewLineageFile(obsidian);
13+
await closeOtherTabs(obsidian);
14+
15+
// insert text into f1_n1
16+
await obsidian.focus(LINEAGE_CARD);
17+
const f1_n1_text = 'file 1 card 1';
18+
await obsidian.keyboard.type(f1_n1_text);
19+
20+
// cancel changes
21+
await obsidian.keyboard.press('Escape');
22+
23+
// test text
24+
const f1_n1 = await getCard(obsidian);
25+
expect(await getCardText(f1_n1)).toEqual('');
26+
await closeObsidian();
27+
});

0 commit comments

Comments
 (0)