Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Editor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Item {
}
function close() {
guard(function() {
presentTimer.stop()
root.opened = false; window.visible = false
if (root.service) { root.service.editorOpen = false; root.service.heartbeat() }
root.call("preview.close", {})
Expand Down
5 changes: 4 additions & 1 deletion Service.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ Item {
var msg = JSON.parse(data)
if (msg.event === "state") { snapshot = msg.state; frame = snapshot.frame; previewPath = snapshot.previewPath || "" }
else if (msg.event === "frame") { frame = msg.frame; previewPath = msg.previewPath; frameReady() }
else if (msg.event === "openEditor" && shell) shell.summon("marchybar.touchbar", "{}")
else if (msg.event === "openEditor" && shell) {
if (editorOpen) shell.hide("marchybar.touchbar")
else shell.summon("marchybar.touchbar", "{}")
}
else if (msg.id !== undefined) {
var entry = pending[msg.id] || {}; var callback = entry.callback
var quiet = ["heartbeat","theme","preview","hello","get","editor.present"].includes(entry.method)
Expand Down
42 changes: 41 additions & 1 deletion tests/qml/editor-harness.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,71 @@ ShellRoot {
id: backend
property var snapshot: ({presets:[testCase.fixture],rules:[],settings:{},data:{},hardware:{},revision:"r1",widgetTypes:["button","slider","clock"],channels:["volume"]})
property var lastRequest: null
property int presentations: 0
property bool editorOpen: false
property string error: ""
property string previewPath: ""
property int frame: 0
function heartbeat() {}
function request(method, params, callback, revision) {
lastRequest = {method:method,params:params}
if(method==="editor.present") presentations++
if(method==="preview" && callback) callback(true,{boxes:[],geometry:{width:2170,height:60}})
if(method==="preset.save" && callback) callback(true,params.preset)
}
}
Editor { id: editor; service:backend }
Service { id: service; shell:host; editorOpen:backend.editorOpen }
QtObject {
id: host
function firstPartyServiceFor(id) { return null }
function summon(id, payload) { testCase.compare(id,"marchybar.touchbar"); editor.open(payload) }
function hide(id) { testCase.compare(id,"marchybar.touchbar"); editor.close() }
}
function compare(a,b) { if(a!==b) throw new Error("Expected " + JSON.stringify(b) + ", got " + JSON.stringify(a)) }
function verify(value) { if(!value) throw new Error("Assertion failed") }
Timer {
interval:150;running:true
onTriggered: {
try {
for(var name of ["test_draftIsolationAndUndo","test_addAndMoveWidget","test_discardGuardAndSave","test_dropdownChangesWidgetType","test_brightnessDraftAndPercent"]) { testCase.init();testCase[name]();console.log("MARCHYBAR_QML_PASS",name) }
for(var name of ["test_draftIsolationAndUndo","test_addAndMoveWidget","test_discardGuardAndSave","test_dropdownChangesWidgetType","test_brightnessDraftAndPercent","test_hamburgerToggle","test_hamburgerDiscardGuard"]) { testCase.init();testCase[name]();console.log("MARCHYBAR_QML_PASS",name) }
closeCheck.start()
} catch(e) { console.error("MARCHYBAR_QML_FAILED",e.stack || String(e)); Qt.quit() }
}
}
Timer {
id: closeCheck
interval:300
onTriggered: {
try {
testCase.compare(backend.presentations,0)
console.log("MARCHYBAR_QML_PASS","test_noPresentationAfterRapidClose")
console.log("MARCHYBAR_QML_ALL_PASSED")
} catch(e) { console.error("MARCHYBAR_QML_FAILED",e.stack || String(e)) }
Qt.quit()
}
}
function init() { editor.draft=null;editor.savedDraft="";editor.load("test") }
function tapHamburger() { service.receive(JSON.stringify({event:"openEditor"})); compare(service.error,"") }
function test_hamburgerToggle() {
tapHamburger();compare(editor.opened,true);compare(backend.editorOpen,true)
tapHamburger();compare(editor.opened,false);compare(backend.editorOpen,false)
compare(backend.lastRequest.method,"preview.close")
tapHamburger();compare(editor.opened,true);compare(backend.editorOpen,true)
tapHamburger();compare(editor.opened,false);compare(backend.editorOpen,false)
}
function test_hamburgerDiscardGuard() {
tapHamburger()
editor.changeWidget("label","Unsaved")
tapHamburger();verify(editor.confirmAction!==null)
compare(editor.opened,true);compare(backend.editorOpen,true)
editor.confirmAction=null
compare(editor.dirty,true);compare(editor.opened,true)
tapHamburger();verify(editor.confirmAction!==null)
editor.confirmAction();editor.confirmAction=null
compare(editor.opened,false);compare(backend.editorOpen,false)
compare(editor.draft,null);compare(backend.lastRequest.method,"preview.close")
}
function test_draftIsolationAndUndo() {
compare(editor.dirty,false)
editor.widgetIndex=0
Expand Down
2 changes: 1 addition & 1 deletion tests/test-qml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -euo pipefail
MARCHYBAR_TEST_ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
MARCHYBAR_TEST_DIR=$(mktemp -d /tmp/marchybar-qml.XXXXXX)
trap 'rm -rf "$MARCHYBAR_TEST_DIR"' EXIT
cp "$MARCHYBAR_TEST_ROOT/Editor.qml" "$MARCHYBAR_TEST_ROOT/SettingNumber.qml" "$MARCHYBAR_TEST_DIR/"
cp "$MARCHYBAR_TEST_ROOT/Editor.qml" "$MARCHYBAR_TEST_ROOT/SettingNumber.qml" "$MARCHYBAR_TEST_ROOT/Service.qml" "$MARCHYBAR_TEST_DIR/"
cp "$MARCHYBAR_TEST_ROOT/tests/qml/editor-harness.qml" "$MARCHYBAR_TEST_DIR/shell.qml"
ln -s "${OMARCHY_PATH:-/usr/share/omarchy}/shell/Commons" "$MARCHYBAR_TEST_DIR/Commons"
ln -s "${OMARCHY_PATH:-/usr/share/omarchy}/shell/Ui" "$MARCHYBAR_TEST_DIR/Ui"
Expand Down
Loading