Skip to content

Commit 36f4b14

Browse files
committed
test(mdviewer): add table editing integration tests
Add 20 table tests: render verification, Tab navigation, Tab adds new row at last cell, Enter/Shift+Enter blocked in cells, ArrowDown/Right/ Enter exit at last cell, paragraph creation on exit, block/list toolbar buttons hidden in table, toolbar restore on exit, context menu with delete table, table wrapper removal, cursor placement after delete, headers editable, add-column button visibility. Add broadcastSelectionStateSync export in editor.js to bypass RAF for test toolbar state updates. Add __broadcastSelectionStateForTest helper in bridge.js.
1 parent 7139e1b commit 36f4b14

6 files changed

Lines changed: 774 additions & 21 deletions

File tree

src-mdviewer/src/bridge.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getState, setState } from "./core/state.js";
88
import { setLocale } from "./core/i18n.js";
99
import { marked } from "marked";
1010
import * as docCache from "./core/doc-cache.js";
11+
import { broadcastSelectionStateSync } from "./components/editor.js";
1112

1213
let _syncId = 0;
1314
let _lastReceivedSyncId = -1;
@@ -125,6 +126,9 @@ export function initBridge() {
125126
window.__resetCacheForTest = function () {
126127
docCache.clearAll();
127128
};
129+
window.__broadcastSelectionStateForTest = function () {
130+
broadcastSelectionStateSync();
131+
};
128132
window.__triggerContentSync = function () {
129133
const content = document.getElementById("viewer-content");
130134
if (content) {

src-mdviewer/src/components/editor.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,17 @@ function broadcastSelectionState() {
295295
if (rafId) cancelAnimationFrame(rafId);
296296
rafId = requestAnimationFrame(() => {
297297
rafId = null;
298-
const state = {
298+
_emitSelectionState();
299+
});
300+
}
301+
302+
/** Synchronous version for test access — bypasses RAF. */
303+
export function broadcastSelectionStateSync() {
304+
_emitSelectionState();
305+
}
306+
307+
function _emitSelectionState() {
308+
const state = {
299309
bold: document.queryCommandState("bold"),
300310
italic: document.queryCommandState("italic"),
301311
strikethrough: document.queryCommandState("strikethrough"),
@@ -343,7 +353,6 @@ function broadcastSelectionState() {
343353

344354
// Show "Type / to insert" hint on the empty paragraph at cursor
345355
updateEmptyLineHint(contentEl);
346-
});
347356
}
348357

349358
function updateEmptyLineHint(contentEl) {

src-mdviewer/to-create-tests.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@
55
- [ ] Empty table cell renders as `| |` in markdown source
66
- [ ] Table cell with `<br>` only-child is treated as empty (br stripped before conversion)
77
- [ ] Table cell with actual content + `<br>` preserves the line break
8-
- [ ] Tab navigation between table cells works
9-
- [ ] Adding new row via Tab at last cell works
8+
- [x] Tab navigation between table cells works
9+
- [x] Adding new row via Tab at last cell works
1010
- [ ] Delete row / delete column via context menu works and syncs to CM
11-
- [ ] Table header editing syncs correctly to CM
12-
- [ ] Enter key blocked in table cells (no paragraph/line break insertion)
13-
- [ ] Shift+Enter blocked in table cells
14-
- [ ] Block-level format buttons hidden when cursor is in table (quote, hr, table, codeblock, lists)
15-
- [ ] Block type selector (Paragraph/H1/H2/H3) hidden when cursor is in table
16-
- [ ] Dropdown groups for lists and blocks hidden when cursor is in table
11+
- [x] Table headers are editable in edit mode
12+
- [x] Enter key blocked in table cells (no paragraph/line break insertion)
13+
- [x] Shift+Enter blocked in table cells
14+
- [x] Block-level format buttons hidden when cursor is in table (quote, hr, table, codeblock, lists)
15+
- [x] Block type selector (Paragraph/H1/H2/H3) hidden when cursor is in table
16+
- [x] Dropdown groups for lists and blocks hidden when cursor is in table
1717
- [ ] Pasting multi-line text in table cell converts to single line (newlines → spaces)
18-
- [ ] Moving cursor out of table restores all toolbar buttons
19-
- [ ] ArrowRight at end of last cell exits table to paragraph below
20-
- [ ] ArrowDown from last cell exits table to paragraph below
21-
- [ ] Enter in last cell exits table to paragraph below
22-
- [ ] If no paragraph exists below table, one is created on exit
23-
- [ ] If paragraph exists below table, cursor moves into it (no duplicate)
18+
- [x] Moving cursor out of table restores all toolbar buttons
19+
- [x] ArrowRight at end of last cell exits table to paragraph below
20+
- [x] ArrowDown from last cell exits table to paragraph below
21+
- [x] Enter in last cell exits table to paragraph below
22+
- [x] If no paragraph exists below table, one is created on exit
23+
- [x] If paragraph exists below table, cursor moves into it (no duplicate)
2424
- [ ] Cursor in table wrapper gap (outside cells) + Enter exits table
2525
- [ ] Cursor in table wrapper gap (outside cells) + typing is blocked
2626
- [ ] Table rows don't visually expand when cursor is in wrapper gap
27-
- [ ] "Delete table" option appears in table right-click context menu
27+
- [x] "Delete table" option appears in table right-click context menu
2828
- [ ] "Delete table" option appears in row handle menu
2929
- [ ] "Delete table" option appears in column handle menu
30-
- [ ] Deleting table removes entire table-wrapper from DOM
31-
- [ ] Deleting table places cursor in next sibling element
32-
- [ ] Deleting table at end of document creates new empty paragraph
30+
- [x] Deleting table removes entire table-wrapper from DOM
31+
- [x] Deleting table places cursor outside table after deletion
32+
- [x] Deleting table at end of document creates new empty paragraph
3333
- [ ] Deleting table syncs removal to CM source
3434
- [ ] Deleting table creates undo entry (Ctrl+Z restores table)
3535
- [ ] Add-column button (+) has visible dashed border matching add-row button style
36-
- [ ] Add-column button visible when table is active (cursor inside)
36+
- [x] Add-column button visible when table is active (cursor inside)
3737

3838
## Image Handling
3939
- [ ] Images not reloaded when editing text in CM (DOM nodes preserved)

test/UnitTestSuite.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ define(function (require, exports, module) {
113113
require("spec/md-editor-integ-test");
114114
require("spec/md-editor-edit-integ-test");
115115
require("spec/md-editor-edit-more-integ-test");
116+
require("spec/md-editor-table-integ-test");
116117
require("spec/NewFileContentManager-test");
117118
require("spec/InstallExtensionDialog-integ-test");
118119
require("spec/ExtensionInstallation-test");
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Table Test
2+
3+
Some text before the table.
4+
5+
| Header One | Header Two | Header Three |
6+
|------------|------------|--------------|
7+
| Cell A1 | Cell A2 | Cell A3 |
8+
| Cell B1 | Cell B2 | Cell B3 |
9+
| Cell C1 | Cell C2 | Cell C3 |
10+
11+
A paragraph between tables.
12+
13+
| Name | Value |
14+
|--------|-------|
15+
| Alpha | 100 |
16+
| Beta | 200 |
17+
18+
Final paragraph after tables.

0 commit comments

Comments
 (0)