package org.terst.feedreader.ui import org.junit.Assert.assertTrue import org.junit.Test /** * The reader's end of maths rendering. * * Extraction converts a page's TeX source to MathML (see ReaderExtractor), which the * WebView renders natively -- no script, no webfont, no stylesheet of KaTeX's. Two things * still have to be true of the reader HTML itself: the MathML has to reach the WebView * intact (the wrapping passes rewrite iframes and images, and must not touch it), and a * wide equation must not be able to drag the whole article into horizontal scrolling -- * an aligned multi-line derivation is routinely wider than a phone screen, and `math` * does not obey the `img`/`svg` clamps already in the stylesheet. */ class ReaderMathTest { private val displayMath = "" @Test fun `mathml reaches the webview unchanged`() { val html = wrapReaderHtml("
A slice of the set:
$displayMathand so on.
") assertTrue("MathML must survive the reader's HTML assembly verbatim", html.contains(displayMath)) } @Test fun `a wide equation scrolls inside itself instead of scrolling the article`() { val html = wrapReaderHtml("x
$displayMath") val style = html.substringAfter("") val displayMathRule = style.lines() .joinToString(" ") .substringAfter("math[display=\"block\"]", "") .substringBefore("}") assertTrue( "the stylesheet needs a math[display=\"block\"] rule, found none in:\n$style", displayMathRule.isNotBlank() ) assertTrue( "display maths must scroll within its own box, got: $displayMathRule", displayMathRule.contains("overflow-x: auto") ) } }