main
1import 'dart:math';
2
3import 'package:blood_pressure_app/features/statistics/clock_bp_graph.dart';
4import 'package:blood_pressure_app/model/storage/settings_store.dart';
5import 'package:flutter/material.dart';
6import 'package:flutter_test/flutter_test.dart';
7import 'package:provider/provider.dart';
8
9import '../../model/analyzer_test.dart';
10import '../../util.dart';
11
12void main() {
13 testWidgets("doesn't throw when empty" , (tester) async {
14 await tester.pumpWidget(MaterialApp(
15 home: Scaffold(
16 body: ChangeNotifierProvider<Settings>(
17 create: (_) => Settings(),
18 child: const ClockBpGraph(measurements: []),
19 ),
20 ),
21 ));
22 expect(tester.takeException(), isNull);
23 expect(find.byType(ClockBpGraph), findsOneWidget);
24 });
25 testWidgets('[gold] renders sample data like expected in light mode', (tester) async {
26 final rng = Random(1234);
27 await tester.pumpWidget(MaterialApp(
28 home: Scaffold(
29 body: ChangeNotifierProvider<Settings>(
30 create: (_) => Settings(
31 pulColor: Colors.pink,
32 ),
33 child: ClockBpGraph(measurements: [
34 for (int i = 0; i < 50; i++)
35 mockRecord(
36 time: DateTime.fromMillisecondsSinceEpoch(rng.nextInt(1724578014) * 1000),
37 sys: rng.nextInt(60) + 70,
38 dia: rng.nextInt(60) + 40,
39 pul: rng.nextInt(70) + 40,
40 )
41 ],),
42 ),
43 ),
44 ));
45 await expectLater(find.byType(ClockBpGraph), myMatchesGoldenFile('ClockBpGraph-light.png'));
46 }, tags: 'gold');
47 testWidgets('[gold] renders sample data like expected in dark mode', (tester) async {
48 final rng = Random(1234);
49 await tester.pumpWidget(MaterialApp(
50 theme: ThemeData.dark(useMaterial3: true),
51 home: Scaffold(
52 body: ChangeNotifierProvider<Settings>(
53 create: (_) => Settings(
54 pulColor: Colors.pink,
55 ),
56 child: ClockBpGraph(measurements: [
57 for (int i = 0; i < 50; i++)
58 mockRecord(
59 time: DateTime.fromMillisecondsSinceEpoch(rng.nextInt(1724578014) * 1000),
60 sys: rng.nextInt(60) + 70,
61 dia: rng.nextInt(60) + 40,
62 pul: rng.nextInt(70) + 40,
63 )
64 ],),
65 ),
66 ),
67 ));
68 await expectLater(find.byType(ClockBpGraph), myMatchesGoldenFile('ClockBpGraph-dark.png'));
69 }, tags: 'gold');
70}