Skip to content

Commit

Permalink
Add some unit tests for the rotationQuarterTurns properties
Browse files Browse the repository at this point in the history
  • Loading branch information
imaNNeo committed Dec 27, 2024
1 parent f628212 commit c31b99f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/chart/base/axis_chart/axis_chart_scaffold_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:fl_chart/fl_chart.dart';
import 'package:fl_chart/src/chart/base/axis_chart/axis_chart_scaffold_widget.dart';
import 'package:fl_chart/src/chart/base/axis_chart/side_titles/side_titles_widget.dart';
import 'package:fl_chart/src/chart/base/custom_interactive_viewer.dart';
import 'package:fl_chart/src/extensions/size_extension.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -366,6 +367,48 @@ void main() {
},
);

testWidgets(
'LineChart with rotationQuarterTurns',
(WidgetTester tester) async {
for (var rotationTurns = 0; rotationTurns <= 8; rotationTurns++) {
Size? chartDrawingSize;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: SizedBox(
width: 400,
height: 200,
child: AxisChartScaffoldWidget(
chartBuilder: (context, chartVirtualRect) => LayoutBuilder(
builder: (context, constraints) {
chartDrawingSize = constraints.biggest;
return const ColoredBox(
color: Colors.red,
);
},
),
data: lineChartDataWithNoTitles.copyWith(
rotationQuarterTurns: rotationTurns,
),
),
),
),
),
),
);
expect(
chartDrawingSize,
const Size(400, 200).rotateByQuarterTurns(rotationTurns),
);
final types = find.byType(RotatedBox);
final rotatedBox = tester.widget<RotatedBox>(types);
expect(rotatedBox.quarterTurns, rotationTurns);
expect(types, findsOne);
}
},
);

group('AxisChartScaffoldWidget', () {
for (final scaleAxis in FlScaleAxis.scalingEnabledAxis) {
testWidgets(
Expand Down
20 changes: 20 additions & 0 deletions test/chart/data_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,26 @@ final LineChartData lineChartData20 = LineChartData(
minX: 11,
minY: 302,
);
final LineChartData lineChartData21 = LineChartData(
borderData: borderData1,
rotationQuarterTurns: 1,
lineTouchData: lineTouchData1,
showingTooltipIndicators: [
showingTooltipIndicator1,
showingTooltipIndicator2,
],
backgroundColor: Colors.red,
maxY: 23,
rangeAnnotations: rangeAnnotations1,
gridData: flGridData1,
titlesData: MockData.flTitlesData1,
lineBarsData: [lineChartBarData1, lineChartBarData2, lineChartBarData3],
betweenBarsData: [betweenBarsData1, betweenBarsData2, betweenBarsData3],
extraLinesData: extraLinesData1,
maxX: 23,
minX: 11,
minY: 302,
);

final PieChartData pieChartData1 = PieChartData(
borderData: FlBorderData(show: false, border: Border.all()),
Expand Down
15 changes: 15 additions & 0 deletions test/chart/line_chart/line_chart_data_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ void main() {
expect(lineChartData1 == lineChartData18, false);
expect(lineChartData1 == lineChartData19, false);
expect(lineChartData1 == lineChartData20, false);
expect(lineChartData1 == lineChartData21, false);
expect(
lineChartData21 ==
lineChartData21.copyWith(
rotationQuarterTurns: 2,
),
false,
);
expect(
lineChartData21 ==
lineChartData21.copyWith(
rotationQuarterTurns: 1,
),
true,
);
});
});
}

0 comments on commit c31b99f

Please sign in to comment.