-
Notifications
You must be signed in to change notification settings - Fork 114
Add configurable tables support #1104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width,initial-scale=1"> | ||
| <title>Lexxy Test — Tables Disabled</title> | ||
| <link rel="stylesheet" href="/styles.css"> | ||
| </head> | ||
| <body> | ||
| <form> | ||
| <div class="title"> | ||
| <input type="text" name="post[title]" placeholder="Post title" aria-label="Post title"> | ||
| </div> | ||
|
|
||
| <div class="body"> | ||
| <lexxy-editor class="lexxy-content" placeholder="Write something..." tables="false" required></lexxy-editor> | ||
| </div> | ||
|
|
||
| <div class="events"></div> | ||
| </form> | ||
|
|
||
| <script type="module" src="/editor.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { test } from "../../test_helper.js" | ||
| import { expect } from "@playwright/test" | ||
| import { startMonitoringConsole } from "../../helpers/assertions.js" | ||
|
|
||
| const TABLE_HTML = | ||
| '<figure class="lexxy-content__table-wrapper"><table><thead><tr><th>alpha</th><th>beta</th></tr></thead><tbody><tr><td>gamma</td><td>delta</td></tr></tbody></table></figure><p>After table</p>' | ||
|
|
||
| const valueOf = async (editor) => { | ||
| await editor.flush() | ||
| return editor.value() | ||
| } | ||
|
|
||
| test.describe("Tables disabled", () => { | ||
| test("the table toolbar button is present by default (regression baseline)", async ({ page }) => { | ||
| await page.goto("/") | ||
| await page.waitForSelector("lexxy-toolbar[connected]") | ||
|
|
||
| await expect(page.locator("lexxy-toolbar button[name='table']")).toBeVisible() | ||
| }) | ||
|
|
||
| test("the table toolbar button is hidden when tables are disabled", async ({ page }) => { | ||
| await page.goto("/tables-false.html") | ||
| await page.waitForSelector("lexxy-editor[connected]") | ||
| await page.waitForSelector("lexxy-toolbar[connected]") | ||
|
|
||
| await expect(page.locator("lexxy-toolbar button[name='table']")).toBeHidden() | ||
| }) | ||
|
|
||
| test("dispatching insertTable does nothing when tables are disabled", async ({ page, editor }) => { | ||
| await page.goto("/tables-false.html") | ||
| await editor.waitForConnected() | ||
|
|
||
| await editor.click() | ||
| await editor.locator.evaluate((el) => el.editor.update(() => el.editor.dispatchCommand("insertTable"))) | ||
|
|
||
| await expect(editor.content.locator("table")).toHaveCount(0) | ||
| await expect.poll(() => valueOf(editor)).not.toContain("<table") | ||
|
Comment on lines
+33
to
+37
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }) | ||
|
|
||
| test("the lexxy-table-tools element is not created when tables are disabled", async ({ page, editor }) => { | ||
| await page.goto("/tables-false.html") | ||
| await editor.waitForConnected() | ||
|
|
||
| await expect(editor.locator.locator("lexxy-table-tools")).toHaveCount(0) | ||
| }) | ||
|
|
||
| test("loading a table strips it to plain text when tables are disabled", async ({ page, editor }) => { | ||
| await page.goto("/tables-false.html") | ||
| await editor.waitForConnected() | ||
|
|
||
| await editor.setValue(TABLE_HTML) | ||
|
|
||
| await expect(editor.content.locator("table")).toHaveCount(0) | ||
| await expect.poll(() => valueOf(editor)).not.toContain("<table") | ||
| await expect.poll(() => valueOf(editor)).not.toContain("lexxy-content__table-wrapper") | ||
| await expect.poll(() => valueOf(editor)).toContain("After table") | ||
|
|
||
| // strip-to-plain-text must preserve the cell content, not drop it | ||
| const value = await valueOf(editor) | ||
| for (const cell of [ "alpha", "beta", "gamma", "delta" ]) { | ||
| expect(value).toContain(cell) | ||
| } | ||
| }) | ||
|
|
||
| test("editor connects without crashing when tables are disabled", async ({ page }) => { | ||
| startMonitoringConsole(page) | ||
|
|
||
| await page.goto("/tables-false.html") | ||
| await page.waitForSelector("lexxy-editor[connected]") | ||
|
|
||
| expect(page).toHaveNoErrors() | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| require "application_system_test_case" | ||
|
|
||
| class TablesDisabledTest < ApplicationSystemTestCase | ||
| setup do | ||
| visit edit_post_path(posts(:empty), tables_disabled: true) | ||
| wait_for_editor | ||
| end | ||
|
|
||
| test "the table toolbar button is not visible" do | ||
| assert_no_selector "lexxy-toolbar button[name='table']" | ||
| end | ||
|
|
||
| test "the lexxy-table-tools element is not created" do | ||
| assert_no_selector "lexxy-editor lexxy-table-tools" | ||
| end | ||
|
|
||
| test "a saved table is stripped to plain text on load and round-trips without one" do | ||
| find_editor.value = '<figure class="lexxy-content__table-wrapper"><table><thead><tr><th>alpha</th><th>beta</th></tr></thead><tbody><tr><td>gamma</td><td>delta</td></tr></tbody></table></figure><p>After table</p>' | ||
|
|
||
| assert_no_selector "lexxy-editor table" | ||
| assert_text "After table" | ||
| assert_text "alpha" | ||
| assert_text "delta" | ||
|
|
||
| click_on "Update Post" | ||
|
|
||
| within "article.post" do | ||
| assert_no_selector "table" | ||
| assert_text "After table" | ||
| assert_text "alpha" | ||
| assert_text "delta" | ||
| end | ||
|
|
||
| click_on "Edit this post" | ||
| wait_for_editor | ||
| assert_no_match(/<table/, find_editor.value) | ||
| assert_includes find_editor.value, "alpha" | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working as intended. The
data-tables/data-attachmentsattributes drive button visibility for Lexxy's default toolbar template, which always ships those buttons. External (toolbar="id") and pre-rendered<lexxy-toolbar>toolbars are consumer-authored — the consumer controls which buttons exist, so if tables are disabled they simply omit the table button. This mirrors the existingdata-attachmentsbehavior. Actual disabling happens at the editor level regardless of toolbar: the table nodes/plugin are never registered anddispatchInsertTable()no-ops, so a stray button would be inert anyway.