forked from Blendman974/faceclaw
Phone UI: Settings are a page instead of a tab, watch vs ring style input is a setting rather than a tab, EvenHub webview is a button with the main buttons rather than in the top bar
This commit is contained in:
1 parent
a02b849200
commit
cd61fefb21
35 files changed
+848
-429
No files matched your search
@@ -3,62 +3,78 @@ const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
function fixture() {
|
||||
let brightness = '40', mode = 'small', picked;
|
||||
const changes = [], writes = [];
|
||||
let style = 'watch';
|
||||
const changes = [], navigations = [];
|
||||
class Observable {
|
||||
notifyPropertyChange(name, value) { changes.push([name, value]); }
|
||||
}
|
||||
const settings = {
|
||||
brightnessSetting: { get: () => brightness, set: value => { brightness = value; writes.push(value); } },
|
||||
displayLayoutSetting: { get: () => mode, set: value => { mode = value; }, values: ['small', 'large', 'huge'],
|
||||
isDisabled: value => value === 'huge', displayValue(value = mode) { return value[0].toUpperCase() + value.slice(1); } },
|
||||
};
|
||||
const { RemoteControlsViewModel } = loader({}, {
|
||||
'@nativescript/core': { Observable, Dialogs: { action: async () => picked } },
|
||||
'../ui/dashboard-settings': settings,
|
||||
'@nativescript/core': { Observable, Frame: { topmost: () => ({ navigate: entry => navigations.push(entry) }) } },
|
||||
'../ui/dashboard-settings': { phoneInputStyleSetting: { get: () => style } },
|
||||
})('app/phone-ui/remote-controls-view-model.ts');
|
||||
return { model: new RemoteControlsViewModel(), create: () => new RemoteControlsViewModel(), changes, writes,
|
||||
brightness: () => brightness, mode: () => mode, pick: value => { picked = value; } };
|
||||
return { model: new RemoteControlsViewModel(), create: () => new RemoteControlsViewModel(), changes, navigations,
|
||||
setStyle: value => { style = value; } };
|
||||
}
|
||||
|
||||
test('shared controls preserve the selected tab across page visits and update all tab bindings', () => {
|
||||
test('the touchpad follows the Phone input style setting and only notifies when it changes', () => {
|
||||
const h = fixture();
|
||||
assert.equal(h.model.watchTabVisibility, 'visible');
|
||||
h.model.onRingTabTap();
|
||||
assert.equal(h.model.watchTabVisibility, 'collapse');
|
||||
assert.equal(h.model.ringTabVisibility, 'visible');
|
||||
assert.match(h.model.ringTabClass, /tab-button-selected/);
|
||||
assert.equal(h.changes.length, 6);
|
||||
assert.equal(h.create().ringTabVisibility, 'visible');
|
||||
h.model.onSettingsTabTap();
|
||||
assert.equal(h.model.settingsTabVisibility, 'visible');
|
||||
assert.equal(h.model.watchPadVisibility, 'visible');
|
||||
assert.equal(h.model.ringPadVisibility, 'collapse');
|
||||
// Some other setting changed: nothing to redraw, no gesture to cancel.
|
||||
h.model.refreshInputStyle();
|
||||
assert.deepEqual(h.changes, []);
|
||||
h.setStyle('ring'); h.model.refreshInputStyle();
|
||||
assert.equal(h.model.watchPadVisibility, 'collapse');
|
||||
assert.equal(h.model.ringPadVisibility, 'visible');
|
||||
assert.deepEqual(h.changes, [['watchPadVisibility', 'collapse'], ['ringPadVisibility', 'visible']]);
|
||||
// A page built later starts on the stored style.
|
||||
assert.equal(h.create().ringPadVisibility, 'visible');
|
||||
});
|
||||
|
||||
test('shared brightness controls snap manual levels and restore the manual value after Auto', () => {
|
||||
const h = fixture();
|
||||
h.model.onBrightnessChange({ value: 76 });
|
||||
assert.equal(h.brightness(), '80');
|
||||
h.model.onBrightnessAutoChange({ value: true });
|
||||
assert.equal(h.brightness(), 'auto');
|
||||
assert.equal(h.model.brightnessSliderEnabled, false);
|
||||
h.model.onBrightnessChange({ value: 10 });
|
||||
assert.equal(h.brightness(), 'auto');
|
||||
h.model.onBrightnessAutoChange({ value: false });
|
||||
assert.equal(h.brightness(), '80');
|
||||
h.model.onBrightnessChange({ value: -10 });
|
||||
assert.equal(h.brightness(), '2');
|
||||
h.model.onBrightnessChange({ value: NaN });
|
||||
assert.equal(h.brightness(), '2');
|
||||
test('the EvenHub phone-UI button shows only with an icon and opens that app through the host', () => {
|
||||
const h = fixture(), opened = [], icon = { id: 'icon' };
|
||||
h.model.showEvenHubPhoneUi = windowId => opened.push(windowId);
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
|
||||
h.model.onEvenHubPhoneUiTap();
|
||||
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon: null };
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
|
||||
h.model.onEvenHubPhoneUiTap();
|
||||
assert.deepEqual(opened, [], 'a hidden button opens nothing');
|
||||
|
||||
h.changes.length = 0;
|
||||
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon };
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'visible');
|
||||
assert.equal(h.model.evenHubPhoneUiIcon, icon);
|
||||
assert.equal(h.model.evenHubPhoneUiLabel, 'Open Chess on phone');
|
||||
assert.deepEqual(h.changes.map(change => change[0]), ['evenHubPhoneUiIcon', 'evenHubPhoneUiVisibility', 'evenHubPhoneUiLabel']);
|
||||
h.model.onEvenHubPhoneUiTap();
|
||||
assert.deepEqual(opened, ['w1']);
|
||||
|
||||
// The host pushes a fresh object on every snapshot; an equal one is not a change.
|
||||
h.changes.length = 0;
|
||||
h.model.evenHubPhoneUi = { windowId: 'w1', title: 'Chess', icon };
|
||||
assert.deepEqual(h.changes, []);
|
||||
h.model.evenHubPhoneUi = null;
|
||||
assert.equal(h.model.evenHubPhoneUiVisibility, 'collapse');
|
||||
assert.equal(h.model.evenHubPhoneUiLabel, '');
|
||||
});
|
||||
|
||||
test('shared display-mode picker preserves cancellation and applies the selected mode', async () => {
|
||||
test('the gear button opens the settings page', () => {
|
||||
const h = fixture();
|
||||
h.pick('Cancel'); await h.model.onDisplayModeTap();
|
||||
assert.equal(h.mode(), 'small');
|
||||
// Unavailable modes (Full Screen beside a side strip) are not offered.
|
||||
h.pick('Huge'); await h.model.onDisplayModeTap();
|
||||
assert.equal(h.mode(), 'small');
|
||||
h.pick('Large'); await h.model.onDisplayModeTap();
|
||||
assert.equal(h.mode(), 'large');
|
||||
assert.equal(h.model.displayModeLabel, 'Large ▾');
|
||||
h.model.onSettingsTap();
|
||||
// The entry is built in the module's own realm, so compare its field.
|
||||
assert.deepEqual(h.navigations.map(entry => entry.moduleName), ['phone-ui/settings-page']);
|
||||
});
|
||||
|
||||
test('the control bar keeps the EvenHub button leftmost and the pads bound to the input style', () => {
|
||||
const xml = require('node:fs').readFileSync(require('node:path').join(__dirname, '../app/phone-ui/remote-controls.xml'), 'utf8');
|
||||
const bar = xml.slice(xml.indexOf('class="control-bar"'), xml.indexOf('onControlsContentLayoutChanged'));
|
||||
const order = ['onEvenHubPhoneUiTap', 'onSyntheticMicTap', 'onKeyboardTap', 'onSettingsTap'].map(name => bar.indexOf(name));
|
||||
assert.ok(order.every(index => index >= 0), 'all four buttons are in the bar');
|
||||
assert.deepEqual(order, [...order].sort((a, b) => a - b));
|
||||
// A leading star column takes the slack, so the app button's coming and going moves no other button.
|
||||
assert.match(xml, /columns="\*,auto,auto,auto,auto"[^>]*class="control-bar"/);
|
||||
assert.match(xml, /visibility="\{\{ watchPadVisibility \}\}"/);
|
||||
assert.match(xml, /visibility="\{\{ ringPadVisibility \}\}"/);
|
||||
assert.doesNotMatch(xml, /TabVisibility|TabClass|TabTap/);
|
||||
});
|
||||
Reference in new issue
Block a user