|
| 1 | +import { test, expect } from "./fixtures/auth"; |
| 2 | +import { navigateToEditorPage } from "./fixtures/editor-helpers"; |
| 3 | + |
| 4 | +test.describe("Editor list indentation", () => { |
| 5 | + test.beforeEach(async ({ authenticatedPage: page }) => { |
| 6 | + await navigateToEditorPage(page); |
| 7 | + }); |
| 8 | + |
| 9 | + test("Tab indents a bullet list item into a nested list", async ({ |
| 10 | + authenticatedPage: page, |
| 11 | + }) => { |
| 12 | + const editor = page.locator('[contenteditable="true"]'); |
| 13 | + await expect(editor).toBeVisible({ timeout: 10_000 }); |
| 14 | + |
| 15 | + // Create a bullet list with two items via slash command |
| 16 | + await editor.click(); |
| 17 | + await page.keyboard.press("End"); |
| 18 | + await page.keyboard.press("Enter"); |
| 19 | + await page.keyboard.type("/"); |
| 20 | + |
| 21 | + const bulletOption = page |
| 22 | + .locator('[role="option"]') |
| 23 | + .filter({ hasText: "Bullet List" }); |
| 24 | + await expect(bulletOption).toBeVisible({ timeout: 3_000 }); |
| 25 | + await bulletOption.click(); |
| 26 | + |
| 27 | + await page.keyboard.type("First item"); |
| 28 | + await page.keyboard.press("Enter"); |
| 29 | + await page.keyboard.type("Second item"); |
| 30 | + |
| 31 | + // Verify we start with a flat list (no nested <ul>) |
| 32 | + await expect(editor.locator("ul ul")).not.toBeVisible(); |
| 33 | + |
| 34 | + // Press Tab to indent the second item |
| 35 | + await page.keyboard.press("Tab"); |
| 36 | + |
| 37 | + // Lexical wraps the indented item in a nested <ul> inside a wrapper <li> |
| 38 | + const nestedList = editor.locator("ul ul"); |
| 39 | + await expect(nestedList).toBeVisible(); |
| 40 | + await expect(nestedList.locator("> li")).toHaveCount(1); |
| 41 | + await expect(nestedList.locator("> li")).toContainText("Second item"); |
| 42 | + }); |
| 43 | + |
| 44 | + test("Shift+Tab unindents a nested bullet list item", async ({ |
| 45 | + authenticatedPage: page, |
| 46 | + }) => { |
| 47 | + const editor = page.locator('[contenteditable="true"]'); |
| 48 | + await expect(editor).toBeVisible({ timeout: 10_000 }); |
| 49 | + |
| 50 | + // Create a bullet list and indent the second item |
| 51 | + await editor.click(); |
| 52 | + await page.keyboard.press("End"); |
| 53 | + await page.keyboard.press("Enter"); |
| 54 | + await page.keyboard.type("/"); |
| 55 | + |
| 56 | + const bulletOption = page |
| 57 | + .locator('[role="option"]') |
| 58 | + .filter({ hasText: "Bullet List" }); |
| 59 | + await expect(bulletOption).toBeVisible({ timeout: 3_000 }); |
| 60 | + await bulletOption.click(); |
| 61 | + |
| 62 | + await page.keyboard.type("First item"); |
| 63 | + await page.keyboard.press("Enter"); |
| 64 | + await page.keyboard.type("Second item"); |
| 65 | + await page.keyboard.press("Tab"); |
| 66 | + |
| 67 | + // Verify it's nested |
| 68 | + const nestedList = editor.locator("ul ul"); |
| 69 | + await expect(nestedList).toBeVisible(); |
| 70 | + |
| 71 | + // Now Shift+Tab to unindent |
| 72 | + await page.keyboard.press("Shift+Tab"); |
| 73 | + |
| 74 | + // Should be back to a flat list with no nesting |
| 75 | + await expect(nestedList).not.toBeVisible(); |
| 76 | + }); |
| 77 | + |
| 78 | + test("Tab indents a numbered list item into a nested list", async ({ |
| 79 | + authenticatedPage: page, |
| 80 | + }) => { |
| 81 | + const editor = page.locator('[contenteditable="true"]'); |
| 82 | + await expect(editor).toBeVisible({ timeout: 10_000 }); |
| 83 | + |
| 84 | + // Create a numbered list via slash command |
| 85 | + await editor.click(); |
| 86 | + await page.keyboard.press("End"); |
| 87 | + await page.keyboard.press("Enter"); |
| 88 | + await page.keyboard.type("/"); |
| 89 | + |
| 90 | + const numberedOption = page |
| 91 | + .locator('[role="option"]') |
| 92 | + .filter({ hasText: "Numbered List" }); |
| 93 | + await expect(numberedOption).toBeVisible({ timeout: 3_000 }); |
| 94 | + await numberedOption.click(); |
| 95 | + |
| 96 | + await page.keyboard.type("First item"); |
| 97 | + await page.keyboard.press("Enter"); |
| 98 | + await page.keyboard.type("Second item"); |
| 99 | + |
| 100 | + // Press Tab to indent |
| 101 | + await page.keyboard.press("Tab"); |
| 102 | + |
| 103 | + // The second item should be nested inside the first |
| 104 | + const nestedList = editor.locator("ol ol"); |
| 105 | + await expect(nestedList).toBeVisible(); |
| 106 | + await expect(nestedList.locator("> li")).toHaveCount(1); |
| 107 | + }); |
| 108 | +}); |
0 commit comments