'use strict'; const assert = require('assert'); const fs = require('fs'); const { readSource } = require('./test-fixtures/sources.js'); const controls = ['PopupSurface', 'PopupSection', 'PopupCard', 'PopupButton', 'PopupBadge', 'PopupDivider', 'PopupSlider', 'PopupTextField', 'PopupToolTip']; for (const control of controls) assert(fs.existsSync(`${control}.qml`), `${control}.qml must exist`); const host = fs.readFileSync('PopupHost.qml', 'utf8'); assert.strictEqual((host.match(/PopupSurface\s*\{/g) || []).length, 1, 'host has exactly one popup surface'); for (const control of ['PopupSurface', 'PopupSection', 'PopupCard']) assert(!/childrenRect/.test(fs.readFileSync(`${control}.qml`, 'utf8')), `${control} avoids container binding loops`); const popupButton = fs.readFileSync('PopupButton.qml', 'utf8'); assert(/activeFocusOnTab:\s*interactive && enabled/.test(popupButton), 'disabled cards reject keyboard traversal through the shared button'); assert(/Accessible\.onPressAction:\s*if \(interactive && enabled\)/.test(popupButton), 'disabled cards reject accessible activation'); const popupTextField = fs.readFileSync('PopupTextField.qml', 'utf8'); assert(/T\.TextField\s*\{[\s\S]*?clip:\s*true/.test(popupTextField), 'shared native text input clips long text'); // Empty focused hints are exercised by the controls fixture's real pointer // focus and fieldHintVisible assertion, not by pinning the editor's private id. const popupSlider = fs.readFileSync('PopupSlider.qml', 'utf8'); assert(/T\.Slider\s*\{/.test(popupSlider), 'slider delegates input and handle dragging to Qt'); assert(/signal moved\(real value\)/.test(popupSlider), 'slider retains the moved(real) caller contract'); // External updates, eased presentation, and manual interruption are exercised // through real Qt in the controls/brightness fixtures, not a private binding regex. const popupToolTip = fs.readFileSync('PopupToolTip.qml', 'utf8'); assert(/required property Theme theme/.test(popupToolTip) && /wrapMode:\s*Text\.Wrap/.test(popupToolTip), 'tooltips use a typed Nugu theme and wrap'); assert(/textFormat:\s*Text\.PlainText/.test(popupToolTip), 'tooltips never interpret service text as markup'); // These are source contracts, not interaction evidence. ui-test.qml exposes // native pressed/focus/geometry and write counts for the nested input driver. const fixture = fs.readFileSync('ui-test.qml', 'utf8'); for (const probe of ['buttonPressed', 'sliderPressed', 'sliderThumb', 'fieldHintVisible', 'cardWrites', 'nestedWrites', 'iconTooltipVisible', 'disabledWrites']) assert(fixture.includes(probe), `nested fixture exposes ${probe}`); const notificationCard = readSource('NotificationCard.qml'); assert(/iconSource:\s*actionBtn\.actIcon/.test(notificationCard), 'notification actions retain advertised icons'); assert(!/height:\s*3\s*\n\s*color:.*ui\.accent/.test(readSource('LauncherPanel.qml')), 'launcher accent removed'); assert(!/left accent bar/.test(readSource('AudioPanel.qml')), 'audio accent strips removed'); const keybinds = fs.readFileSync('../../niri/cfg/keybinds.kdl', 'utf8'); assert(/Mod\+Escape[^}]*notificationsDismissToasts/s.test(keybinds), 'super+escape dismisses notification toasts'); const bluetoothService = readSource('Bluetooth.qml'); // Async native changes reach the panel through bindings, never a refresh poll. assert(/readonly property var devices: devicesList\(\)/.test(bluetoothService) && !/stateObject\(|refreshed/.test(readSource('ConnectivityPanel.qml')), 'bluetooth state reaches the panel through typed bindings'); const panels = ['ConnectivityPanel', 'AudioPanel', 'TrayPanel', 'NotificationGroup', 'NotificationCard', 'ClipboardPanel', 'PowerPanel', 'BrightnessPanel', 'MediaPanel', 'NokoPanel', 'LauncherPanel']; for (const panel of panels) { const source = readSource(`${panel}.qml`); assert(/Popup(?:Section|Card|Button|Badge|Divider|Slider|TextField)\s*\{/.test(source), `${panel} uses shared popup controls`); assert(!/text:\s*"[A-Z]/.test(source), `${panel} authored labels are lowercase`); } for (const panel of ['AudioPanel', 'BrightnessPanel', 'MediaPanel']) assert(/PopupSlider\s*\{/.test(readSource(`${panel}.qml`)), `${panel} uses the shared slider`); for (const panel of ['ConnectivityPanel', 'MediaPanel']) assert(/PopupBadge\s*\{/.test(readSource(`${panel}.qml`)), `${panel} uses shared status badges`); const nokoPanel = readSource('NokoPanel.qml'); assert(/onClicked: root\.configureRequested\(\)/.test(nokoPanel) && !/NokoAssetRow|setupExpanded/.test(nokoPanel), 'noko setup lives in Config, capture stays local'); assert(/running: root\.nokoService\.dictating && !root\.theme\.lowPowerMode/.test(nokoPanel), 'the noko panel wave never ticks in low-power mode'); for (const panel of ['ClipboardPanel', 'ConnectivityPanel', 'LauncherPanel']) assert(/PopupTextField\s*\{/.test(readSource(`${panel}.qml`)), `${panel} uses the shared text field`); console.log('popup-controls.test.js: ALL PASS');