|
| 1 | +import { test, expect } from '../../fixtures/superdoc.js'; |
| 2 | +import { createOrderedList, LIST_MARKER_SELECTOR } from '../../helpers/lists.js'; |
| 3 | + |
| 4 | +test.use({ config: { toolbar: 'full' } }); |
| 5 | + |
| 6 | +/** |
| 7 | + * Helper: select all text in the document and change font via toolbar. |
| 8 | + */ |
| 9 | +async function selectAllAndChangeFont( |
| 10 | + superdoc: Parameters<Parameters<typeof test>[2]>[0]['superdoc'], |
| 11 | + fontName: string, |
| 12 | +) { |
| 13 | + await superdoc.selectAll(); |
| 14 | + await superdoc.waitForStable(); |
| 15 | + |
| 16 | + // Open font family dropdown and pick the font |
| 17 | + await superdoc.page.locator('[data-item="btn-fontFamily"]').click(); |
| 18 | + await superdoc.page.locator('[data-item="btn-fontFamily-option"]').filter({ hasText: fontName }).click(); |
| 19 | + await superdoc.waitForStable(); |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * Helper: get the computed font-family of a list marker by line index. |
| 24 | + * DomPainter renders markers as .superdoc-paragraph-marker — CSS is the |
| 25 | + * authoritative source for visual font since the layout engine sets it. |
| 26 | + */ |
| 27 | +async function getMarkerFontFamily( |
| 28 | + superdoc: Parameters<Parameters<typeof test>[2]>[0]['superdoc'], |
| 29 | + markerIndex: number, |
| 30 | +): Promise<string> { |
| 31 | + return superdoc.page.evaluate((idx) => { |
| 32 | + const markers = document.querySelectorAll('.superdoc-paragraph-marker'); |
| 33 | + const marker = markers[idx]; |
| 34 | + if (!marker) throw new Error(`Marker at index ${idx} not found`); |
| 35 | + return getComputedStyle(marker).fontFamily; |
| 36 | + }, markerIndex); |
| 37 | +} |
| 38 | + |
| 39 | +test('new list item marker inherits font from previous paragraph', async ({ superdoc }) => { |
| 40 | + // Create a 2-item ordered list and change font to Georgia |
| 41 | + await createOrderedList(superdoc, ['first item', 'second item']); |
| 42 | + await superdoc.waitForStable(); |
| 43 | + await selectAllAndChangeFont(superdoc, 'Georgia'); |
| 44 | + |
| 45 | + // Verify markers are in Georgia |
| 46 | + const markerFontBefore = await getMarkerFontFamily(superdoc, 0); |
| 47 | + expect(markerFontBefore.toLowerCase()).toContain('georgia'); |
| 48 | + |
| 49 | + // Place cursor at end of last item and press Enter to create a new empty item |
| 50 | + const pos = await superdoc.findTextPos('second item'); |
| 51 | + await superdoc.setTextSelection(pos + 'second item'.length); |
| 52 | + await superdoc.waitForStable(); |
| 53 | + await superdoc.newLine(); |
| 54 | + await superdoc.waitForStable(); |
| 55 | + |
| 56 | + // Should now have 3 markers |
| 57 | + const markerCount = await superdoc.page.locator(LIST_MARKER_SELECTOR).count(); |
| 58 | + expect(markerCount).toBe(3); |
| 59 | + |
| 60 | + // The new (third) marker should inherit Georgia, not fall back to default |
| 61 | + const newMarkerFont = await getMarkerFontFamily(superdoc, 2); |
| 62 | + expect(newMarkerFont.toLowerCase()).toContain('georgia'); |
| 63 | +}); |
0 commit comments