Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo committed Sep 20, 2024
1 parent d2149fe commit 0784915
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions test/chart/bar_chart/bar_chart_alignment_widget_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

List<BarChartGroupData> 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'),
);
}
}
},
);
}

0 comments on commit 0784915

Please sign in to comment.