diff --git a/devtools/visual-testing/packages/test-helpers/package.json b/devtools/visual-testing/packages/test-helpers/package.json index 08e96ef86..4f6273ade 100644 --- a/devtools/visual-testing/packages/test-helpers/package.json +++ b/devtools/visual-testing/packages/test-helpers/package.json @@ -22,5 +22,8 @@ }, "devDependencies": { "eslint_d": "^14.3.0" + }, + "dependencies": { + "@superdoc-testing/harness": "workspace:*" } } diff --git a/devtools/visual-testing/tests/interactions/stories/formatting/apply-font.ts b/devtools/visual-testing/tests/interactions/stories/formatting/apply-font.ts new file mode 100644 index 000000000..b210b450f --- /dev/null +++ b/devtools/visual-testing/tests/interactions/stories/formatting/apply-font.ts @@ -0,0 +1,28 @@ +import { defineStory } from '@superdoc-testing/helpers'; + +const WAIT_MS = 300; +const START_DOC = 'other/sd-1778-apply-font.docx'; +const FONT_NAME = 'Courier New'; + +export default defineStory({ + name: 'apply-font', + description: 'Select all content and apply the Courier New font.', + tickets: ['SD-1778'], + startDocument: START_DOC, + layout: true, + toolbar: 'full', + waitForFonts: true, + + async run(_, helpers): Promise { + const { selectAll, focus, executeCommand, waitForStable, milestone } = helpers; + await waitForStable(WAIT_MS); + await focus(); + + await selectAll(); + + await waitForStable(WAIT_MS); + await executeCommand('setFontFamily', FONT_NAME); + await waitForStable(WAIT_MS); + await milestone('font-applied', `Applied ${FONT_NAME} to document.`); + }, +}); diff --git a/packages/super-editor/src/extensions/run/calculateInlineRunPropertiesPlugin.test.js b/packages/super-editor/src/extensions/run/calculateInlineRunPropertiesPlugin.test.js index c613edaf3..24a444090 100644 --- a/packages/super-editor/src/extensions/run/calculateInlineRunPropertiesPlugin.test.js +++ b/packages/super-editor/src/extensions/run/calculateInlineRunPropertiesPlugin.test.js @@ -53,6 +53,11 @@ const makeSchema = () => instruction: { default: null }, }, }, + bookmarkStart: { + inline: true, + group: 'inline', + content: 'inline*', + }, text: { group: 'inline' }, }, marks: { @@ -210,6 +215,25 @@ describe('calculateInlineRunPropertiesPlugin', () => { expect(paragraph.attrs.paragraphProperties).toEqual({ runProperties: { bold: true } }); }); + it('treats the first run inside inline wrappers as the paragraph first run', () => { + const schema = makeSchema(); + const doc = schema.node('doc', null, [ + schema.node('paragraph', null, [ + schema.node('bookmarkStart', null, [schema.node('run', null, schema.text('Wrapped'))]), + ]), + ]); + const state = createState(schema, doc); + const [wrappedRunPos] = runPositions(state.doc); + const from = wrappedRunPos + 1; + const to = wrappedRunPos + 3; + + const tr = state.tr.addMark(from, to, schema.marks.bold.create()); + const { state: nextState } = state.applyTransaction(tr); + + const paragraph = nextState.doc.firstChild; + expect(paragraph.attrs.paragraphProperties).toEqual({ runProperties: { bold: true } }); + }); + it('does not update paragraph runProperties when a non-first run changes', () => { const schema = makeSchema(); const doc = schema.node('doc', null, [