install_test.dart 2.41 KB
Newer Older
Ian Fischer's avatar
Ian Fischer committed
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:args/command_runner.dart';
Ian Fischer's avatar
Ian Fischer committed
6
import 'package:mockito/mockito.dart';
7
import 'package:flutter_tools/src/commands/install.dart';
Ian Fischer's avatar
Ian Fischer committed
8 9
import 'package:test/test.dart';

10
import 'src/mocks.dart';
11

Ian Fischer's avatar
Ian Fischer committed
12 13 14 15
main() => defineTests();

defineTests() {
  group('install', () {
16
    test('returns 0 when Android is connected and ready for an install', () {
17 18 19
      InstallCommand command = new InstallCommand();
      applyMocksToCommand(command);
      MockDeviceStore mockDevices = command.devices;
20

21
      when(mockDevices.android.isConnected()).thenReturn(true);
22
      when(mockDevices.android.isAppInstalled(any)).thenReturn(false);
23
      when(mockDevices.android.installApp(any)).thenReturn(true);
24

25
      when(mockDevices.iOS.isConnected()).thenReturn(false);
26
      when(mockDevices.iOS.isAppInstalled(any)).thenReturn(false);
27
      when(mockDevices.iOS.installApp(any)).thenReturn(false);
28

29
      when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
30
      when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false);
31
      when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false);
32

33 34 35 36 37 38 39

      CommandRunner runner = new CommandRunner('test_flutter', '')
        ..addCommand(command);
      runner.run(['install']).then((int code) => expect(code, equals(0)));
    });

    test('returns 0 when iOS is connected and ready for an install', () {
40 41 42
      InstallCommand command = new InstallCommand();
      applyMocksToCommand(command);
      MockDeviceStore mockDevices = command.devices;
43

44
      when(mockDevices.android.isConnected()).thenReturn(false);
45
      when(mockDevices.android.isAppInstalled(any)).thenReturn(false);
46
      when(mockDevices.android.installApp(any)).thenReturn(false);
47

48
      when(mockDevices.iOS.isConnected()).thenReturn(true);
49
      when(mockDevices.iOS.isAppInstalled(any)).thenReturn(false);
50
      when(mockDevices.iOS.installApp(any)).thenReturn(true);
51

52
      when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
53
      when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false);
54
      when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false);
55

56
      CommandRunner runner = new CommandRunner('test_flutter', '')
57 58
        ..addCommand(command);
      runner.run(['install']).then((int code) => expect(code, equals(0)));
Ian Fischer's avatar
Ian Fischer committed
59 60 61
    });
  });
}