|
| 1 | +import { fileURLToPath } from 'node:url'; |
| 2 | +import path from 'node:path'; |
| 3 | +import { test, expect } from '../../fixtures/superdoc.js'; |
| 4 | + |
| 5 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 6 | +const DOC_PATH = path.resolve(__dirname, 'fixtures/sd-3110-inline-sdt-appearance-variants.docx'); |
| 7 | + |
| 8 | +test.use({ config: { toolbar: 'full', showSelection: true } }); |
| 9 | + |
| 10 | +// The fixture has five paragraphs; we keep the wrapper-by-sdtId mapping |
| 11 | +// explicit because it's the contract this spec asserts against. |
| 12 | +const HIDDEN_IDS = ['1001', '1004', '1005'] as const; |
| 13 | +const VISIBLE_IDS = ['1002', '1003'] as const; // boundingBox + omitted (default) |
| 14 | +const HIDDEN_ALIAS_CANARIES = [ |
| 15 | + 'HIDDEN_ALIAS_LEAK_CANARY', |
| 16 | + 'HIDDEN_ALIAS_DOUBLE_A', |
| 17 | + 'HIDDEN_ALIAS_DOUBLE_B', |
| 18 | +] as const; |
| 19 | + |
| 20 | +const INLINE_SDT = '.superdoc-structured-content-inline'; |
| 21 | +const INLINE_LABEL = '.superdoc-structured-content-inline__label'; |
| 22 | + |
| 23 | +test.describe('inline SDT appearance=hidden (SD-3110)', () => { |
| 24 | + test.beforeEach(async ({ superdoc }) => { |
| 25 | + await superdoc.loadDocument(DOC_PATH); |
| 26 | + await superdoc.waitForStable(); |
| 27 | + }); |
| 28 | + |
| 29 | + test('hidden wrappers carry data-appearance="hidden" and visible ones do not', async ({ superdoc }) => { |
| 30 | + const attrs = await superdoc.page.evaluate((sel) => { |
| 31 | + return Array.from(document.querySelectorAll(sel)).map((el) => ({ |
| 32 | + sdtId: (el as HTMLElement).dataset.sdtId ?? null, |
| 33 | + appearance: (el as HTMLElement).dataset.appearance ?? null, |
| 34 | + })); |
| 35 | + }, INLINE_SDT); |
| 36 | + |
| 37 | + const byId = new Map(attrs.map((a) => [a.sdtId, a.appearance])); |
| 38 | + for (const id of HIDDEN_IDS) expect(byId.get(id)).toBe('hidden'); |
| 39 | + for (const id of VISIBLE_IDS) expect(byId.get(id)).toBeNull(); |
| 40 | + }); |
| 41 | + |
| 42 | + test('hidden wrappers have no alias label child; visible wrappers do', async ({ superdoc }) => { |
| 43 | + const labelPresence = await superdoc.page.evaluate( |
| 44 | + ({ sel, labelSel }) => { |
| 45 | + return Array.from(document.querySelectorAll(sel)).map((el) => ({ |
| 46 | + sdtId: (el as HTMLElement).dataset.sdtId ?? null, |
| 47 | + hasLabel: !!el.querySelector(labelSel), |
| 48 | + })); |
| 49 | + }, |
| 50 | + { sel: INLINE_SDT, labelSel: INLINE_LABEL }, |
| 51 | + ); |
| 52 | + |
| 53 | + const byId = new Map(labelPresence.map((a) => [a.sdtId, a.hasLabel])); |
| 54 | + for (const id of HIDDEN_IDS) expect(byId.get(id)).toBe(false); |
| 55 | + for (const id of VISIBLE_IDS) expect(byId.get(id)).toBe(true); |
| 56 | + }); |
| 57 | + |
| 58 | + test('hidden wrappers omit the alias canary from textContent', async ({ superdoc }) => { |
| 59 | + const textByIdRaw = await superdoc.page.evaluate((sel) => { |
| 60 | + return Array.from(document.querySelectorAll(sel)).map((el) => ({ |
| 61 | + sdtId: (el as HTMLElement).dataset.sdtId ?? null, |
| 62 | + text: el.textContent ?? '', |
| 63 | + })); |
| 64 | + }, INLINE_SDT); |
| 65 | + const textById = new Map(textByIdRaw.map((a) => [a.sdtId, a.text])); |
| 66 | + |
| 67 | + expect(textById.get('1001')).toBe('Alpha Corp v. SEC'); |
| 68 | + expect(textById.get('1004')).toBe('first hidden span'); |
| 69 | + expect(textById.get('1005')).toBe('second hidden span'); |
| 70 | + |
| 71 | + // Visible wrappers still surface the alias as a label — that's the |
| 72 | + // pre-existing boundingBox/default behavior. |
| 73 | + expect(textById.get('1002')).toContain('VISIBLE_ALIAS_FOR_COMPARISON'); |
| 74 | + expect(textById.get('1003')).toContain('DEFAULT_APPEARANCE_ALIAS'); |
| 75 | + }); |
| 76 | + |
| 77 | + test('no hidden-SDT alias canary appears anywhere in the painted layout', async ({ superdoc }) => { |
| 78 | + const layoutText = await superdoc.page.evaluate(() => { |
| 79 | + // .presentation-editor__pages is the painter-dom root; selection, |
| 80 | + // copy, and visual reads operate on it. |
| 81 | + const root = |
| 82 | + document.querySelector('.presentation-editor__pages') ?? |
| 83 | + document.querySelector('.superdoc-layout'); |
| 84 | + return root?.textContent ?? ''; |
| 85 | + }); |
| 86 | + |
| 87 | + for (const canary of HIDDEN_ALIAS_CANARIES) { |
| 88 | + expect(layoutText).not.toContain(canary); |
| 89 | + } |
| 90 | + }); |
| 91 | + |
| 92 | + test('hovering a hidden wrapper does not paint the lock-hover background or boost z-index', async ({ superdoc }) => { |
| 93 | + // Regression guard for the CSS specificity bug caught in PR review: |
| 94 | + // the lock-hover rule |
| 95 | + // .superdoc-structured-content-inline[data-lock-mode]:hover:not(.ProseMirror-selectednode) |
| 96 | + // has (0,4,0) specificity vs (0,3,0) for the hidden-appearance hover |
| 97 | + // rule, so without an explicit :not([data-appearance='hidden']) it |
| 98 | + // re-introduces the lock-hover blue background + z-index 9999999 on |
| 99 | + // hover, contradicting "visually transparent". |
| 100 | + // Painter may emit more than one wrapper for the same SDT when the run |
| 101 | + // is split across lines/fragments — each fragment carries the same |
| 102 | + // data-sdt-id. Scope to the painter class and take `.first()`: the |
| 103 | + // CSS specificity bug is per-element, so a single wrapper is enough. |
| 104 | + const wrapper = superdoc.page |
| 105 | + .locator('.superdoc-structured-content-inline[data-sdt-id="1001"]') |
| 106 | + .first(); |
| 107 | + await wrapper.hover(); |
| 108 | + await superdoc.waitForStable(); |
| 109 | + |
| 110 | + const styles = await wrapper.evaluate((el) => { |
| 111 | + const cs = getComputedStyle(el); |
| 112 | + return { backgroundColor: cs.backgroundColor, zIndex: cs.zIndex }; |
| 113 | + }); |
| 114 | + |
| 115 | + // Default backgrounds on most browsers are transparent / rgba(0, 0, 0, 0); |
| 116 | + // the regression value is rgba(98, 155, 231, 0.08). |
| 117 | + expect(styles.backgroundColor).not.toContain('98, 155, 231'); |
| 118 | + // The lock-hover rule sets z-index 9999999 on top of any default — if |
| 119 | + // it slipped through, the hidden wrapper would jump above siblings. |
| 120 | + expect(styles.zIndex).not.toBe('9999999'); |
| 121 | + }); |
| 122 | + |
| 123 | + test('selecting a hidden wrapper copies only the wrapped phrase', async ({ superdoc }) => { |
| 124 | + const selectionText = await superdoc.page.evaluate(() => { |
| 125 | + const wrapper = document.querySelector('[data-sdt-id="1001"]'); |
| 126 | + if (!wrapper) return null; |
| 127 | + const range = document.createRange(); |
| 128 | + range.selectNodeContents(wrapper); |
| 129 | + const sel = window.getSelection(); |
| 130 | + sel?.removeAllRanges(); |
| 131 | + sel?.addRange(range); |
| 132 | + return sel?.toString() ?? null; |
| 133 | + }); |
| 134 | + |
| 135 | + expect(selectionText).toBe('Alpha Corp v. SEC'); |
| 136 | + expect(selectionText).not.toContain('HIDDEN_ALIAS_LEAK_CANARY'); |
| 137 | + }); |
| 138 | +}); |
0 commit comments