Files
pipelines/app/test/ui/theme/app_design_controller_test.dart
T
alan 8ed3998dd5 Design: Terminal is the default when none is stored; Default is now Classic
An unset (or unknown) design id resolves to Terminal, in the controller's
initial value, AppDesign.fromId and the boot spinner. A stored choice,
including Classic's stable 'default' id, is respected. The picker calls the
original Material look Classic so no row reads 'Default'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 21:33:05 +00:00

80 lines
2.8 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/theme/app_design.dart';
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
import 'package:shared_preferences/shared_preferences.dart';
void main() {
test('an unset device starts on Terminal and keeps it', () async {
final unset = AppDesignController(store: MemoryAppDesignStore());
expect(unset.design, AppDesign.terminal);
await unset.restore();
expect(unset.design, AppDesign.terminal);
});
test(
'restore applies the stored design; unknown ids are the default',
() async {
// An explicit Classic choice, stored as `default` back when Classic was
// the default, is respected.
final stored = AppDesignController(
store: MemoryAppDesignStore('default'),
);
var notified = 0;
stored.addListener(() => notified++);
await stored.restore();
expect(stored.design, AppDesign.standard);
expect(notified, 1);
final paper = AppDesignController(store: MemoryAppDesignStore('paper'));
await paper.restore();
expect(paper.design, AppDesign.paper);
final unknown = AppDesignController(store: MemoryAppDesignStore('neon'));
await unknown.restore();
expect(unknown.design, AppDesign.terminal);
},
);
test('select applies at once and stores the id', () async {
final store = MemoryAppDesignStore();
final designs = AppDesignController(store: store);
final pending = designs.select(AppDesign.standard);
expect(designs.design, AppDesign.standard);
await pending;
expect(store.id, 'default');
expect(designs.saveFailed, isFalse);
});
test('a failed save is reported and the choice still applies', () async {
final store = MemoryAppDesignStore()..failSaves = true;
final designs = AppDesignController(store: store);
await designs.select(AppDesign.paper);
expect(designs.design, AppDesign.paper);
expect(designs.saveFailed, isTrue);
store.failSaves = false;
await designs.select(AppDesign.standard);
expect(designs.saveFailed, isFalse);
});
test('a choice made while restoring wins over the stored one', () async {
final designs = AppDesignController(
store: MemoryAppDesignStore('terminal'),
);
final restoring = designs.restore();
await designs.select(AppDesign.standard);
await restoring;
expect(designs.design, AppDesign.standard);
});
test('shared preferences keep the choice per device', () async {
SharedPreferences.setMockInitialValues({});
const store = SharedPreferencesAppDesignStore();
expect(await store.load(), isNull);
expect(await store.save('terminal'), isTrue);
expect(await store.load(), 'terminal');
final designs = AppDesignController(store: store);
await designs.restore();
expect(designs.design, AppDesign.terminal);
});
}