-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding unit test to check forwarding of minIncluded/maxIncluded via s…
…ideTitles
- Loading branch information
Stefan Czesla
committed
Jun 24, 2024
1 parent
52f62c1
commit 655e405
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
test/chart/base/axis_chart/side_titles/side_titles_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import 'package:fl_chart/fl_chart.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
final data = [ | ||
const FlSpot(0, 0.5), | ||
const FlSpot(1, 1.3), | ||
const FlSpot(2, 1.9), | ||
]; | ||
|
||
const viewSize = Size(400, 400); | ||
|
||
testWidgets( | ||
'Test the effect of minIncluded and maxIncluded in sideTitles', | ||
(WidgetTester tester) async { | ||
|
||
// Minimum/maximum included | ||
final mima = [[true, true], [true, false], [false, true], [false, false]]; | ||
|
||
for(final e in mima) { | ||
|
||
final titlesData = FlTitlesData( | ||
leftTitles: AxisTitles( | ||
sideTitles: SideTitles( | ||
showTitles: true, | ||
minIncluded: e[0], | ||
maxIncluded: e[1], | ||
reservedSize: 50, | ||
interval: 1, | ||
),), | ||
rightTitles: const AxisTitles(), | ||
topTitles: const AxisTitles(), | ||
bottomTitles: const AxisTitles(), | ||
); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: Scaffold( | ||
body: Center( | ||
child: SizedBox( | ||
width: viewSize.width, | ||
height: viewSize.height, | ||
child: LineChart( | ||
LineChartData( | ||
titlesData: titlesData, | ||
lineBarsData: [ | ||
LineChartBarData( | ||
spots: data, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
// Number of expected text widgets (titles) on the y-axis | ||
expect(find.byType(Text), findsNWidgets((e[0] ? 1 : 0) + (e[1] ? 1 : 0) + 1)); | ||
// Always there | ||
expect(find.text('1'), findsOneWidget); | ||
if(e[0]) { | ||
// Minimum included | ||
expect(find.text('0.5'), findsOneWidget); | ||
} | ||
if(e[1]) { | ||
// Maximum included | ||
expect(find.text('1.9'), findsOneWidget); | ||
} | ||
} | ||
}, | ||
); | ||
} |