Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
Desktop: QML tests, run by check.ps1 and CI
Bee926910088c8a
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 652c000..b0cc9fe 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -68,6 +68,9 @@ jobs:run: cargo clippy --locked -p nectarlink-desktop -p nectarlink-vcam -p s1-qt-rust --all-targets -- -D warnings- name: Testsrun: cargo test --locked -p nectarlink-desktop -p nectarlink-vcam+ - name: QML tests+ shell: pwsh+ run: ./scripts/qml-tests.ps1- name: Release buildrun: cargo build --locked --release -p nectarlink-desktop -p nectarlink-vcam- name: Install NSISdiff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 2098dfa..5aca078 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -46,6 +46,12 @@ Before opening a pull request, run the same checks as CI:./scripts/check.ps1```+The desktop app's shared QML components have tests in+`desktop/app/tests/qml` (`tst_*.qml`, Qt Quick Test), which check.ps1 runs+through `./scripts/qml-tests.ps1`. The Rust singletons the components read+are stubbed in `desktop/app/tests/qml/stubs`; a test that needs one more+adds it there.+## Ground rules for codeThese come from the plan and will grow into a full style guide:diff --git a/desktop/app/tests/qml/stubs/AppController.qml b/desktop/app/tests/qml/stubs/AppController.qmlnew file mode 100644index 0000000..3c5d3c1--- /dev/null+++ b/desktop/app/tests/qml/stubs/AppController.qml@@ -0,0 +1,26 @@+// SPDX-License-Identifier: GPL-3.0-or-later+pragma Singleton+import QtQuick++// Stands in for the Rust AppController in QML tests: still, light, no+// phone or wallpaper colors.+QtObject {+ property bool systemDark: false+ property bool reduceMotion: true+ property bool powerSaver: false+ property string phoneColors: ""+ property string wallpaperColors: ""+ property string currentPage: "home"+ property string settingsSection: ""+ property bool doctorBusy: false+ property var doctorChecks: []+ property var commandPaletteResults: []+ property double commandPaletteOpenMs: 0+ function featureState(feature) { return "" }+ function closeCommandPalette() {}+ function noteCommandPaletteShown() {}+ function runCommandPalette(id) {}+ function searchCommandPalette(query) {}+ function runDoctor() {}+ function doctorFix(id) {}+}diff --git a/desktop/app/tests/qml/stubs/MediaList.qml b/desktop/app/tests/qml/stubs/MediaList.qmlnew file mode 100644index 0000000..0e02a65--- /dev/null+++ b/desktop/app/tests/qml/stubs/MediaList.qml@@ -0,0 +1,10 @@+// SPDX-License-Identifier: GPL-3.0-or-later+pragma Singleton+import QtQuick++// Stands in for the Rust MediaList in QML tests: nothing playing.+QtObject {+ property string activeArt: ""+ property string activeColors: ""+ function command(id, action) {}+}diff --git a/desktop/app/tests/qml/stubs/Preferences.qml b/desktop/app/tests/qml/stubs/Preferences.qmlnew file mode 100644index 0000000..49eff61--- /dev/null+++ b/desktop/app/tests/qml/stubs/Preferences.qml@@ -0,0 +1,14 @@+// SPDX-License-Identifier: GPL-3.0-or-later+pragma Singleton+import QtQuick++// Stands in for the Rust Preferences in QML tests: Bloom, light.+QtObject {+ property string theme: "bloom"+ property string colorMode: "light"+ property bool amoled: false+ property bool combMotion: false+ property string seed: ""+ property string commandPaletteHotkey: ""+ property bool streamPcAudioToPhone: false+}diff --git a/desktop/app/tests/qml/tst_iconbutton.qml b/desktop/app/tests/qml/tst_iconbutton.qmlnew file mode 100644index 0000000..6141a8e--- /dev/null+++ b/desktop/app/tests/qml/tst_iconbutton.qml@@ -0,0 +1,53 @@+// SPDX-License-Identifier: GPL-3.0-or-later+import QtQuick+import QtTest+import app.nectarlink++// An IconButton's tooltip shows under its button, in the window's top+// layer, wherever the button sits (it once showed at the window's top-left).+Item {+ id: root+ width: 400+ height: 300++ Item {+ x: 120+ y: 90+ width: 200+ height: 100+ IconButton {+ id: button+ x: 40+ y: 20+ iconPath: Icons.pause+ label: "Pause"+ }+ }++ TestCase {+ name: "IconButton"+ when: windowShown++ function tooltip() {+ const layer = root.Window.contentItem+ for (let i = 0; i < layer.children.length; i++) {+ const child = layer.children[i]+ if (child.hasOwnProperty("shown") && child.hasOwnProperty("reposition"))+ return child+ }+ return null+ }++ function test_tooltip_shows_under_its_button() {+ mouseMove(button, button.width / 2, button.height / 2)+ let tip = null+ tryVerify(() => { tip = tooltip(); return tip !== null && tip.visible && tip.opacity === 1 },+ 3000, "the tooltip shows")+ const under = button.mapToItem(root.Window.contentItem, button.width / 2, button.height)+ verify(Math.abs(tip.x + tip.width / 2 - under.x) <= 1, "centered on the button: " + tip.x)+ verify(tip.y >= under.y && tip.y <= under.y + 12, "just under the button: " + tip.y)+ mouseMove(root, 5, 5)+ tryVerify(() => !tip.visible, 3000, "the tooltip hides when the pointer leaves")+ }+ }+}diff --git a/desktop/app/tests/qml/tst_segmented.qml b/desktop/app/tests/qml/tst_segmented.qmlnew file mode 100644index 0000000..41b2433--- /dev/null+++ b/desktop/app/tests/qml/tst_segmented.qml@@ -0,0 +1,64 @@+// SPDX-License-Identifier: GPL-3.0-or-later+import QtQuick+import QtTest+import app.nectarlink++// A Segmented follows its value and its options as they change, as the+// webcam's resolution choice does when the phone's camera can't do 4K.+Item {+ id: root+ width: 400+ height: 100++ property bool uhd: true++ Segmented {+ id: choice+ options: [+ { value: "720", label: "720p" },+ { value: "1080", label: "1080p" }+ ].concat(root.uhd ? [{ value: "2160", label: "4K" }] : [])+ value: "2160"+ }++ SignalSpy {+ id: picked+ target: choice+ signalName: "picked"+ }++ TestCase {+ name: "Segmented"+ when: windowShown++ function init() {+ root.uhd = true+ choice.value = "2160"+ picked.clear()+ }++ function test_the_value_is_selected() {+ compare(choice.selectedIndex, 2)+ verify(choice.selectedItem !== null)+ }++ function test_options_that_go_take_their_choice_with_them() {+ root.uhd = false+ compare(choice.options.length, 2)+ compare(choice.selectedIndex, -1, "nothing selected while the value isn't offered")+ choice.value = "1080"+ compare(choice.selectedIndex, 1)+ root.uhd = true+ compare(choice.options.length, 3)+ compare(choice.selectedIndex, 1, "the choice stays when an option comes back")+ }++ function test_a_click_picks_its_option() {+ const first = choice.selectedItem.parent.children[0]+ mouseClick(first)+ compare(picked.count, 1)+ compare(picked.signalArguments[0][0], "720")+ compare(choice.value, "2160", "the value is the owner's to change")+ }+ }+}diff --git a/scripts/check.ps1 b/scripts/check.ps1index 4e5b65c..7ea4a2d 100644--- a/scripts/check.ps1+++ b/scripts/check.ps1@@ -1,8 +1,8 @@# SPDX-License-Identifier: GPL-3.0-or-later<#.SYNOPSIS- Runs the same checks as CI: formatting, lints, tests, license headers,- generated files and the dependency policy. Exits non-zero if any step+ Runs the same checks as CI: formatting, lints, tests (the QML ones too),+ license headers, generated files and the dependency policy. Exits non-zero if any stepfails..DESCRIPTION@@ -60,6 +60,7 @@ try {Invoke-Step "Clippy" { cargo clippy --workspace --all-targets --locked -- -D warnings }if (-not $Fast) {Invoke-Step "Tests" { cargo test --workspace --locked }+ Invoke-Step "QML tests" { & (Join-Path $PSScriptRoot "qml-tests.ps1") }}Invoke-Step "License headers" { & (Join-Path $PSScriptRoot "check-headers.ps1") }Invoke-Step "Generated files" { cargo xtask tokens --check }diff --git a/scripts/qml-tests.ps1 b/scripts/qml-tests.ps1new file mode 100644index 0000000..9a52d72--- /dev/null+++ b/scripts/qml-tests.ps1@@ -0,0 +1,54 @@+# SPDX-License-Identifier: GPL-3.0-or-later+<#+.SYNOPSIS+ Runs the desktop app's QML tests (desktop/app/tests/qml/tst_*.qml).++.DESCRIPTION+ Puts the app's shared components and its Theme, Tokens and Icons+ singletons in a QML module named app.nectarlink under target/qml-tests,+ with the stubs in desktop/app/tests/qml/stubs standing in for the Rust+ singletons they read, and runs qmltestrunner over the tests, off screen.+ Needs Qt (qmake on PATH, or QT_ROOT_DIR / -QtRoot).+#>+param(+ [string]$QtRoot+)++$ErrorActionPreference = 'Stop'+$repo = Split-Path -Parent $PSScriptRoot++if (-not $QtRoot) { $QtRoot = $env:QT_ROOT_DIR }+if (-not $QtRoot) {+ $qmake = Get-Command qmake6, qmake -ErrorAction SilentlyContinue | Select-Object -First 1+ if ($qmake) { $QtRoot = Split-Path -Parent (Split-Path -Parent $qmake.Source) }+}+if (-not $QtRoot) { $QtRoot = 'C:\Qt\6.12.0\msvc2022_64' }+$runner = Join-Path $QtRoot 'bin\qmltestrunner.exe'+if (-not (Test-Path $runner)) { throw "qmltestrunner not found under $QtRoot; pass -QtRoot" }++$qml = Join-Path $repo 'desktop\app\qml'+$tests = Join-Path $repo 'desktop\app\tests\qml'+$imports = Join-Path $repo 'target\qml-tests'+$module = Join-Path $imports 'app\nectarlink'+if (Test-Path $imports) { Remove-Item -Recurse -Force $imports }+New-Item -ItemType Directory -Force $module | Out-Null++$singletons = @('Theme', 'Tokens', 'Icons')+foreach ($name in $singletons) { Copy-Item (Join-Path $qml "$name.qml") $module }+$components = Get-ChildItem (Join-Path $qml 'components') -Filter *.qml+$components | Copy-Item -Destination $module+$stubs = Get-ChildItem (Join-Path $tests 'stubs') -Filter *.qml+$stubs | Copy-Item -Destination $module++$lines = @('module app.nectarlink')+foreach ($name in $singletons + @($stubs | ForEach-Object BaseName)) {+ $lines += "singleton $name 1.0 $name.qml"+}+foreach ($component in $components) {+ $lines += "$($component.BaseName) 1.0 $($component.Name)"+}+[System.IO.File]::WriteAllLines((Join-Path $module 'qmldir'), $lines)++$env:PATH = "$(Join-Path $QtRoot 'bin');$env:PATH"+& $runner -platform offscreen -import $imports -input $tests -o "-,txt"+if ($LASTEXITCODE -ne 0) { throw "QML tests failed" }