Skip to content

Commit 1e50bf0

Browse files
test: add Playwright tests for clearHistory()
Tests verify: - Undo cannot revert into a pre-refresh diagram after clearHistory() - Operations performed after clearHistory() are themselves undoable/redoable - The first undo baseline is the refreshed diagram state, not a prior one
1 parent 15a42c9 commit 1e50bf0

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

tests/clear-history.spec.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { test, expect } from './mind-elixir-test'
2+
3+
const diagramA = {
4+
nodeData: {
5+
id: 'root-a',
6+
topic: 'Diagram A',
7+
children: [
8+
{ id: 'child-a', topic: 'Child A' },
9+
],
10+
},
11+
}
12+
13+
const diagramB = {
14+
nodeData: {
15+
id: 'root-b',
16+
topic: 'Diagram B',
17+
children: [
18+
{ id: 'child-b', topic: 'Child B' },
19+
],
20+
},
21+
}
22+
23+
test.beforeEach(async ({ me }) => {
24+
await me.init(diagramA)
25+
})
26+
27+
test('clearHistory - undo cannot revert into the pre-refresh diagram', async ({ page, me }) => {
28+
// Perform an operation in Diagram A
29+
await me.click('Child A')
30+
await page.keyboard.press('Tab')
31+
await page.keyboard.press('Enter')
32+
await expect(me.getByText('New Node')).toBeVisible()
33+
34+
// Load a new diagram and clear the history
35+
await page.evaluate(data => {
36+
const mind = (window as any)['#map']
37+
mind.refresh(data)
38+
mind.clearHistory()
39+
}, diagramB)
40+
41+
// Diagram B should now be shown
42+
await expect(me.getByText('Diagram B')).toBeVisible()
43+
await expect(me.getByText('Diagram A')).toBeHidden()
44+
45+
// Undo should NOT travel back into Diagram A
46+
await page.keyboard.press('Control+z')
47+
await expect(me.getByText('Diagram B')).toBeVisible()
48+
await expect(me.getByText('Diagram A')).toBeHidden()
49+
50+
// Redo should also be a no-op
51+
await page.keyboard.press('Control+y')
52+
await expect(me.getByText('Diagram B')).toBeVisible()
53+
await expect(me.getByText('Diagram A')).toBeHidden()
54+
})
55+
56+
test('clearHistory - operations after clearHistory are undoable normally', async ({ page, me }) => {
57+
// Perform an operation in Diagram A then load Diagram B and clear history
58+
await me.click('Child A')
59+
await page.keyboard.press('Delete')
60+
await expect(me.getByText('Child A')).toBeHidden()
61+
62+
await page.evaluate(data => {
63+
const mind = (window as any)['#map']
64+
mind.refresh(data)
65+
mind.clearHistory()
66+
}, diagramB)
67+
68+
// Now add a node to Diagram B
69+
await me.click('Child B')
70+
await page.keyboard.press('Tab')
71+
await page.keyboard.press('Enter')
72+
await expect(me.getByText('New Node')).toBeVisible()
73+
74+
// Undo the add — should work
75+
await page.keyboard.press('Control+z')
76+
await expect(me.getByText('New Node')).toBeHidden()
77+
78+
// Redo the add — should also work
79+
await page.keyboard.press('Control+y')
80+
await expect(me.getByText('New Node')).toBeVisible()
81+
82+
// One more undo should be a no-op (no history before the cleared point)
83+
await page.keyboard.press('Control+z') // undo add
84+
await page.keyboard.press('Control+z') // should be no-op, not reach Diagram A
85+
await expect(me.getByText('Diagram B')).toBeVisible()
86+
await expect(me.getByText('Diagram A')).toBeHidden()
87+
})
88+
89+
test('clearHistory - first undo baseline is the refreshed diagram state', async ({ page, me }) => {
90+
// Load Diagram B, clear history, then add a node and undo
91+
await page.evaluate(data => {
92+
const mind = (window as any)['#map']
93+
mind.refresh(data)
94+
mind.clearHistory()
95+
}, diagramB)
96+
97+
await me.click('Child B')
98+
await page.keyboard.press('Tab')
99+
await page.keyboard.press('Enter')
100+
await expect(me.getByText('New Node')).toBeVisible()
101+
102+
// Undo restores exactly to the state right after refresh (Diagram B with just Child B)
103+
await page.keyboard.press('Control+z')
104+
await expect(me.getByText('New Node')).toBeHidden()
105+
await expect(me.getByText('Child B')).toBeVisible()
106+
await expect(me.getByText('Diagram B')).toBeVisible()
107+
})

0 commit comments

Comments
 (0)