diff --git a/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs b/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs index 5f5d99b93e..8a73739dd6 100644 --- a/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs +++ b/openpilot/starpilot/galaxy/tests/test_onroad_layout.mjs @@ -67,6 +67,17 @@ for (const name of ["layoutDocument", "previewDocument", "withDisplay", "ordered assert.equal(layoutModule[name], documentHelpers[name], name) const data = snapshot() +for (const width of [50, 65, 100]) + assert.equal(validDocument({ ...data.document, borderWidth: width }, data.metadata), true) +for (const width of [0, 49, 51, 102, null, "60"]) + assert.equal(validDocument({ ...data.document, borderWidth: width }, data.metadata), false) +const borderEditor = { state: { draft: copy(data.document), notice: "" }, editable: true, projection: false, + recordChange: (before, group) => assert.equal(group, "borderWidth") } +OnroadLayoutPage.methods.setBorderWidth.call(borderEditor, 55) +assert.equal(previewDocument(borderEditor.state.draft).borderWidth, 55) +OnroadLayoutPage.methods.setBorderWidth.call(borderEditor, 100) +assert.deepEqual(borderEditor.state.draft, data.document) +assert.ok(ONROAD_LAYOUT_TEMPLATE.includes('aria-label="Edit Screen Border"')) const restoredCompact = copy(data) for (const [id, width, height, x, y] of [["max_speed", 162, 162, 0, 0], ["speed_limit", 118, 132, 330, 20]]) { Object.assign(restoredCompact.metadata.profiles.compact.widgets[id], { width, height, default: {x, y, enabled:true} }) diff --git a/openpilot/starpilot/galaxy/tests/test_onroad_layout.py b/openpilot/starpilot/galaxy/tests/test_onroad_layout.py index 1e4ebfbfce..75651a54c7 100644 --- a/openpilot/starpilot/galaxy/tests/test_onroad_layout.py +++ b/openpilot/starpilot/galaxy/tests/test_onroad_layout.py @@ -308,6 +308,24 @@ class TestOnroadLayoutHttp(unittest.TestCase): self.assertEqual(self.request('/api/ui/layout', {'revision': saved['revision'], 'document': saved['document']}, cookie)[0], 409) self.assertEqual(self.params.get(PARAM_KEY), default_document()) + def test_border_width_persists_without_moving_widgets(self): + cookie = self.login() + _, snapshot, _ = self.request('/api/ui/layout', cookie=cookie) + request = {key: snapshot[key] for key in ('revision', 'document')} + initial = copy.deepcopy(request["document"]) + request["document"]["borderWidth"] = 0 + self.assertEqual(self.request('/api/ui/layout', request, cookie)[0], 400) + request["document"]["borderWidth"] = 60 + code, saved, _ = self.request('/api/ui/layout', request, cookie) + self.assertEqual(saved["document"]["borderWidth"], 60) + self.assertEqual(saved["document"]["layouts"], initial["layouts"]) + _, reread, _ = self.request('/api/ui/layout', cookie=cookie) + self.assertEqual(reread["document"]["borderWidth"], 60) + reset = {'revision': reread['revision'], 'document': {**reread['document'], 'borderWidth': 100}} + reset_code, reset_saved, _ = self.request('/api/ui/layout', reset, cookie) + self.assertEqual(reset_code, 200) + self.assertEqual(reset_saved['document'], initial) + def test_mutation_requires_origin_session_and_unique_fields(self): cookie = self.login() _, snapshot, _ = self.request('/api/ui/layout', cookie=cookie) diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js b/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js index 109141ced7..3870bf79ba 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout-document.js @@ -145,11 +145,13 @@ export const PROJECTION_DISPLAY_SWITCHES = ["blindSpotBorder", "signalBorder", " export function validDocument(document, metadata) { if (!object(document)) return false const profiles = metadata?.projection === true ? ["large"] : PROFILES - if (!keysEqual(document, ["version", "palette", "layouts", "widgetColors", "roadColors", ...(Object.hasOwn(document, "widgetOrder") ? ["widgetOrder"] : []), ...(Object.hasOwn(document, "speedSources") ? ["speedSources"] : []), ...(Object.hasOwn(document, "speedSourcesCard") ? ["speedSourcesCard"] : []), ...(Object.hasOwn(document, "speedAlign") ? ["speedAlign"] : []), ...(Object.hasOwn(document, "clock24Hour") ? ["clock24Hour"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "reduceMotion") ? ["reduceMotion"] : []), ...(Object.hasOwn(document, "showMaxSpeed") ? ["showMaxSpeed"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "speedDisplayOffset") ? ["speedDisplayOffset"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "display") ? ["display"] : []), ...(metadata?.projection === true && Object.hasOwn(document, "largeUiGammaTrial") ? ["largeUiGammaTrial"] : []), ...(metadata?.projection === true ? PROJECTION_DISPLAY_SWITCHES.filter(key => Object.hasOwn(document, key)) : []), ...(metadata?.projection === true && Object.hasOwn(document, "leadInfo") ? ["leadInfo"] : [])]) || (metadata?.projection === true ? document.version !== 8 : document.version !== 17) || + if (!keysEqual(document, ["version", "palette", "layouts", "widgetColors", "roadColors", ...(Object.hasOwn(document, "widgetOrder") ? ["widgetOrder"] : []), ...(Object.hasOwn(document, "speedSources") ? ["speedSources"] : []), ...(Object.hasOwn(document, "speedSourcesCard") ? ["speedSourcesCard"] : []), ...(Object.hasOwn(document, "speedAlign") ? ["speedAlign"] : []), ...(Object.hasOwn(document, "clock24Hour") ? ["clock24Hour"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "reduceMotion") ? ["reduceMotion"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "borderWidth") ? ["borderWidth"] : []), ...(Object.hasOwn(document, "showMaxSpeed") ? ["showMaxSpeed"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "speedDisplayOffset") ? ["speedDisplayOffset"] : []), ...(metadata?.projection !== true && Object.hasOwn(document, "display") ? ["display"] : []), ...(metadata?.projection === true && Object.hasOwn(document, "largeUiGammaTrial") ? ["largeUiGammaTrial"] : []), ...(metadata?.projection === true ? PROJECTION_DISPLAY_SWITCHES.filter(key => Object.hasOwn(document, key)) : []), ...(metadata?.projection === true && Object.hasOwn(document, "leadInfo") ? ["leadInfo"] : [])]) || (metadata?.projection === true ? document.version !== 8 : document.version !== 17) || (Object.hasOwn(document, "speedSources") && typeof document.speedSources !== "boolean") || (Object.hasOwn(document, "speedSourcesCard") && typeof document.speedSourcesCard !== "boolean") || (Object.hasOwn(document, "speedAlign") && !SPEED_ALIGNMENTS.includes(document.speedAlign)) || (Object.hasOwn(document, "clock24Hour") && typeof document.clock24Hour !== "boolean") || + (Object.hasOwn(document, "borderWidth") && (!Number.isInteger(document.borderWidth) || document.borderWidth < 50 || + document.borderWidth > 100 || document.borderWidth % 5 !== 0)) || (Object.hasOwn(document, "reduceMotion") && typeof document.reduceMotion !== "boolean") || (Object.hasOwn(document, "showMaxSpeed") && typeof document.showMaxSpeed !== "boolean") || (Object.hasOwn(document, "speedDisplayOffset") && (!Number.isFinite(document.speedDisplayOffset) || document.speedDisplayOffset < -5 || document.speedDisplayOffset > 5)) || diff --git a/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js b/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js index d3bc39fc0a..3305f89b9b 100644 --- a/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js +++ b/openpilot/starpilot/galaxy/web/js/onroad-layout-template.js @@ -104,9 +104,17 @@ export const ONROAD_LAYOUT_TEMPLATE = ` + :x="projection ? profile.bounds.x : borderInset" :y="projection ? profile.bounds.y : borderInset" + :width="state.profile === 'compact' ? 476 - borderStroke : roadBounds.width + (projection ? 0 : 60 - 2 * borderInset)" + :height="projection ? profile.bounds.height : profile.height - 2 * borderInset" + :rx="state.profile === 'compact' ? 14 : 61" fill="none" :stroke="sceneBorder" :stroke-width="borderStroke" /> +