-
Notifications
You must be signed in to change notification settings - Fork 177
test(fonts): font availability + curation behavior matrix (SD-3441) #3733
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
95ec065
test(fonts): npm font availability + curation behavior specs (SD-3441)
caio-pizzol 4d6281b
test(fonts): no-pack document preserves font names without substituti…
caio-pizzol fa296aa
test(fonts): @superdoc-dev/fonts package import smoke test (SD-3441)
caio-pizzol 6a19d5e
fix(test): serve the bundled-font harness at /bundled-fonts/, not /fo…
caio-pizzol 5496c8e
test(fonts): sync pack assets in the harness webServer startup (SD-3441)
caio-pizzol 60b779c
test(font-system): assert the conflicting-config warning text, not ju…
caio-pizzol 225fb3a
test(fonts): broken-base advertising + no-pack programmatic apply (SD…
caio-pizzol d612a0e
test(fonts): custom-font render-vs-selectable split (SD-3441)
caio-pizzol d3b5efc
test(fonts): tighten the broken-base spec comment (SD-3441)
caio-pizzol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { test, expect, type SuperDocFixture } from '../../fixtures/superdoc.js'; | ||
|
|
||
| // Custom (consumer-licensed) fonts, split along the contract that surprises people: | ||
| // - fonts.families REGISTERS a face so it RENDERS when the document uses it - but registration alone | ||
| // does NOT add a toolbar option. | ||
| // - A custom family becomes SELECTABLE only when the consumer lists it in modules.toolbar.fonts (or | ||
| // the document already uses it, which surfaces it as a document font). | ||
| // The harness registers "Brand Sans" from a real served woff2 under a distinct name (see the `custom` | ||
| // modes in harness/main.ts). | ||
|
|
||
| const FONT_TOGGLE = '[data-item="btn-fontFamily-toggle"]'; | ||
| const FONT_OPTION = '[data-item="btn-fontFamily-option"]'; | ||
| const OPTION_LABEL = `${FONT_OPTION} .toolbar-dropdown-option__label`; | ||
|
|
||
| async function fontOptionLabels(superdoc: SuperDocFixture): Promise<string[]> { | ||
| await superdoc.page.locator(FONT_TOGGLE).click(); | ||
| await superdoc.page.locator(FONT_OPTION).first().waitFor({ state: 'visible', timeout: 5000 }); | ||
| await superdoc.waitForStable(); | ||
| return (await superdoc.page.locator(OPTION_LABEL).allInnerTexts()).map((label) => label.trim()); | ||
| } | ||
|
|
||
| test.describe('npm + custom font registered via fonts.families', () => { | ||
| test.use({ config: { toolbar: 'full', fonts: 'custom' } }); | ||
|
|
||
| test('renders when applied but is NOT a toolbar option from registration alone', async ({ superdoc }) => { | ||
| const woff2: Array<{ url: string; status: number }> = []; | ||
| superdoc.page.on('response', (res) => { | ||
| if (/\.woff2(\?|$)/.test(res.url())) woff2.push({ url: res.url(), status: res.status() }); | ||
| }); | ||
|
|
||
| // Registration alone does not add a toolbar row: the dropdown is the no-pack baseline only. | ||
| expect(await fontOptionLabels(superdoc)).not.toContain('Brand Sans'); | ||
| await superdoc.page.keyboard.press('Escape'); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| // It still RENDERS when the document uses it: apply it programmatically, and its registered face | ||
| // loads over the wire. | ||
| await superdoc.type('Brand Sans sample'); | ||
| await superdoc.waitForStable(); | ||
| const pos = await superdoc.findTextPos('Brand Sans sample'); | ||
| await superdoc.setTextSelection(pos, pos + 'Brand Sans sample'.length); | ||
| await superdoc.waitForStable(); | ||
| await superdoc.page.evaluate(() => { | ||
| ( | ||
| window as unknown as { editor: { commands: { setFontFamily: (f: string) => void } } } | ||
| ).editor.commands.setFontFamily('Brand Sans'); | ||
| }); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| await superdoc.assertTextMarkAttrs('Brand Sans sample', 'textStyle', { fontFamily: 'Brand Sans' }); | ||
| await expect.poll(() => woff2.filter((r) => r.status === 200).length, { timeout: 10_000 }).toBeGreaterThan(0); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('npm + custom font listed in modules.toolbar.fonts', () => { | ||
| test.use({ config: { toolbar: 'full', fonts: 'custom-toolbar' } }); | ||
|
|
||
| test('is selectable because the consumer provided the toolbar list', async ({ superdoc }) => { | ||
| await superdoc.type('Toolbar custom sample'); | ||
| await superdoc.waitForStable(); | ||
| const pos = await superdoc.findTextPos('Toolbar custom sample'); | ||
| await superdoc.setTextSelection(pos, pos + 'Toolbar custom sample'.length); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| // A consumer-provided fonts list replaces the built-in one entirely, so Brand Sans appears and is | ||
| // selectable. Open the dropdown once, assert it's there, then pick it. | ||
| const labels = await fontOptionLabels(superdoc); | ||
| expect(labels).toContain('Brand Sans'); | ||
| await superdoc.page | ||
| .locator(FONT_OPTION) | ||
| .filter({ has: superdoc.page.getByText('Brand Sans', { exact: true }) }) | ||
| .click(); | ||
| await superdoc.waitForStable(); | ||
| await superdoc.page | ||
| .locator('.presentation-editor__viewport') | ||
| .first() | ||
| .click({ position: { x: 50, y: 50 } }); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| await superdoc.assertTextMarkAttrs('Toolbar custom sample', 'textStyle', { fontFamily: 'Brand Sans' }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { test, expect, type SuperDocFixture } from '../../fixtures/superdoc.js'; | ||
|
|
||
| // A document that USES bundled fonts, with no pack configured. The point: SuperDoc preserves the | ||
| // document's font names (they show in the toolbar as document fonts) but must NOT activate a bundled | ||
| // substitute for them - no `.woff2` is fetched. This is the regression the 1.40 rollback was about: | ||
| // advertising/serving a substitute the app never configured. | ||
|
|
||
| const HERE = path.dirname(fileURLToPath(import.meta.url)); | ||
| const CALIBRI_DOC = path.resolve(HERE, 'fixtures/calibri.docx'); // runs in Arial + Calibri | ||
|
|
||
| const FONT_TOGGLE = '[data-item="btn-fontFamily-toggle"]'; | ||
| const FONT_OPTION = '[data-item="btn-fontFamily-option"]'; | ||
| const OPTION_LABEL = `${FONT_OPTION} .toolbar-dropdown-option__label`; | ||
|
|
||
| async function fontOptionLabels(superdoc: SuperDocFixture): Promise<string[]> { | ||
| await superdoc.page.locator(FONT_TOGGLE).click(); | ||
| await superdoc.page.locator(FONT_OPTION).first().waitFor({ state: 'visible', timeout: 5000 }); | ||
| await superdoc.waitForStable(); | ||
| return (await superdoc.page.locator(OPTION_LABEL).allInnerTexts()).map((label) => label.trim()); | ||
| } | ||
|
|
||
| test.describe('npm, no pack: a document that uses bundled fonts', () => { | ||
| test.use({ config: { toolbar: 'full', fonts: 'no-pack' } }); | ||
|
|
||
| test('preserves the document font name without fetching a bundled substitute', async ({ superdoc }) => { | ||
| // No pack means no bundled substitution at all, so assert NO `.woff2` is fetched from any base. | ||
| const fontRequests: string[] = []; | ||
| superdoc.page.on('request', (req) => { | ||
| if (/\.woff2(\?|$)/.test(req.url())) fontRequests.push(req.url()); | ||
| }); | ||
|
|
||
| await superdoc.loadDocument(CALIBRI_DOC); | ||
| await superdoc.waitForStable(); | ||
|
|
||
| // Rendering a Calibri document with no pack must not fetch a substitute face. | ||
| expect(fontRequests).toEqual([]); | ||
|
|
||
| // The Calibri run keeps its logical Word name (no substitution baked in). | ||
| await superdoc.assertTextMarkAttrs('Hamburgefonts', 'textStyle', { fontFamily: 'Calibri' }); | ||
|
|
||
| // The document's font still appears in the toolbar - document fonts are advertised even with no | ||
| // pack - so the user can re-apply it; it simply renders with the system font, not a substitute. | ||
| expect(await fontOptionLabels(superdoc)).toContain('Calibri'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.