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);
|
||||
});
|
||||
}
|
||||
@@ -94,10 +94,11 @@ void main() {
|
||||
final context = tester.element(find.byType(Scaffold));
|
||||
final add = diffLineColors(context, ChangeLineKind.add);
|
||||
final remove = diffLineColors(context, ChangeLineKind.remove);
|
||||
expect(add.background, isNull);
|
||||
expect(remove.background, isNull);
|
||||
// Additions are green and removals red, each line on a light tint.
|
||||
expect(add.background, isNotNull);
|
||||
expect(remove.background, isNotNull);
|
||||
expect(add.text, isNot(remove.text), reason: '$brightness text');
|
||||
expect(add.text, Theme.of(context).colorScheme.primary);
|
||||
expect(add.text.g, greaterThan(add.text.r), reason: 'green addition');
|
||||
expect(remove.text, Theme.of(context).colorScheme.error);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user