diff options
Diffstat (limited to 'app/src/test/java/org/terst/feedreader/ui/ReaderMathTest.kt')
| -rw-r--r-- | app/src/test/java/org/terst/feedreader/ui/ReaderMathTest.kt | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/src/test/java/org/terst/feedreader/ui/ReaderMathTest.kt b/app/src/test/java/org/terst/feedreader/ui/ReaderMathTest.kt new file mode 100644 index 0000000..fea5d22 --- /dev/null +++ b/app/src/test/java/org/terst/feedreader/ui/ReaderMathTest.kt @@ -0,0 +1,46 @@ +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 = + "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><semantics>" + + "<mtable><mtr><mtd><mi>t</mi></mtd></mtr></mtable></semantics></math>" + + @Test + fun `mathml reaches the webview unchanged`() { + val html = wrapReaderHtml("<p>A slice of the set:</p>$displayMath<p>and so on.</p>") + 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("<p>x</p>$displayMath") + val style = html.substringAfter("<style>").substringBefore("</style>") + 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") + ) + } +} |
