diff --git a/test/chart/bar_chart/bar_chart_alignment_widget_test.dart b/test/chart/bar_chart/bar_chart_alignment_widget_test.dart new file mode 100644 index 000000000..be90880fc --- /dev/null +++ b/test/chart/bar_chart/bar_chart_alignment_widget_test.dart @@ -0,0 +1,79 @@ +import 'package:fl_chart/fl_chart.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +List get barGroups => [ + BarChartGroupData(x: 0, barRods: [BarChartRodData(toY: 8)]), + BarChartGroupData(x: 1, barRods: [BarChartRodData(toY: 10)]), + BarChartGroupData(x: 2, barRods: [BarChartRodData(toY: 14)]), + BarChartGroupData(x: 3, barRods: [BarChartRodData(toY: 15)]), + BarChartGroupData(x: 4, barRods: [BarChartRodData(toY: 13)]), + BarChartGroupData(x: 5, barRods: [BarChartRodData(toY: 10)]), + BarChartGroupData(x: 6, barRods: [BarChartRodData(toY: 16)]), + BarChartGroupData(x: 7, barRods: [BarChartRodData(toY: 8)]), + BarChartGroupData(x: 8, barRods: [BarChartRodData(toY: 10)]), + BarChartGroupData(x: 9, barRods: [BarChartRodData(toY: 14)]), + BarChartGroupData(x: 10, barRods: [BarChartRodData(toY: 15)]), + BarChartGroupData(x: 11, barRods: [BarChartRodData(toY: 13)]), + BarChartGroupData(x: 12, barRods: [BarChartRodData(toY: 10)]), + BarChartGroupData(x: 13, barRods: [BarChartRodData(toY: 16)]), + BarChartGroupData(x: 14, barRods: [BarChartRodData(toY: 8)]), + BarChartGroupData(x: 15, barRods: [BarChartRodData(toY: 10)]), + BarChartGroupData(x: 16, barRods: [BarChartRodData(toY: 14)]), + BarChartGroupData(x: 17, barRods: [BarChartRodData(toY: 15)]), + BarChartGroupData(x: 18, barRods: [BarChartRodData(toY: 13)]), + BarChartGroupData(x: 19, barRods: [BarChartRodData(toY: 10)]), + BarChartGroupData(x: 20, barRods: [BarChartRodData(toY: 16)]), + ]; + +void main() { + const viewSize = Size(400, 400); + + testWidgets( + 'Barchart alignment overflow test', + (WidgetTester tester) async { + // Test that the bar chart alignment works as expected when the + // bar groups are too wide to fit in the chart. + for (final groupsSpace in [4.0, 20.0]) { + for (final barChartAlignment in [ + BarChartAlignment.start, + BarChartAlignment.center, + BarChartAlignment.end, + ]) { + // Build the bar chart. + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Center( + child: SizedBox( + width: viewSize.width, + height: viewSize.height, + child: BarChart( + BarChartData( + barGroups: barGroups, + gridData: const FlGridData(show: false), + alignment: barChartAlignment, + groupsSpace: groupsSpace, + maxY: 20, + ), + ), + ), + ), + ), + ), + ); + + // Wait for the chart to be rendered. + await tester.pumpAndSettle(); + + // Take a golden image. + final fname = '${barChartAlignment}_$groupsSpace'; + await expectLater( + find.byType(BarChart), + matchesGoldenFile('golden/$fname.png'), + ); + } + } + }, + ); +}