1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
package org.terst.feedreader.data
import org.junit.Assert.assertEquals
import org.junit.Test
class SettingsTest {
@Test
fun `pinch zoom with scale factor of 1 leaves the font size unchanged`() {
assertEquals(18, pinchZoomFontSizePx(18, 1.0f))
}
@Test
fun `pinching out scales the font size up, rounded to the nearest pixel`() {
assertEquals(22, pinchZoomFontSizePx(20, 1.1f))
}
@Test
fun `pinching in scales the font size down, rounded to the nearest pixel`() {
assertEquals(16, pinchZoomFontSizePx(20, 0.8f))
}
@Test
fun `pinch zoom result is clamped to the minimum reader font size`() {
assertEquals(READER_FONT_SIZE_RANGE_PX.first, pinchZoomFontSizePx(14, 0.3f))
}
@Test
fun `pinch zoom result is clamped to the maximum reader font size`() {
assertEquals(READER_FONT_SIZE_RANGE_PX.last, pinchZoomFontSizePx(28, 3.0f))
}
@Test
fun `text already laid out at the wanted size needs no zoom`() {
assertEquals(UNZOOMED_TEXT_ZOOM_PERCENT, readerTextZoomPercent(renderedPx = 18, targetPx = 18))
}
@Test
fun `a bigger wanted size lifts the text zoom proportionally`() {
assertEquals(156, readerTextZoomPercent(renderedPx = 18, targetPx = 28))
}
@Test
fun `a smaller wanted size drops the text zoom proportionally`() {
assertEquals(78, readerTextZoomPercent(renderedPx = 18, targetPx = 14))
}
@Test
fun `text zoom is measured against the size the page is laid out at, not the saved size`() {
// Pinch, release, pinch again before the reload at the new size has landed: the page is
// still laid out at 18px even though 22px is the saved size, so going on to 24px has to
// be 24/18 -- measuring it against the saved 22px would visibly shrink the text first.
assertEquals(133, readerTextZoomPercent(renderedPx = 18, targetPx = 24))
}
}
|