Replace background task spinner with gear
Use an outlined settings gear with a running-count badge and slow linear rotation while background tasks are active. Preserve reduced-motion behavior, composer sizing, and tooltip coverage with updated focused tests and notes.
This commit is contained in:
@@ -675,7 +675,7 @@ void main() {
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
expect(find.byTooltip('Background tasks (2 running)'), findsOneWidget);
|
||||
final counter = find.byKey(const Key('chat-background-tasks-button'));
|
||||
// One '2' is the count inside the ring, one is the compact caption.
|
||||
// One '2' is the count on the gear badge, one is the compact caption.
|
||||
expect(
|
||||
tester
|
||||
.widget<Text>(find.byKey(const Key('chat-background-tasks-count')))
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_background_tasks.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_task_gear.dart';
|
||||
|
||||
final _gearFinder = find.byKey(const Key('chat-background-tasks-gear'));
|
||||
final _badgeFinder = find.byKey(const Key('chat-background-tasks-badge'));
|
||||
final _rotationFinder = find.byKey(const Key('chat-background-tasks-rotation'));
|
||||
|
||||
RotationTransition _rotation(WidgetTester tester) =>
|
||||
tester.widget<RotationTransition>(_rotationFinder);
|
||||
|
||||
Badge _badge(WidgetTester tester) => tester.widget<Badge>(_badgeFinder);
|
||||
|
||||
Widget _gear(int running, {Brightness brightness = Brightness.light}) =>
|
||||
MaterialApp(
|
||||
theme: ThemeData(colorSchemeSeed: Colors.indigo, brightness: brightness),
|
||||
home: Scaffold(
|
||||
body: Center(child: ChatTaskGear(running: running)),
|
||||
),
|
||||
);
|
||||
|
||||
void _reducedMotion(bool reduced) =>
|
||||
TestWidgetsFlutterBinding.ensureInitialized()
|
||||
.platformDispatcher
|
||||
.accessibilityFeaturesTestValue = FakeAccessibilityFeatures(
|
||||
disableAnimations: reduced,
|
||||
);
|
||||
|
||||
class _TasksGateway implements ApiGateway {
|
||||
final _frames = StreamController<JsonMap>.broadcast();
|
||||
List<JsonMap> running = const [];
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => _frames.stream;
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (type == 'chat_shells') return {'chat_shells': running};
|
||||
if (type == 'chat_automations') {
|
||||
return {
|
||||
'chat_automations': {'status': 'unavailable'},
|
||||
};
|
||||
}
|
||||
return <String, dynamic>{};
|
||||
}
|
||||
|
||||
void close() => _frames.close();
|
||||
}
|
||||
|
||||
void main() {
|
||||
tearDown(() => _reducedMotion(false));
|
||||
|
||||
testWidgets('a running task shows the outlined gear with a count badge', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(false);
|
||||
await tester.pumpWidget(_gear(2));
|
||||
expect(_badge(tester).isLabelVisible, isTrue);
|
||||
expect(
|
||||
find.descendant(of: _gearFinder, matching: find.text('2')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: _gearFinder,
|
||||
matching: find.byIcon(Icons.settings_outlined),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: _gearFinder,
|
||||
matching: find.byIcon(Icons.layers_outlined),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
expect(tester.binding.transientCallbackCount, greaterThan(0));
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
});
|
||||
|
||||
testWidgets('the running gear turns linearly, one turn per four seconds', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(false);
|
||||
await tester.pumpWidget(_gear(1));
|
||||
expect(_rotation(tester).turns.value, closeTo(0, 1e-9));
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(_rotation(tester).turns.value, closeTo(0.25, 1e-3));
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(_rotation(tester).turns.value, closeTo(0.5, 1e-3));
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(_rotation(tester).turns.value, closeTo(0, 1e-3));
|
||||
expect(ChatTaskGear.turnDuration, const Duration(seconds: 4));
|
||||
});
|
||||
|
||||
testWidgets('an idle gear is static with no badge and no animation', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(false);
|
||||
await tester.pumpWidget(_gear(0));
|
||||
expect(_badge(tester).isLabelVisible, isFalse);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: _gearFinder,
|
||||
matching: find.byIcon(Icons.settings_outlined),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(_rotation(tester).turns.value, closeTo(0, 1e-9));
|
||||
});
|
||||
|
||||
testWidgets('stopping the last task halts and resets the turn', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(false);
|
||||
await tester.pumpWidget(_gear(2));
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(_rotation(tester).turns.value, greaterThan(0));
|
||||
await tester.pumpWidget(_gear(0));
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
expect(_rotation(tester).turns.value, closeTo(0, 1e-9));
|
||||
expect(_badge(tester).isLabelVisible, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('reduced motion never rotates but still shows the count', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(true);
|
||||
await tester.pumpWidget(_gear(3));
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(_rotation(tester).turns.value, closeTo(0, 1e-9));
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
expect(_badge(tester).isLabelVisible, isTrue);
|
||||
expect(
|
||||
find.descendant(of: _gearFinder, matching: find.text('3')),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('the badge uses the theme primary in dark mode', (tester) async {
|
||||
_reducedMotion(false);
|
||||
await tester.pumpWidget(_gear(1, brightness: Brightness.dark));
|
||||
final scheme = ColorScheme.fromSeed(
|
||||
seedColor: Colors.indigo,
|
||||
brightness: Brightness.dark,
|
||||
);
|
||||
expect(_badge(tester).backgroundColor, scheme.primary);
|
||||
expect(_badge(tester).textColor, scheme.onPrimary);
|
||||
});
|
||||
|
||||
testWidgets('every state keeps the same square size', (tester) async {
|
||||
_reducedMotion(false);
|
||||
for (final running in [0, 1, 12]) {
|
||||
await tester.pumpWidget(_gear(running));
|
||||
expect(tester.getSize(_gearFinder), const Size(16, 16));
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('the composer button shows the gear and its tooltip', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(false);
|
||||
final gateway = _TasksGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.running = const [
|
||||
{'id': 'sh1', 'status': 'running', 'command': 'go test ./...'},
|
||||
{'id': 'sh2', 'status': 'running', 'command': 'make'},
|
||||
];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatBackgroundTasks(gateway: gateway, sessionId: 's'),
|
||||
),
|
||||
),
|
||||
);
|
||||
// The gear turns forever while tasks run, so settle by pumping only.
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.text('2 tasks'), findsOneWidget);
|
||||
expect(find.byTooltip('Background tasks (2 running)'), findsOneWidget);
|
||||
expect(_badge(tester).isLabelVisible, isTrue);
|
||||
expect(
|
||||
find.descendant(of: _gearFinder, matching: find.text('2')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.binding.transientCallbackCount, greaterThan(0));
|
||||
});
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_background_tasks.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_task_spinner.dart';
|
||||
|
||||
final _spinnerFinder = find.byKey(const Key('chat-background-tasks-spinner'));
|
||||
|
||||
CircularProgressIndicator _ring(WidgetTester tester) =>
|
||||
tester.widget<CircularProgressIndicator>(
|
||||
find.descendant(
|
||||
of: _spinnerFinder,
|
||||
matching: find.byType(CircularProgressIndicator),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _spinner(int running, {Brightness brightness = Brightness.light}) =>
|
||||
MaterialApp(
|
||||
theme: ThemeData(colorSchemeSeed: Colors.indigo, brightness: brightness),
|
||||
home: Scaffold(
|
||||
body: Center(child: ChatTaskSpinner(running: running)),
|
||||
),
|
||||
);
|
||||
|
||||
void _reducedMotion(bool reduced) =>
|
||||
TestWidgetsFlutterBinding.ensureInitialized()
|
||||
.platformDispatcher
|
||||
.accessibilityFeaturesTestValue = FakeAccessibilityFeatures(
|
||||
disableAnimations: reduced,
|
||||
);
|
||||
|
||||
class _TasksGateway implements ApiGateway {
|
||||
final _frames = StreamController<JsonMap>.broadcast();
|
||||
List<JsonMap> running = const [];
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => _frames.stream;
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (type == 'chat_shells') return {'chat_shells': running};
|
||||
if (type == 'chat_automations') {
|
||||
return {
|
||||
'chat_automations': {'status': 'unavailable'},
|
||||
};
|
||||
}
|
||||
return <String, dynamic>{};
|
||||
}
|
||||
|
||||
void close() => _frames.close();
|
||||
}
|
||||
|
||||
void main() {
|
||||
tearDown(() => _reducedMotion(false));
|
||||
|
||||
testWidgets(
|
||||
'a running task shows an indeterminate primary ring with the count',
|
||||
(tester) async {
|
||||
_reducedMotion(false);
|
||||
await tester.pumpWidget(_spinner(2));
|
||||
final ring = _ring(tester);
|
||||
expect(ring.value, isNull);
|
||||
expect(ring.strokeWidth, 2);
|
||||
expect(
|
||||
ring.color,
|
||||
ThemeData(colorSchemeSeed: Colors.indigo).colorScheme.primary,
|
||||
);
|
||||
expect(
|
||||
find.descendant(of: _spinnerFinder, matching: find.text('2')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: _spinnerFinder,
|
||||
matching: find.byIcon(Icons.layers_outlined),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
// The ring keeps turning: time advances the animation.
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
expect(tester.binding.transientCallbackCount, greaterThan(0));
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('dark theme uses the dark primary for the ring', (tester) async {
|
||||
_reducedMotion(false);
|
||||
await tester.pumpWidget(_spinner(1, brightness: Brightness.dark));
|
||||
expect(
|
||||
_ring(tester).color,
|
||||
ThemeData(
|
||||
colorSchemeSeed: Colors.indigo,
|
||||
brightness: Brightness.dark,
|
||||
).colorScheme.primary,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('no running task shows the static icon with no ring', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(false);
|
||||
await tester.pumpWidget(_spinner(0));
|
||||
expect(
|
||||
find.descendant(
|
||||
of: _spinnerFinder,
|
||||
matching: find.byType(CircularProgressIndicator),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: _spinnerFinder,
|
||||
matching: find.byIcon(Icons.layers_outlined),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
});
|
||||
|
||||
testWidgets('every state keeps the same square size', (tester) async {
|
||||
_reducedMotion(false);
|
||||
for (final running in [0, 1, 12]) {
|
||||
await tester.pumpWidget(_spinner(running));
|
||||
expect(tester.getSize(_spinnerFinder), const Size(16, 16));
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('reduced motion holds one static ring segment while running', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(true);
|
||||
await tester.pumpWidget(_spinner(3));
|
||||
expect(_ring(tester).value, ChatTaskSpinner.reducedSegment);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(_ring(tester).value, ChatTaskSpinner.reducedSegment);
|
||||
expect(tester.binding.transientCallbackCount, 0);
|
||||
});
|
||||
|
||||
testWidgets('the composer button shows the count ring and its tooltip', (
|
||||
tester,
|
||||
) async {
|
||||
_reducedMotion(false);
|
||||
final gateway = _TasksGateway();
|
||||
addTearDown(gateway.close);
|
||||
gateway.running = const [
|
||||
{'id': 'sh1', 'status': 'running', 'command': 'go test ./...'},
|
||||
{'id': 'sh2', 'status': 'running', 'command': 'make'},
|
||||
];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatBackgroundTasks(gateway: gateway, sessionId: 's'),
|
||||
),
|
||||
),
|
||||
);
|
||||
// The ring repeats forever, so settle by pumping, never by waiting.
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.text('2 tasks'), findsOneWidget);
|
||||
expect(find.byTooltip('Background tasks (2 running)'), findsOneWidget);
|
||||
expect(_ring(tester).value, isNull);
|
||||
expect(
|
||||
find.descendant(of: _spinnerFinder, matching: find.text('2')),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user