32 lines
1.0 KiB
Dart
32 lines
1.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/changes/widgets/change_style.dart';
|
|
|
|
void main() {
|
|
testWidgets('+N is green and -N red; other words keep the text colour', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
const MaterialApp(
|
|
home: Scaffold(
|
|
body: ChangeStatText('2 files changed · +12 -3 · run-4 kept'),
|
|
),
|
|
),
|
|
);
|
|
final rich = tester.widget<RichText>(find.byType(RichText)).text;
|
|
final spans = <String, Color?>{};
|
|
rich.visitChildren((span) {
|
|
if (span is TextSpan && span.text != null) {
|
|
spans[span.text!] = span.style?.color;
|
|
}
|
|
return true;
|
|
});
|
|
final context = tester.element(find.byType(ChangeStatText));
|
|
expect(spans['+12'], addedColor(context));
|
|
expect(spans['-3'], removedColor(context));
|
|
// A hyphenated word is not a count.
|
|
expect(spans.keys.where((key) => key.contains('run-4')), isNotEmpty);
|
|
expect(spans['-4'], isNull);
|
|
});
|
|
}
|