| 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { |
| 3 | buildMasterStyleLink, |
| 4 | ensureMasterStyleLink, |
| 5 | hasUniqueMasterStyleLink, |
| 6 | isMasterElementsDisabled, |
| 7 | setMasterElementsDisabled, |
| 8 | setMasterPageNumber |
| 9 | } from '../../../src/main/presentation/html/master-link' |
| 10 | |
| 11 | describe('slide master page link', () => { |
| 12 | it('builds the canonical marked stylesheet link', () => { |
| 13 | expect(buildMasterStyleLink()).toBe( |
| 14 | '<link rel="stylesheet" href="./master/master.css" data-ppt-master="1">' |
| 15 | ) |
| 16 | }) |
| 17 | |
| 18 | it('normalizes marked and canonical duplicate links at the end of head', () => { |
| 19 | const normalized = ensureMasterStyleLink(`<!doctype html> |
| 20 | <html><head> |
| 21 | <link rel="stylesheet" href="master/master.css"> |
| 22 | <style data-ppt-fonts="1">:root { --ppt-body-font: Test; }</style> |
| 23 | <link rel="stylesheet" href="./master/master.css" data-ppt-master="1"> |
| 24 | <style>.page { color: red; }</style> |
| 25 | </head><body>slide</body></html>`) |
| 26 | |
| 27 | expect(hasUniqueMasterStyleLink(normalized)).toBe(true) |
| 28 | expect(normalized.match(/master\.css/g)).toHaveLength(1) |
| 29 | expect(normalized.lastIndexOf('data-ppt-master="1"')).toBeGreaterThan( |
| 30 | normalized.lastIndexOf('.page { color: red; }') |
| 31 | ) |
| 32 | }) |
| 33 | |
| 34 | it('persists page numbers and a page-scoped global-elements override on both shell anchors', () => { |
| 35 | const numbered = setMasterPageNumber( |
| 36 | '<html><head></head><body><main class="ppt-page-root" data-ppt-guard-root="1"></main></body></html>', |
| 37 | 3 |
| 38 | ) |
| 39 | expect(numbered).toContain('data-ppt-page-number="3"') |
| 40 | const disabled = setMasterElementsDisabled(numbered, true) |
| 41 | expect(isMasterElementsDisabled(disabled)).toBe(true) |
| 42 | expect(setMasterElementsDisabled(disabled, false)).not.toContain('data-ppt-master-off') |
| 43 | }) |
| 44 | }) |
| 45 |