Skip to content

Commit

Permalink
Adding unit test to check forwarding of minIncluded/maxIncluded via s…
Browse files Browse the repository at this point in the history
…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.
74 changes: 74 additions & 0 deletions test/chart/base/axis_chart/side_titles/side_titles_test.dart
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);
}
}
},
);
}

0 comments on commit 655e405

Please sign in to comment.