Add permanent device deletion and refine frontend UI/snackbars

Backend:
- Add db::devices::delete to erase a device and its events atomically
- Expose DELETE /api/devices/{mac}/permanently, wired to OpenAPI
- Cover the new db method and endpoint with tests

Frontend:
- Delete action for not-registered devices (detail screen + list row)
  and an opt-in "permanently delete" checkbox in the Forget dialog
- Navigate to the devices list after deleting from the detail screen
- Refine button emphasis to M3: single filled primary, error-colored
  text buttons for destructive actions, Test demoted to filled-tonal
- Flash the backend-config Test button red on a failed connection test
- Render snackbars through a top-level ScaffoldMessenger host so they
  show above dialogs; keep the built-in SnackBar (with an Overlay host)

Docs:
- CLAUDE.md: rustfmt edition 2024, don't revert formatter-only changes,
  prefer built-in Flutter components, follow existing patterns + M3

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-06-12 09:49:11 -04:00
co-authored by Claude Opus 4.8
parent 2541d0989c
commit 587e097291
20 changed files with 1021 additions and 177 deletions
@@ -3,13 +3,16 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:frontend/settings/settings.dart';
import 'package:frontend/utils/pref_utils.dart';
import 'package:http_mock_adapter/http_mock_adapter.dart';
import '../helpers/backend_test_harness.dart';
import '../helpers/pump_app.dart';
void main() {
late DioAdapter adapter;
setUp(() async {
final adapter = await setUpBackendForTest(
adapter = await setUpBackendForTest(
prefs: {
'base_url': 'http://my.server/api',
'api_key': XOR().xorEncode('topsecret'),
@@ -56,6 +59,47 @@ void main() {
expect(find.text('The URL cannot be empty'), findsOneWidget);
});
// Locates the error icon inside the Test button (its failure-flash state).
Finder testButtonErrorIcon() => find.descendant(
of: find.widgetWithText(FilledButton, 'Test'),
matching: find.byIcon(Icons.error_outline),
);
testWidgets('a failed test flashes the Test button red, then reverts', (
tester,
) async {
// The test binding fails outbound HTTP, so the connection test fails
// without any explicit stubbing.
await openDialog(tester);
await tester.tap(find.widgetWithText(FilledButton, 'Test'));
// Let the request resolve and the snackbar's entrance animation run.
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
// The button flashes its failure state...
expect(testButtonErrorIcon(), findsOneWidget);
// ...and the error snackbar is shown *while the dialog is still open*. (In
// the real app it renders above the dialog via the top-level messenger; the
// bare test harness falls back to the page messenger, but co-presence still
// proves the snackbar fires on failure.)
expect(find.text('Backend configuration'), findsOneWidget);
expect(find.byType(SnackBar), findsOneWidget);
// After the flash duration the button reverts to its idle look.
await tester.pump(const Duration(milliseconds: 1600));
expect(testButtonErrorIcon(), findsNothing);
expect(
find.descendant(
of: find.widgetWithText(FilledButton, 'Test'),
matching: find.byIcon(Icons.play_arrow),
),
findsOneWidget,
);
await tearDownTree(tester);
});
testWidgets('editing the connection re-gates Save behind a Test', (
tester,
) async {