Skip to content

Commit eaba3ba

Browse files
test(behavior): cover formatted footer page fields
1 parent 000d792 commit eaba3ba

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

tests/behavior/helpers/story-fixtures.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,32 @@ function lowercasePageFieldFooterXml(): string {
498498
`;
499499
}
500500

501+
function formattedPageFieldFooterXml(): string {
502+
const pageField = (instruction: string, cachedText: string) => `
503+
<w:r><w:fldChar w:fldCharType="begin"/></w:r>
504+
<w:r><w:instrText xml:space="preserve">${instruction}</w:instrText></w:r>
505+
<w:r><w:fldChar w:fldCharType="separate"/></w:r>
506+
<w:r><w:t>${cachedText}</w:t></w:r>
507+
<w:r><w:fldChar w:fldCharType="end"/></w:r>`;
508+
509+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
510+
<w:ftr xmlns:w="${NS_W}" xmlns:r="${NS_R}">
511+
<w:p>
512+
<w:pPr>
513+
<w:pStyle w:val="Footer"/>
514+
<w:jc w:val="center"/>
515+
</w:pPr>
516+
<w:r><w:t xml:space="preserve">Formats </w:t></w:r>
517+
${pageField('PAGE \\* Roman', 'I')}
518+
<w:r><w:t xml:space="preserve"> </w:t></w:r>
519+
${pageField('PAGE \\* ALPHABETIC', 'A')}
520+
<w:r><w:t xml:space="preserve"> </w:t></w:r>
521+
${pageField('PAGE \\* ArabicDash', '- 1 -')}
522+
</w:p>
523+
</w:ftr>
524+
`;
525+
}
526+
501527
function inlinePageFieldSingleRunFooterXml(): string {
502528
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
503529
<w:ftr xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="${NS_R}" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w="${NS_W}" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 wp14">
@@ -658,6 +684,14 @@ export const FOOTER_LOWERCASE_PAGE_FIELD_DOC_PATH = ensureGeneratedFixture(
658684
'word/footer2.xml': lowercasePageFieldFooterXml(),
659685
},
660686
);
687+
export const FOOTER_FORMATTED_PAGE_FIELD_DOC_PATH = ensureGeneratedFixture(
688+
'footer-formatted-page-field.docx',
689+
'h_f-normal.docx',
690+
{
691+
'word/document.xml': multiPageHeaderFooterDocumentXml(),
692+
'word/footer2.xml': formattedPageFieldFooterXml(),
693+
},
694+
);
661695
export const FOOTER_SIMPLE_TEXT_WITH_TABLE_AND_FOOTNOTE_DOC_PATH = ensureGeneratedFixture(
662696
'footer-simple-text-with-table-and-footnote.docx',
663697
'h_f-normal.docx',

tests/behavior/tests/field-annotations/footer-page-keyword-case.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { test, expect } from '../../fixtures/superdoc.js';
2-
import { FOOTER_LOWERCASE_PAGE_FIELD_DOC_PATH } from '../../helpers/story-fixtures.js';
2+
import {
3+
FOOTER_FORMATTED_PAGE_FIELD_DOC_PATH,
4+
FOOTER_LOWERCASE_PAGE_FIELD_DOC_PATH,
5+
} from '../../helpers/story-fixtures.js';
36

47
test('lowercase PAGE field in repeated footer resolves per page instead of using cached text', async ({ superdoc }) => {
58
await superdoc.loadDocument(FOOTER_LOWERCASE_PAGE_FIELD_DOC_PATH);
@@ -14,3 +17,17 @@ test('lowercase PAGE field in repeated footer resolves per page instead of using
1417
await expect(secondPageFooter).toContainText(/Case footer\s*2/);
1518
await expect(secondPageFooter).not.toContainText(/Case footer\s*1/);
1619
});
20+
21+
test('formatted PAGE fields in repeated footer resolve per page', async ({ superdoc }) => {
22+
await superdoc.loadDocument(FOOTER_FORMATTED_PAGE_FIELD_DOC_PATH);
23+
await superdoc.waitForStable();
24+
25+
await expect.poll(() => superdoc.page.locator('.superdoc-page-footer').count()).toBeGreaterThanOrEqual(2);
26+
27+
const secondPageFooter = superdoc.page.locator('.superdoc-page-footer').nth(1);
28+
await secondPageFooter.scrollIntoViewIfNeeded();
29+
await secondPageFooter.waitFor({ state: 'visible', timeout: 15_000 });
30+
31+
await expect(secondPageFooter).toContainText(/Formats\s*II\s*B\s*-\s*2\s*-/);
32+
await expect(secondPageFooter).not.toContainText(/Formats\s*I\s*A\s*-\s*1\s*-/);
33+
});

0 commit comments

Comments
 (0)