70 lines
2.0 KiB
Dart
70 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/settings/health/health_models.dart';
|
|
import 'package:pipelines_app/features/settings/health/health_widgets.dart';
|
|
|
|
void main() {
|
|
test('missing usage remains unknown', () {
|
|
expect(healthUsageRatio(null, 100), isNull);
|
|
expect(healthUsageRatio(5, null), isNull);
|
|
expect(healthUsageRatio(5, 0), isNull);
|
|
expect(healthUsageRatio(150, 100), 1);
|
|
});
|
|
testWidgets('meter applies consistent high and critical thresholds', (
|
|
tester,
|
|
) async {
|
|
final scheme = ColorScheme.fromSeed(seedColor: Colors.blue);
|
|
for (final (value, color) in [
|
|
(0.799, scheme.primary),
|
|
(0.8, scheme.tertiary),
|
|
(0.949, scheme.tertiary),
|
|
(0.95, scheme.error),
|
|
]) {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: ThemeData(colorScheme: scheme),
|
|
home: Scaffold(
|
|
body: HealthMeter(label: 'CPU', value: value),
|
|
),
|
|
),
|
|
);
|
|
expect(
|
|
tester
|
|
.widget<LinearProgressIndicator>(
|
|
find.byType(LinearProgressIndicator),
|
|
)
|
|
.color,
|
|
color,
|
|
);
|
|
}
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(body: HealthMeter(label: 'CPU', value: null)),
|
|
),
|
|
);
|
|
expect(
|
|
tester
|
|
.widget<LinearProgressIndicator>(find.byType(LinearProgressIndicator))
|
|
.value,
|
|
0,
|
|
);
|
|
expect(find.text('CPU —'), findsOneWidget);
|
|
});
|
|
testWidgets('meter label fits narrow large text', (tester) async {
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: MediaQuery(
|
|
data: const MediaQueryData(textScaler: TextScaler.linear(2)),
|
|
child: const SizedBox(
|
|
width: 200,
|
|
child: HealthMeter(label: 'Utilization', value: 0.97),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|