Skip to content

Commit c917d14

Browse files
content [test]: Add golden tests for KaTeX content
1 parent ec14306 commit c917d14

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

test/widgets/content_test.dart

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,43 @@ void main() {
729729
});
730730
}
731731
});
732+
733+
testWidgets('golden tests', (tester) async {
734+
await _loadKatexFonts();
735+
736+
addTearDown(testBinding.reset);
737+
final globalSettings = testBinding.globalStore.settings;
738+
await globalSettings.setBool(BoolGlobalSetting.renderKatex, true);
739+
check(globalSettings).getBool(BoolGlobalSetting.renderKatex).isTrue();
740+
741+
final contentHtml =
742+
ContentExample.mathBlockKatexSizing.html +
743+
ContentExample.mathBlockKatexNestedSizing.html +
744+
ContentExample.mathBlockKatexDelimSizing.html +
745+
ContentExample.mathBlockKatexVertical1.html +
746+
ContentExample.mathBlockKatexVertical2.html +
747+
ContentExample.mathBlockKatexVertical3.html +
748+
ContentExample.mathBlockKatexVertical4.html +
749+
ContentExample.mathBlockKatexVertical5.html;
750+
751+
await prepareContent(tester, Builder(builder: (context) =>
752+
DefaultTextStyle(
753+
style: ContentTheme.of(context).textStylePlainParagraph,
754+
child: BlockContentList(
755+
nodes: parseContent(contentHtml).nodes.map((node) {
756+
final mathBlockNode = node as MathBlockNode;
757+
return ParagraphNode(
758+
links: null,
759+
nodes: [
760+
MathInlineNode(
761+
texSource: mathBlockNode.texSource,
762+
nodes: mathBlockNode.nodes),
763+
]);
764+
}).toList(growable: false)))));
765+
766+
await check(find.byType(BlockContentList))
767+
.matchesGoldenFile(Uri.file('goldens/katex.png'));
768+
});
732769
});
733770

734771
/// Make a [TargetFontSizeFinder] to pass to [checkFontSizeRatio],
@@ -1492,4 +1529,4 @@ Future<void> _loadKatexFonts() async {
14921529
Future.value(fontFile.readAsBytesSync().buffer.asByteData());
14931530
await (FontLoader(fontName)..addFont(bytes)).load();
14941531
}
1495-
}
1532+
}

test/widgets/goldens/katex.png

11.3 KB
Loading

0 commit comments

Comments
 (0)