feat(app): diffs colour added lines and +N green, removed lines and -N red
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user