test: add unit test for display of font size
This commit is contained in:
1 parent
56f884a412
commit
f4973caade
3 files changed
+54
-19
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import { HEADING_STYLE_OVERRIDES } from '../export/odt';
|
||||
|
||||
// The size a block renders its unmarked text at — what the toolbar's size box must show.
|
||||
// Keep in sync with editor.css (tests/unit/font-size-display.test.ts asserts it).
|
||||
|
||||
export const DEFAULT_FONT_SIZE = '12pt';
|
||||
|
||||
export const HEADING_SIZES: Record<number, string> =
|
||||
Object.fromEntries(HEADING_STYLE_OVERRIDES.map((h, i) => [i + 1, h.fontSize]));
|
||||
|
||||
export type SizedBlock = { type: { name: string }; attrs?: Record<string, unknown> } | null;
|
||||
|
||||
// Paragraph-mark size (blockFontSize attr) wins, else the heading/body default.
|
||||
export function blockFontSize(block: SizedBlock): string {
|
||||
const explicit = block?.attrs?.fontSize;
|
||||
if (typeof explicit === 'string' && explicit) return explicit;
|
||||
if (block?.type.name === 'heading') return HEADING_SIZES[Number(block.attrs?.level)] ?? DEFAULT_FONT_SIZE;
|
||||
return DEFAULT_FONT_SIZE;
|
||||
}
|
||||
Reference in new issue
Block a user