forked from Blendman974/faceclaw
Fix issue that caused broken Nightscout widget on the status bar on iOS
This commit is contained in:
1 parent
6df52021c8
commit
32fa5c0e6e
4 files changed
+56
-7
No files matched your search
@@ -0,0 +1,23 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { GrayImage } = require('../.test-build/app/graphics/image.js');
|
||||
|
||||
test('a non-integer size rounds up, warns, and leaves every pixel addressable', t => {
|
||||
const warn = t.mock.method(console, 'warn', () => {});
|
||||
const image = new GrayImage(78.625, 23.5, 7);
|
||||
assert.deepEqual([image.width, image.height, image.pixels.length], [79, 24, 79 * 24]);
|
||||
assert.ok(image.pixels.every(value => value === 7));
|
||||
for (let y = 0; y < image.height; y++) {
|
||||
image.setPixel(78, y, 200);
|
||||
assert.equal(image.getPixel(78, y), 200, `row ${y}`);
|
||||
}
|
||||
assert.equal(warn.mock.callCount(), 1);
|
||||
assert.match(warn.mock.calls[0].arguments[0], /78\.625x23\.5/);
|
||||
});
|
||||
|
||||
test('a whole-number size is kept as given, without a warning', t => {
|
||||
const warn = t.mock.method(console, 'warn', () => {});
|
||||
const image = new GrayImage(79, 24);
|
||||
assert.deepEqual([image.width, image.height], [79, 24]);
|
||||
assert.equal(warn.mock.callCount(), 0);
|
||||
});
|
||||
@@ -125,14 +125,14 @@ test('overflow warning backgrounds cover graph pixels and deferred graph labels'
|
||||
assert.equal(baked.getPixel(200, 8), 56, 'uncovered graph remains visible');
|
||||
});
|
||||
|
||||
function fixture(always = false) {
|
||||
function fixture(always = false, GrayImage = Image, uiFont = font) {
|
||||
let time = now, icon, tick, changed, notify, renders = 0;
|
||||
const state = { ...healthy, available: true, latest: { sgv: 100, timestampMs: now }, history: [], units: 'mg/dL', delta: 0, direction: '', iob: 1, cob: 0, pumpStatus: '0m ago', configurationMissing: false };
|
||||
const bridge = { snapshot: () => state, onStateChange(fn) { notify = fn; fn(state); } };
|
||||
const settings = { loadNightscoutThresholds: () => limits, nightscoutAlwaysShowInTopBarSetting: { get: () => always }, onAnySettingChanged(fn) { changed = fn; }, isNightscoutSettingsConfigured: () => true };
|
||||
const deps = {
|
||||
'../../graphics/image': { GrayImage: Image },
|
||||
'../../graphics/ui-fonts': { getDefaultSmallFont: () => font, getDefaultLargeFont: () => font },
|
||||
'../../graphics/image': { GrayImage },
|
||||
'../../graphics/ui-fonts': { getDefaultSmallFont: () => uiFont, getDefaultLargeFont: () => uiFont },
|
||||
'../../native/nightscout-bridge': { nightscoutBridge: bridge },
|
||||
'../../ui/dashboard-settings': settings,
|
||||
'./nightscout-alerts': alerts,
|
||||
@@ -181,6 +181,22 @@ test('tray is hidden by default and clears recovered measurement warnings immedi
|
||||
second.close(); assert.equal(f.icon(), null);
|
||||
});
|
||||
|
||||
test('tray keeps every pixel row when a TTF font measures the reading fractionally', () => {
|
||||
const { GrayImage } = require('../.test-build/app/graphics/image.js');
|
||||
// 8.875 is Roboto-Light 16's digit advance under iOS Core Text.
|
||||
const f = fixture(true, GrayImage, { ...font, measureText: text => text.length * 8.875, drawText() {} });
|
||||
f.state.latest = { sgv: 142, timestampMs: now };
|
||||
// Spans the graph's full 60..200 range, so its line crosses every row.
|
||||
f.state.history = [{ timestampMs: now - 10 * 60_000, sgv: 200 }, { timestampMs: now, sgv: 60 }];
|
||||
f.app.startNightscoutTrayIcon();
|
||||
const icon = f.icon();
|
||||
assert.ok(Number.isInteger(icon.width), `width ${icon.width}`);
|
||||
for (let y = 0; y < icon.height; y++) {
|
||||
const row = Array.from({ length: icon.width }, (_, x) => icon.getPixel(x, y));
|
||||
assert.ok(row.some(value => value !== 0), `row ${y} of the graph is drawn`);
|
||||
}
|
||||
});
|
||||
|
||||
test('main page highlights only the breached field and removes highlights on recovery', () => {
|
||||
const f = fixture();
|
||||
const page = load('app/apps/nightscout/nightscout.ts', {
|
||||
|
||||
Reference in new issue
Block a user