Skip to content

Commit

Permalink
Created line_chart_test.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
theperu committed Dec 27, 2022
1 parent f013647 commit a961284
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/custom_widgets/line_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ class _LineChartSample2State extends State<LineChartWidget> {
final style = TextStyle(
color: widget.colorLine1Data.withOpacity(1.0),
fontWeight: FontWeight.normal,
fontSize: 9,
fontSize: 10,
);
Widget text;
switch (value.toInt()) {
case 6:
text = Text('8 Nov', style: style);
case 3:
text = Text('4', style: style);
break;
case 16:
text = Text('15 Nov', style: style);
case 10:
text = Text('11', style: style);
break;
case 23:
text = Text('22 Nov', style: style);
case 17:
text = Text('18', style: style);
break;
case 6:
text = Text('30 Nov', style: style);
case 24:
text = Text('25', style: style);
break;
default:
text = Text('', style: style);
Expand Down
86 changes: 86 additions & 0 deletions test/widget/line_chart_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import "dart:math";
import '../../lib/custom_widgets/line_chart.dart';
import 'package:fl_chart/fl_chart.dart';

void main() {
testWidgets('Properly Render Accounts Widget', (WidgetTester tester) async {
final random = Random();

double lower = -5;
double upper = 8;

await tester.pumpWidget(MaterialApp(
home: Material(
child: LineChartWidget(
line1Data: [
FlSpot(0, lower + random.nextDouble() * (upper - lower)),
FlSpot(1, lower + random.nextDouble() * (upper - lower)),
FlSpot(2, lower + random.nextDouble() * (upper - lower)),
FlSpot(3, lower + random.nextDouble() * (upper - lower)),
FlSpot(4, lower + random.nextDouble() * (upper - lower)),
FlSpot(5, lower + random.nextDouble() * (upper - lower)),
FlSpot(6, lower + random.nextDouble() * (upper - lower)),
FlSpot(7, lower + random.nextDouble() * (upper - lower)),
FlSpot(8, lower + random.nextDouble() * (upper - lower)),
FlSpot(9, lower + random.nextDouble() * (upper - lower)),
FlSpot(10, lower + random.nextDouble() * (upper - lower)),
FlSpot(11, lower + random.nextDouble() * (upper - lower)),
FlSpot(12, lower + random.nextDouble() * (upper - lower)),
FlSpot(13, lower + random.nextDouble() * (upper - lower)),
FlSpot(14, lower + random.nextDouble() * (upper - lower)),
FlSpot(15, lower + random.nextDouble() * (upper - lower)),
FlSpot(16, lower + random.nextDouble() * (upper - lower)),
],
colorLine1Data: const Color(0xffffffff),
line2Data: [
FlSpot(0, lower + random.nextDouble() * (upper - lower)),
FlSpot(1, lower + random.nextDouble() * (upper - lower)),
FlSpot(2, lower + random.nextDouble() * (upper - lower)),
FlSpot(3, lower + random.nextDouble() * (upper - lower)),
FlSpot(4, lower + random.nextDouble() * (upper - lower)),
FlSpot(5, lower + random.nextDouble() * (upper - lower)),
FlSpot(6, lower + random.nextDouble() * (upper - lower)),
FlSpot(7, lower + random.nextDouble() * (upper - lower)),
FlSpot(8, lower + random.nextDouble() * (upper - lower)),
FlSpot(9, lower + random.nextDouble() * (upper - lower)),
FlSpot(10, lower + random.nextDouble() * (upper - lower)),
FlSpot(11, lower + random.nextDouble() * (upper - lower)),
FlSpot(12, lower + random.nextDouble() * (upper - lower)),
FlSpot(13, lower + random.nextDouble() * (upper - lower)),
FlSpot(14, lower + random.nextDouble() * (upper - lower)),
FlSpot(15, lower + random.nextDouble() * (upper - lower)),
FlSpot(16, lower + random.nextDouble() * (upper - lower)),
FlSpot(17, lower + random.nextDouble() * (upper - lower)),
FlSpot(18, lower + random.nextDouble() * (upper - lower)),
FlSpot(19, lower + random.nextDouble() * (upper - lower)),
FlSpot(20, lower + random.nextDouble() * (upper - lower)),
FlSpot(21, lower + random.nextDouble() * (upper - lower)),
FlSpot(22, lower + random.nextDouble() * (upper - lower)),
FlSpot(23, lower + random.nextDouble() * (upper - lower)),
FlSpot(24, lower + random.nextDouble() * (upper - lower)),
FlSpot(25, lower + random.nextDouble() * (upper - lower)),
FlSpot(26, lower + random.nextDouble() * (upper - lower)),
FlSpot(27, lower + random.nextDouble() * (upper - lower)),
FlSpot(28, lower + random.nextDouble() * (upper - lower)),
FlSpot(29, lower + random.nextDouble() * (upper - lower)),
],
colorLine2Data: const Color(0xffffffff),
colorBackground: const Color(0xff356CA3),
maxY: upper,
minY: lower,
maxDays: 30.0,
),
),
)
);

expect(find.text('4'), findsOneWidget);
expect(find.text('11'), findsOneWidget);
expect(find.text('18'), findsOneWidget);
expect(find.text('25'), findsOneWidget);

}
);
}

0 comments on commit a961284

Please sign in to comment.