install_test.dart 2.45 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:flutter_tools/src/commands/install.dart';
6
import 'package:mockito/mockito.dart';
Ian Fischer's avatar
Ian Fischer committed
7 8
import 'package:test/test.dart';

9 10
import 'src/common.dart';
import 'src/context.dart';
11
import 'src/mocks.dart';
12

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

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

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

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

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

34 35
      testDeviceManager.addDevice(mockDevices.android);

36 37 38
      return createTestCommandRunner(command).run(['install']).then((int code) {
        expect(code, equals(0));
      });
39 40
    });

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

46
      when(mockDevices.android.isConnected()).thenReturn(false);
47
      when(mockDevices.android.isAppInstalled(any)).thenReturn(false);
48
      when(mockDevices.android.installApp(any)).thenReturn(false);
49

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

54
      when(mockDevices.iOSSimulator.isConnected()).thenReturn(false);
55
      when(mockDevices.iOSSimulator.isAppInstalled(any)).thenReturn(false);
56
      when(mockDevices.iOSSimulator.installApp(any)).thenReturn(false);
57

58 59
      testDeviceManager.addDevice(mockDevices.iOS);

60 61 62
      return createTestCommandRunner(command).run(['install']).then((int code) {
        expect(code, equals(0));
      });
Ian Fischer's avatar
Ian Fischer committed
63 64 65
    });
  });
}