macos_workflow_test.dart 2.05 KB
Newer Older
1 2 3 4
// Copyright 2018 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/features.dart';
6 7 8 9
import 'package:mockito/mockito.dart';

import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/macos/macos_workflow.dart';
10
import 'package:process/process.dart';
11

12 13
import '../../src/common.dart';
import '../../src/context.dart';
14
import '../../src/testbed.dart';
15 16

void main() {
17 18 19 20 21 22 23
  MockPlatform mac;
  MockPlatform notMac;
  Testbed testbed;

  setUp(() {
    mac = MockPlatform();
    notMac = MockPlatform();
24 25
    when(mac.isMacOS).thenReturn(true);
    when(notMac.isMacOS).thenReturn(false);
26
    testbed = Testbed(overrides: <Type, Generator>{
27
      Platform: () => mac,
28
      FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
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

  test('Applies to macOS platform', () => testbed.run(() {
    expect(macOSWorkflow.appliesToHostPlatform, true);
    expect(macOSWorkflow.canListDevices, true);
    expect(macOSWorkflow.canLaunchDevices, true);
    expect(macOSWorkflow.canListEmulators, false);
  }));

  test('Does not apply to non-macOS platform', () => testbed.run(() {
    expect(macOSWorkflow.appliesToHostPlatform, false);
    expect(macOSWorkflow.canListDevices, false);
    expect(macOSWorkflow.canLaunchDevices, false);
    expect(macOSWorkflow.canListEmulators, false);
  }, overrides: <Type, Generator>{
    Platform: () => notMac,
  }));

  test('Does not apply when feature is disabled', () => testbed.run(() {
    expect(macOSWorkflow.appliesToHostPlatform, false);
    expect(macOSWorkflow.canListDevices, false);
    expect(macOSWorkflow.canLaunchDevices, false);
    expect(macOSWorkflow.canListEmulators, false);
  }, overrides: <Type, Generator>{
    FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: false),
  }));
56 57 58 59
}

class MockPlatform extends Mock implements Platform {
  @override
60
  Map<String, String> environment = <String, String>{};
61
}
62 63

class MockProcessManager extends Mock implements ProcessManager {}