integration_tests.dart 4.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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
library integration_tests;

import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';

import 'page_objects/page_objects.dart';
import 'page_objects/screens/details_test_screen.dart';

main() {
  group('Todo App Test', () {
    FlutterDriver driver;
    HomeTestScreen homeScreen;

    setUpAll(() async {
      driver = await FlutterDriver.connect();
      homeScreen = new HomeTestScreen(driver);
    });

    tearDownAll(() async {
      if (driver != null) {
        driver.close();
      }
    });

    test('should show a loading screen while the todos are fetched', () async {
      expect(await homeScreen.isLoading(), isTrue);
    });

    test('should start with a list of Todos', () async {
      expect(await homeScreen.isReady(), isTrue);
      expect(await homeScreen.todoList.todoItem('1').isVisible, isTrue);
      expect(await homeScreen.todoList.todoItem('2').isVisible, isTrue);
      expect(await homeScreen.todoList.todoItem('3').isVisible, isTrue);
      expect(await homeScreen.todoList.todoItem('4').isVisible, isTrue);
      expect(await homeScreen.todoList.todoItem('5').isVisible, isTrue);
    });

    test('should be able to click on an item to see details', () async {
      final detailsScreen = await homeScreen.todoList.todoItem('2').tap();
      expect(await detailsScreen.task, isNotEmpty);
      expect(await detailsScreen.note, isNotEmpty);

      final editScreen = await detailsScreen.tapEditTodoButton();

      expect(await editScreen.isReady(), isTrue);

      await editScreen.tapBackButton();
    });

    test('should be able to delete a todo on the details screen', () async {
      final detailsScreen = new DetailsTestScreen(driver);

      await detailsScreen.tapDeleteButton();

55 56 57 58
      expect(await homeScreen.todoList.todoItem('2').isAbsent, isTrue,
          reason: 'TodoItem2 should be absent');
      expect(await homeScreen.snackbarVisible, isTrue,
          reason: 'snackbar should be visible');
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    });

    test('should filter to completed todos', () async {
      await homeScreen.tapFilterButton().tapShowCompleted();

      expect(await homeScreen.todoList.todoItem('3').isVisible, isTrue);
      expect(await homeScreen.todoList.todoItem('5').isVisible, isTrue);
    });

    test('should filter to active todos', () async {
      await homeScreen.tapFilterButton().tapShowActive();

      expect(await homeScreen.todoList.todoItem('1').isVisible, isTrue);
      expect(await homeScreen.todoList.todoItem('4').isVisible, isTrue);
    });

    test('should once again filter to all todos', () async {
      await homeScreen.tapFilterButton().tapShowAll();

      expect(await homeScreen.todoList.todoItem('1').isVisible, isTrue);
      expect(await homeScreen.todoList.todoItem('3').isVisible, isTrue);
      expect(await homeScreen.todoList.todoItem('4').isVisible, isTrue);
      expect(await homeScreen.todoList.todoItem('5').isVisible, isTrue);
    });

    test('should be able to view stats', () async {
      final stats = await homeScreen.tapStatsTab();

      expect(await stats.numActive, 2);
      expect(await stats.numCompleted, 2);
    });

    test('should be able to toggle a todo complete', () async {
      await homeScreen.tapTodosTab().todoItem('1').tapCheckbox();
      final stats = homeScreen.tapStatsTab();

      // This is a hacky way to check if the tapping the checkbox was
      // successful. Would be better to have an `isChecked` method from the
      // driver.
      expect(await stats.numActive, 1);
      expect(await stats.numCompleted, 3);
    });

    test('should be able to clear the completed todos', () async {
      await homeScreen.tapExtraActionsButton().tapClearCompleted();

      final stats = homeScreen.tapStatsTab();

      expect(await stats.numActive, 1);
      expect(await stats.numCompleted, 0);
    });

    test('should be able to toggle all todos complete', () async {
      await homeScreen.tapExtraActionsButton().tapToggleAll();

      expect(await homeScreen.stats.numActive, 0);
      expect(await homeScreen.stats.numCompleted, 1);
    });
  });
}