Salah 0.4: center-magnified prayer times and larger clock
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
const assert = require('node:assert/strict')
|
||||
const fs = require('node:fs')
|
||||
const vm = require('node:vm')
|
||||
const src = fs.readFileSync('src/pages/index/index.ux', 'utf8')
|
||||
const body = src.match(/<script>([\s\S]*?)<\/script>/)[1].replace(/import\s+\w+\s+from\s+'[^']*';?/, '').replace('export default', 'globalThis.spec =')
|
||||
const ctx = {prayer: require('../src/common/prayer.js'), setInterval: () => 1, clearInterval: () => {}}
|
||||
vm.createContext(ctx); vm.runInContext(body, ctx)
|
||||
const p = Object.assign({}, ctx.spec, JSON.parse(JSON.stringify(ctx.spec.private)))
|
||||
p.update()
|
||||
assert.equal(typeof p.onScroll, 'function', 'scroll handler drives center magnification')
|
||||
const size = i => parseFloat(p.rows[i].timeStyle.fontSize)
|
||||
p.onScroll({scrollY: 0})
|
||||
assert.equal(size(0), 60, 'first centered prayer gets 60px time')
|
||||
assert.ok(size(1) < size(0))
|
||||
p.onScroll({scrollY: 104})
|
||||
assert.equal(size(1), 60)
|
||||
assert.equal(size(0), size(2), 'symmetric shrink around center')
|
||||
p.onScroll({scrollY: 52})
|
||||
assert.equal(size(0), size(1), 'continuous interpolation between rows')
|
||||
assert.ok(size(0) > 30 && size(0) < 60)
|
||||
p.onScroll({scrollY: 520})
|
||||
assert.equal(size(5), 60, 'last prayer can be magnified')
|
||||
p.update()
|
||||
assert.equal(size(5), 60, 'clock refresh preserves scroll focus')
|
||||
for (const offset of [-100, 9999]) {
|
||||
p.onScroll({scrollY: offset})
|
||||
p.rows.forEach(row => assert.ok(parseFloat(row.timeStyle.fontSize) >= 30 && parseFloat(row.timeStyle.fontSize) <= 60))
|
||||
}
|
||||
const before = JSON.stringify(p.rows)
|
||||
for (const event of [undefined, {}, {scrollY: NaN}, {scrollY: Infinity}]) p.onScroll(event)
|
||||
assert.equal(JSON.stringify(p.rows), before, 'invalid events do not corrupt styles')
|
||||
assert.ok(!src.includes('SWIPE TO SCROLL'))
|
||||
assert.match(src, /onscroll="onScroll"/)
|
||||
assert.match(src, /style="\{\{ row.timeStyle \}\}"/)
|
||||
assert.match(src, /style="\{\{ row.nameStyle \}\}"/)
|
||||
function css(c,k) { return parseFloat(src.match(new RegExp('\\.'+c+'\\s*\\{([^}]+)'))[1].match(new RegExp(k+':\\s*([^;]+)'))[1]) }
|
||||
assert.equal(css('prayers','top') + css('prayers','height') / 2, 233, 'magnification center is physical screen center')
|
||||
assert.equal(css('row','height'), 104, 'fixed row geometry prevents scroll feedback')
|
||||
assert.ok(css('clock','font-size') > 42, 'header clock enlarged too')
|
||||
console.log('Center magnification, interpolation, end rows, refresh preservation, invalid events and wiring passed')
|
||||
Reference in New Issue
Block a user