arblant
Railynx / test / app / settings_test.dart
settings_test.dart185 lines · 6.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:railway_clean_ip_scanner/app/controller.dart';
import 'package:railway_clean_ip_scanner/app/prefs_store.dart';
import 'package:railway_clean_ip_scanner/main.dart';
import 'package:railway_clean_ip_scanner/ui/settings_page.dart';
import 'package:railway_clean_ip_scanner/ui/widgets.dart';

import '../fakes.dart';

void main() {
  group('appearance presets', () {
    test('defaults are the full shipped look', () {
      final c = AppController(engine: FakeEngine());
      addTearDown(c.dispose);
      expect(c.uiPreset, 'original');
      expect(c.animatedAurora, isTrue);
      expect(c.fxBlobs, isTrue);
      expect(c.fxWashes, isTrue);
      expect(c.fxDockBlur, isTrue);
      expect(c.fxRichShadows, isTrue);
      expect(c.fxGlowBlur, isTrue);
      expect(c.fxHalfRes, isFalse);
      expect(c.fxLiteRows, isTrue);
      expect(c.fpsLimit, 0);
      expect(c.fxButtonFlow, isTrue);
      expect(c.fxRingGlow, isTrue);
      expect(c.fxRowAnimations, isTrue);
    });

    test('performance preset turns every effect off', () {
      final c = AppController(engine: FakeEngine());
      addTearDown(c.dispose);
      c.applyPreset('performance');
      expect(c.uiPreset, 'performance');
      expect(c.animatedAurora, isFalse);
      expect(c.fxBlobs, isFalse);
      expect(c.fxWashes, isFalse);
      expect(c.fxDockBlur, isFalse);
      expect(c.fxButtonFlow, isFalse);
      expect(c.fxRingGlow, isFalse);
      expect(c.fxRowAnimations, isFalse);
      expect(c.fxRichShadows, isFalse);
      expect(c.fxGlowBlur, isFalse);
      expect(c.fxHalfRes, isTrue);
    });

    test('balanced keeps the aurora but draws it the cheap way', () {
      final c = AppController(engine: FakeEngine());
      addTearDown(c.dispose);
      c.applyPreset('balanced');
      expect(c.uiPreset, 'balanced');
      expect(c.fxBlobs, isTrue);
      expect(c.fxWashes, isTrue);
      expect(c.fxRingGlow, isTrue);
      expect(c.animatedAurora, isFalse);
      expect(c.fxDockBlur, isTrue);
      expect(c.fxButtonFlow, isFalse);
      expect(c.fxRichShadows, isFalse);
      expect(c.fxGlowBlur, isFalse);
      expect(c.fxHalfRes, isTrue);
    });

    test('touching one switch makes the preset custom, restoring it re-derives', () {
      final c = AppController(engine: FakeEngine());
      addTearDown(c.dispose);
      c.setFx(blobs: false);
      expect(c.uiPreset, 'custom');
      c.setFx(blobs: true);
      expect(c.uiPreset, 'original');
    });

    test('settings survive a restart (prefs round-trip)', () async {
      final dir = await Directory.systemTemp.createTemp('railynx_prefs');
      addTearDown(() => dir.delete(recursive: true));
      final store = PrefsStore(File('${dir.path}/prefs.json'));

      final a = AppController(engine: FakeEngine(), prefs: store);
      a.applyPreset('balanced');
      a.setFx(ringGlow: false);
      a.dispose();

      final b = AppController(engine: FakeEngine(), prefs: store);
      addTearDown(b.dispose);
      expect(b.animatedAurora, isFalse);
      expect(b.fxDockBlur, isTrue);
      expect(b.fxBlobs, isTrue);
      expect(b.fxRingGlow, isFalse);
      expect(b.uiPreset, 'custom');
    });

    test('frame-rate cap and new look flags persist', () async {
      final dir = await Directory.systemTemp.createTemp('railynx_prefs');
      addTearDown(() => dir.delete(recursive: true));
      final store = PrefsStore(File('${dir.path}/prefs.json'));

      final a = AppController(engine: FakeEngine(), prefs: store);
      expect(a.fpsLimit, 0);
      a.setFpsLimit(60);
      a.setFx(richShadows: false, halfRes: true, liteRows: false);
      a.dispose();

      final b = AppController(engine: FakeEngine(), prefs: store);
      addTearDown(b.dispose);
      expect(b.fpsLimit, 60);
      expect(b.fxRichShadows, isFalse);
      expect(b.fxHalfRes, isTrue);
      expect(b.fxLiteRows, isFalse);
    });
  });

  group('settings page', () {
    testWidgets('gear opens it; preset card and switches drive the controller', (tester) async {
      tester.view.physicalSize = const Size(1280, 1400);
      tester.view.devicePixelRatio = 1;
      addTearDown(tester.view.resetPhysicalSize);
      addTearDown(tester.view.resetDevicePixelRatio);

      final c = AppController(engine: FakeEngine());
      // The aurora clock repeats forever; freeze it so pumps can settle.
      c.animatedAurora = false;
      addTearDown(c.dispose);
      await tester.pumpWidget(ScannerApp(controller: c));
      await tester.pump();

      await tester.tap(find.byIcon(Icons.settings_rounded));
      await tester.pump(const Duration(milliseconds: 450));
      await tester.pump();
      expect(find.byType(SettingsPage), findsOneWidget);
      expect(find.text('Original'), findsOneWidget);
      expect(find.text('Performance'), findsOneWidget);

      await tester.tap(find.text('Performance'));
      await tester.pump();
      expect(c.uiPreset, 'performance');
      expect(c.fxBlobs, isFalse);

      // Flip "Aurora lights" (the second switch) back on: preset -> custom.
      // (Finders are scoped to the settings page — the home page's own
      // ListView is still in the tree underneath the pushed route.)
      final pageList = find.descendant(of: find.byType(SettingsPage), matching: find.byType(ListView));
      await tester.drag(pageList, const Offset(0, -320));
      await tester.pump(const Duration(milliseconds: 300));
      final pageSwitches = find.descendant(of: find.byType(SettingsPage), matching: find.byType(AppSwitch));
      await tester.tap(pageSwitches.at(1));
      await tester.pump();
      expect(c.fxBlobs, isTrue);
      expect(c.uiPreset, 'custom');
      expect(find.text('Custom'), findsOneWidget);
    });

    testWidgets('frame-rate segmented control drives the fps limit', (tester) async {
      tester.view.physicalSize = const Size(1280, 1600);
      tester.view.devicePixelRatio = 1.0;
      addTearDown(tester.view.reset);
      final c = AppController(engine: FakeEngine());
      addTearDown(c.dispose);
      await tester.pumpWidget(ScannerApp(controller: c));
      await tester.pump();
      expect(c.fpsLimit, 0);

      await tester.tap(find.byIcon(Icons.settings_rounded));
      await tester.pump();
      await tester.pump(const Duration(milliseconds: 400));
      expect(find.byType(SettingsPage), findsOneWidget);

      final pageScrollable = find.descendant(of: find.byType(SettingsPage), matching: find.byType(Scrollable));
      await tester.scrollUntilVisible(
        find.text('Refresh-rate cap'),
        300,
        scrollable: pageScrollable,
      );
      await tester.pump(const Duration(milliseconds: 300));
      expect(find.text('Refresh-rate cap'), findsOneWidget);
      await tester.tap(find.text('60'));
      await tester.pump();
      expect(c.fpsLimit, 60);
      await tester.tap(find.text('30'));
      await tester.pump();
      expect(c.fpsLimit, 30);
    });
  });
}