"Fossies" - the Fresh Open Source Software Archive

Member "flutter-3.7.0/packages/flutter/test/cupertino/activity_indicator_test.dart" (24 Jan 2023, 5655 Bytes) of package /linux/misc/flutter-3.7.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 // This file is run as part of a reduced test set in CI on Mac and Windows
    6 // machines.
    7 @Tags(<String>['reduced-test-set'])
    8 
    9 import 'package:flutter/cupertino.dart';
   10 import 'package:flutter/scheduler.dart';
   11 import 'package:flutter_test/flutter_test.dart';
   12 
   13 import '../rendering/mock_canvas.dart';
   14 
   15 void main() {
   16   testWidgets('Activity indicator animate property works', (WidgetTester tester) async {
   17     await tester.pumpWidget(buildCupertinoActivityIndicator());
   18     expect(SchedulerBinding.instance.transientCallbackCount, equals(1));
   19 
   20     await tester.pumpWidget(buildCupertinoActivityIndicator(false));
   21     expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
   22 
   23     await tester.pumpWidget(Container());
   24 
   25     await tester.pumpWidget(buildCupertinoActivityIndicator(false));
   26     expect(SchedulerBinding.instance.transientCallbackCount, equals(0));
   27 
   28     await tester.pumpWidget(buildCupertinoActivityIndicator());
   29     expect(SchedulerBinding.instance.transientCallbackCount, equals(1));
   30   });
   31 
   32   testWidgets('Activity indicator dark mode', (WidgetTester tester) async {
   33     final Key key = UniqueKey();
   34     await tester.pumpWidget(
   35       Center(
   36         child: MediaQuery(
   37           data: const MediaQueryData(),
   38           child: RepaintBoundary(
   39             key: key,
   40             child: Container(
   41               color: CupertinoColors.white,
   42               child: const CupertinoActivityIndicator(
   43                 animating: false,
   44                 radius: 35,
   45               ),
   46             ),
   47           ),
   48         ),
   49       ),
   50     );
   51 
   52     await expectLater(
   53       find.byKey(key),
   54       matchesGoldenFile('activityIndicator.paused.light.png'),
   55     );
   56 
   57     await tester.pumpWidget(
   58       Center(
   59         child: MediaQuery(
   60           data: const MediaQueryData(platformBrightness: Brightness.dark),
   61           child: RepaintBoundary(
   62             key: key,
   63             child: Container(
   64               color: CupertinoColors.black,
   65               child: const CupertinoActivityIndicator(
   66                 animating: false,
   67                 radius: 35,
   68               ),
   69             ),
   70           ),
   71         ),
   72       ),
   73     );
   74 
   75     await expectLater(
   76       find.byKey(key),
   77       matchesGoldenFile('activityIndicator.paused.dark.png'),
   78     );
   79   });
   80 
   81   testWidgets('Activity indicator 0% in progress', (WidgetTester tester) async {
   82     final Key key = UniqueKey();
   83     await tester.pumpWidget(
   84       Center(
   85         child: RepaintBoundary(
   86           key: key,
   87           child: Container(
   88             color: CupertinoColors.white,
   89             child: const CupertinoActivityIndicator.partiallyRevealed(
   90               progress: 0,
   91             ),
   92           ),
   93         ),
   94       ),
   95     );
   96 
   97     await expectLater(
   98       find.byKey(key),
   99       matchesGoldenFile('activityIndicator.inprogress.0.0.png'),
  100     );
  101   });
  102 
  103   testWidgets('Activity indicator 30% in progress', (WidgetTester tester) async {
  104     final Key key = UniqueKey();
  105     await tester.pumpWidget(
  106       Center(
  107         child: RepaintBoundary(
  108           key: key,
  109           child: Container(
  110             color: CupertinoColors.white,
  111             child: const CupertinoActivityIndicator.partiallyRevealed(
  112               progress: 0.5,
  113             ),
  114           ),
  115         ),
  116       ),
  117     );
  118 
  119     await expectLater(
  120       find.byKey(key),
  121       matchesGoldenFile('activityIndicator.inprogress.0.3.png'),
  122     );
  123   });
  124 
  125   testWidgets('Activity indicator 100% in progress', (WidgetTester tester) async {
  126     final Key key = UniqueKey();
  127     await tester.pumpWidget(
  128       Center(
  129         child: RepaintBoundary(
  130           key: key,
  131           child: Container(
  132             color: CupertinoColors.white,
  133             child: const CupertinoActivityIndicator.partiallyRevealed(),
  134           ),
  135         ),
  136       ),
  137     );
  138 
  139     await expectLater(
  140       find.byKey(key),
  141       matchesGoldenFile('activityIndicator.inprogress.1.0.png'),
  142     );
  143   });
  144 
  145   // Regression test for https://github.com/flutter/flutter/issues/41345.
  146   testWidgets('has the correct corner radius', (WidgetTester tester) async {
  147     await tester.pumpWidget(
  148       const CupertinoActivityIndicator(animating: false, radius: 100),
  149     );
  150 
  151     // An earlier implementation for the activity indicator started drawing
  152     // the ticks at 9 o'clock, however, in order to support partially revealed
  153     // indicator (https://github.com/flutter/flutter/issues/29159), the
  154     // first tick was changed to be at 12 o'clock.
  155     expect(
  156       find.byType(CupertinoActivityIndicator),
  157       paints
  158         ..rrect(rrect: const RRect.fromLTRBXY(-10, -100 / 3, 10, -100, 10, 10)),
  159     );
  160   });
  161 
  162   testWidgets('Can specify color', (WidgetTester tester) async {
  163     final Key key = UniqueKey();
  164     await tester.pumpWidget(
  165       Center(
  166         child: RepaintBoundary(
  167           key: key,
  168           child: Container(
  169             color: CupertinoColors.white,
  170             child: const CupertinoActivityIndicator(
  171               animating: false,
  172               color: Color(0xFF5D3FD3),
  173               radius: 100,
  174             ),
  175           ),
  176         ),
  177       ),
  178     );
  179 
  180     expect(
  181       find.byType(CupertinoActivityIndicator),
  182       paints
  183         ..rrect(rrect: const RRect.fromLTRBXY(-10, -100 / 3, 10, -100, 10, 10),
  184                 color: const Color(0x935d3fd3)),
  185     );
  186   });
  187 }
  188 
  189 Widget buildCupertinoActivityIndicator([bool? animating]) {
  190   return MediaQuery(
  191     data: const MediaQueryData(),
  192     child: CupertinoActivityIndicator(
  193       animating: animating ?? true,
  194     ),
  195   );
  196 }