cupertino_date_picker.0_test.dart 2.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_api_samples/cupertino/date_picker/cupertino_date_picker.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';

const Offset _kRowOffset = Offset(0.0, -50.0);

void main() {
  testWidgets('Can change date, time and dateTime using CupertinoDatePicker', (WidgetTester tester) async {
    await tester.pumpWidget(
13
      const example.DatePickerApp(),
14 15 16 17 18 19 20
    );
    // Open the date picker.
    await tester.tap(find.text('10-26-2016'));
    await tester.pumpAndSettle();

    // Drag month, day and year wheels to change the picked date.
    await tester.drag(find.text('October'), _kRowOffset, touchSlopY: 0, warnIfMissed: false); // see top of file
21
    await tester.drag(find.textContaining('26').last, _kRowOffset, touchSlopY: 0, warnIfMissed: false); // see top of file
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    await tester.drag(find.text('2016'), _kRowOffset, touchSlopY: 0, warnIfMissed: false); // see top of file

    await tester.pump();
    await tester.pump(const Duration(milliseconds: 500));

    // Close the date picker.
    await tester.tapAt(const Offset(1.0, 1.0));
    await tester.pumpAndSettle();

    expect(find.text('12-28-2018'), findsOneWidget);

    // Open the time picker.
    await tester.tap(find.text('22:35'));
    await tester.pumpAndSettle();

    // Drag hour and minute wheels to change the picked time.
    await tester.drag(find.text('22'), const Offset(0.0, 50.0), touchSlopY: 0, warnIfMissed: false); // see top of file
    await tester.drag(find.text('35'), const Offset(0.0, 50.0), touchSlopY: 0, warnIfMissed: false); // see top of file

    await tester.pump();
    await tester.pump(const Duration(milliseconds: 500));

    // Close the time picker.
    await tester.tapAt(const Offset(1.0, 1.0));
    await tester.pumpAndSettle();

    expect(find.text('20:33'), findsOneWidget);

    // Open the dateTime picker.
    await tester.tap(find.text('8-3-2016 17:45'));
    await tester.pumpAndSettle();

    // Drag hour and minute wheels to change the picked time.
    await tester.drag(find.text('17'), const Offset(0.0, 50.0), touchSlopY: 0, warnIfMissed: false); // see top of file
    await tester.drag(find.text('45'), const Offset(0.0, 50.0), touchSlopY: 0, warnIfMissed: false); // see top of file

    await tester.pump();
    await tester.pump(const Duration(milliseconds: 500));

    // Close the dateTime picker.
    await tester.tapAt(const Offset(1.0, 1.0));
    await tester.pumpAndSettle();

    expect(find.text('8-3-2016 15:43'), findsOneWidget);
  });
}