Skip to content

Commit 7585ae2

Browse files
committed
test(mdviewer): improve list split and Shift+Enter assertions
Verify Enter splits li content into consecutive 'Second' and 'item with some text' lis (not just count increase). Verify Shift+Enter keeps li count unchanged and text stays in same bullet.
1 parent e3fa543 commit 7585ae2

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

test/spec/md-editor-edit-integ-test.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,24 @@ define(function (require, exports, module) {
718718
// Press Enter
719719
_dispatchKey("Enter");
720720

721-
// Should have one more li
721+
// Should have one more li with content split correctly
722722
await awaitsFor(() => {
723-
return parentUl.querySelectorAll(":scope > li").length > itemCountBefore;
724-
}, "new li to be created after Enter");
723+
const lis = Array.from(parentUl.querySelectorAll(":scope > li"));
724+
if (lis.length <= itemCountBefore) { return false; }
725+
// The original li should no longer contain the full unsplit text
726+
if (targetLi.textContent.includes("Second item with some text")) {
727+
return false;
728+
}
729+
// Find two consecutive lis: one ending with "Second" and next starting with "item"
730+
for (let i = 0; i < lis.length - 1; i++) {
731+
const cur = lis[i].textContent.trim();
732+
const next = lis[i + 1].textContent.trim();
733+
if (cur === "Second" && next.startsWith("item with some text")) {
734+
return true;
735+
}
736+
}
737+
return false;
738+
}, "li to split into consecutive 'Second' and 'item with some text'");
725739

726740
await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE, { _forceClose: true }),
727741
"force close");
@@ -756,7 +770,7 @@ define(function (require, exports, module) {
756770
"force close");
757771
}, 10000);
758772

759-
it("should Shift+Enter in list item insert line break within same bullet", async function () {
773+
it("should Shift+Enter in list item insert line break without creating new bullet", async function () {
760774
await _openMdFile("list-test.md");
761775
await _enterEditMode();
762776

@@ -770,19 +784,28 @@ define(function (require, exports, module) {
770784
}
771785
expect(targetLi).not.toBeNull();
772786

787+
const parentUl = targetLi.closest("ul");
788+
const itemCountBefore = parentUl.querySelectorAll(":scope > li").length;
789+
773790
// Place cursor at end of first item
774791
_placeCursorAtEnd(targetLi);
775792

776793
// Press Shift+Enter
777794
_dispatchKey("Enter", { shiftKey: true });
778795

779-
// Should still be in the same li (not a new li)
796+
// Li count should NOT increase (no new bullet created)
797+
expect(parentUl.querySelectorAll(":scope > li").length).toBe(itemCountBefore);
798+
799+
// Should still be in the same li
780800
const curEl = _getCursorElement();
781-
expect(curEl && curEl.closest("li")).not.toBeNull();
801+
expect(curEl && curEl.closest("li")).toBe(targetLi);
782802

783-
// The li should contain a <br> (line break)
803+
// The li should contain a <br> (line break within same bullet)
784804
expect(targetLi.querySelector("br")).not.toBeNull();
785805

806+
// The text content should still be in one li (not split)
807+
expect(targetLi.textContent).toContain("First item");
808+
786809
await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE, { _forceClose: true }),
787810
"force close");
788811
}, 10000);

0 commit comments

Comments
 (0)