PluginProbe
Extendify / 3.1.1
Extendify v3.1.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / tests / unit / QuickEdit / lib / escape-rule.test.js

escape-rule.test.js in Extendify 3.1.1, at tests/unit/QuickEdit/lib/escape-rule.test.js

122 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // Pure escape-rule decision matrix.
2 //
3 // Mirrors the click-rule shape (decideClickAction in click-rule.js):
4 // the decision is a pure function tested without DOM dispatch plumbing.
5 // Wiring (listener attach, stopPropagation, store mutations) lives in
6 // global-escape.js and is exercised by global-escape.test.js.
7 //
8 // Priority order:
9 // 1. agent block + QE on same block → clear-selection-and-agent-block
10 // 2. agent block staged → clear-agent-block (cancels workflow too)
11 // 3. QE selection set → clear-selection
12 // 4. committedSelection → clear-committed-selection
13 // 5. else → noop (Esc must NOT flip edit mode off)
14 // * edit mode off → pass-through (the wiring layer bails early)
15
16 import { decideEscapeAction } from '@quick-edit/lib/escape-rule';
17
18 describe('decideEscapeAction — edit mode off', () => {
19 it('passes through regardless of selector state', () => {
20 expect(
21 decideEscapeAction({
22 editModeOn: false,
23 hasAgentBlock: true,
24 hasQuickEditSelection: true,
25 hasCommittedSelection: true,
26 }),
27 ).toEqual({ action: 'pass-through' });
28 });
29 });
30
31 describe('decideEscapeAction — priority order', () => {
32 it('agent block beats QE selection (different blocks)', () => {
33 expect(
34 decideEscapeAction({
35 editModeOn: true,
36 hasAgentBlock: true,
37 hasQuickEditSelection: true,
38 hasCommittedSelection: false,
39 sameBlock: false,
40 }),
41 ).toEqual({ action: 'clear-agent-block' });
42 });
43
44 it('agent block + QE selection on the same block collapses to one keypress', () => {
45 expect(
46 decideEscapeAction({
47 editModeOn: true,
48 hasAgentBlock: true,
49 hasQuickEditSelection: true,
50 hasCommittedSelection: false,
51 sameBlock: true,
52 }),
53 ).toEqual({ action: 'clear-selection-and-agent-block' });
54 });
55
56 it('agent block beats committedSelection', () => {
57 expect(
58 decideEscapeAction({
59 editModeOn: true,
60 hasAgentBlock: true,
61 hasQuickEditSelection: false,
62 hasCommittedSelection: true,
63 }),
64 ).toEqual({ action: 'clear-agent-block' });
65 });
66
67 it('QE selection beats committedSelection', () => {
68 expect(
69 decideEscapeAction({
70 editModeOn: true,
71 hasAgentBlock: false,
72 hasQuickEditSelection: true,
73 hasCommittedSelection: true,
74 }),
75 ).toEqual({ action: 'clear-selection' });
76 });
77
78 it('agent block alone returns clear-agent-block', () => {
79 expect(
80 decideEscapeAction({
81 editModeOn: true,
82 hasAgentBlock: true,
83 hasQuickEditSelection: false,
84 hasCommittedSelection: false,
85 }),
86 ).toEqual({ action: 'clear-agent-block' });
87 });
88
89 it('QE selection alone returns clear-selection', () => {
90 expect(
91 decideEscapeAction({
92 editModeOn: true,
93 hasAgentBlock: false,
94 hasQuickEditSelection: true,
95 hasCommittedSelection: false,
96 }),
97 ).toEqual({ action: 'clear-selection' });
98 });
99
100 it('committedSelection alone returns clear-committed-selection', () => {
101 expect(
102 decideEscapeAction({
103 editModeOn: true,
104 hasAgentBlock: false,
105 hasQuickEditSelection: false,
106 hasCommittedSelection: true,
107 }),
108 ).toEqual({ action: 'clear-committed-selection' });
109 });
110
111 it('nothing set returns noop (Esc does not turn off edit mode)', () => {
112 expect(
113 decideEscapeAction({
114 editModeOn: true,
115 hasAgentBlock: false,
116 hasQuickEditSelection: false,
117 hasCommittedSelection: false,
118 }),
119 ).toEqual({ action: 'noop' });
120 });
121 });
122