Skip to content

Commit

Permalink
Merge pull request #36 from yosemiteyss/feat/integration_test
Browse files Browse the repository at this point in the history
add integration test
  • Loading branch information
yosemiteyss authored Feb 11, 2023
2 parents eef554c + 6665cdd commit cae9a43
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

env:
FLUTTER_CHANNEL: 'stable'
FLUTTER_VERSION: '3.3.9'
FLUTTER_VERSION: '3.7.1'

jobs:
build_example_android:
Expand Down
136 changes: 136 additions & 0 deletions example/integration_test/main_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_volume_controller/flutter_volume_controller.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter/material.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

setUp(() {
runApp(const MaterialApp());
});

testWidgets('should get volume', (tester) async {
final volume = await FlutterVolumeController.getVolume();
expect(volume, isNotNull);
});

testWidgets('should set volume', (tester) async {
const List<double> targets = [1.0, 0.0];

for (final target in targets) {
await FlutterVolumeController.setVolume(target);
await _insertDelay();

final actual = await FlutterVolumeController.getVolume();
expect(actual, target);
}
});

testWidgets('should raise volume', (tester) async {
const before = 0.2;

await FlutterVolumeController.setVolume(before);
await _insertDelay();

await FlutterVolumeController.raiseVolume(0.5);
await _insertDelay();

final actual = await FlutterVolumeController.getVolume();
expect(actual, greaterThan(before));
});

testWidgets('should lower volume', (tester) async {
const before = 0.8;

await FlutterVolumeController.setVolume(before);
await _insertDelay();

await FlutterVolumeController.lowerVolume(0.5);
await _insertDelay();

final actual = await FlutterVolumeController.getVolume();
expect(actual, lessThan(before));
});

testWidgets('should get mute', (tester) async {
final isMuted = await FlutterVolumeController.getMute();
expect(isMuted, isNotNull);
});

testWidgets('should set mute', (tester) async {
const List<bool> targets = [true, false];

for (final target in targets) {
await FlutterVolumeController.setMute(target);
await _insertDelay();

final actual = await FlutterVolumeController.getMute();
expect(actual, target);
}
});

testWidgets('should toggle mute', (tester) async {
const target = true;

await FlutterVolumeController.setMute(!target);
await _insertDelay();

await FlutterVolumeController.toggleMute();
await _insertDelay();

final actual = await FlutterVolumeController.getMute();
expect(actual, target);
});

/// TODO: add test for [FlutterVolumeController.setAndroidAudioStream].
/// TODO: add test for [FlutterVolumeController.setIOSAudioSessionCategory].
testWidgets('should receive volume event after adding listener',
(tester) async {
final List<double> targets = [0.0, 1.0, 0.0, 1.0, 0.0];
final List<double> actual = [];

await FlutterVolumeController.setVolume(targets[0]);
await _insertDelay();

FlutterVolumeController.addListener(actual.add);

for (final target in targets) {
await FlutterVolumeController.setVolume(target);
await _insertDelay();
}

expect(actual, targets);
});

testWidgets('should receive no new volume event after removing listener',
(tester) async {
final List<double> targets = [0.0, 1.0, 0.0];
final List<double> actual = [];

await FlutterVolumeController.setVolume(targets[0]);
await _insertDelay();

FlutterVolumeController.addListener(actual.add);

for (final target in targets) {
await FlutterVolumeController.setVolume(target);
await _insertDelay();
}

expect(actual, targets);

FlutterVolumeController.removeListener();

await FlutterVolumeController.setVolume(1.0);
await _insertDelay();

expect(actual, targets);
});
}

Future<void> _insertDelay() async {
await Future.delayed(const Duration(milliseconds: 50));
}
6 changes: 6 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@ PODS:
- Flutter (1.0.0)
- flutter_volume_controller (0.0.1):
- Flutter
- integration_test (0.0.1):
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_volume_controller (from `.symlinks/plugins/flutter_volume_controller/ios`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
flutter_volume_controller:
:path: ".symlinks/plugins/flutter_volume_controller/ios"
integration_test:
:path: ".symlinks/plugins/integration_test/ios"

SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_volume_controller: e4d5832f08008180f76e30faf671ffd5a425e529
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5

PODFILE CHECKSUM: ec7bdfce9f82e8314b94d9cd1cfee2974a0e1c97

Expand Down
2 changes: 1 addition & 1 deletion example/macos/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :osx, '10.11'
platform :osx, '10.14'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
6 changes: 3 additions & 3 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
flutter_volume_controller: 25d09126b0d695560f11c80b1311d5063fed882f
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24

PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c
PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7

COCOAPODS: 1.11.3
COCOAPODS: 1.11.2
9 changes: 5 additions & 4 deletions example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXAggregateTarget section */
Expand Down Expand Up @@ -273,6 +273,7 @@
};
3399D490228B24CF009A79C7 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -404,7 +405,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down Expand Up @@ -483,7 +484,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -530,7 +531,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
87 changes: 87 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
sha256: "80e5141fafcb3361653ce308776cfd7d45e6e9fbb429e14eec571382c0c5fecb"
url: "https://pub.dev"
source: hosted
version: "3.3.2"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -41,6 +49,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.17.0"
crypto:
dependency: transitive
description:
name: crypto
sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67
url: "https://pub.dev"
source: hosted
version: "3.0.2"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -57,11 +73,24 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
file:
dependency: transitive
description:
name: file
sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d"
url: "https://pub.dev"
source: hosted
version: "6.1.4"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_driver:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -90,6 +119,16 @@ packages:
relative: true
source: path
version: "1.2.3"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
integration_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
Expand Down Expand Up @@ -138,6 +177,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.8.2"
platform:
dependency: transitive
description:
name: platform
sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76"
url: "https://pub.dev"
source: hosted
version: "3.1.0"
process:
dependency: transitive
description:
name: process
sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09"
url: "https://pub.dev"
source: hosted
version: "4.2.4"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -175,6 +230,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
sync_http:
dependency: transitive
description:
name: sync_http
sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961"
url: "https://pub.dev"
source: hosted
version: "0.3.1"
term_glyph:
dependency: transitive
description:
Expand All @@ -191,6 +254,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.4.16"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
vector_math:
dependency: transitive
description:
Expand All @@ -199,6 +270,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: e7fb6c2282f7631712b69c19d1bff82f3767eea33a2321c14fa59ad67ea391c7
url: "https://pub.dev"
source: hosted
version: "9.4.0"
webdriver:
dependency: transitive
description:
name: webdriver
sha256: ef67178f0cc7e32c1494645b11639dd1335f1d18814aa8435113a92e9ef9d841
url: "https://pub.dev"
source: hosted
version: "3.0.1"
sdks:
dart: ">=2.18.0 <3.0.0"
flutter: ">=2.8.0"
3 changes: 3 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ dev_dependencies:
flutter_test:
sdk: flutter

integration_test:
sdk: flutter

# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
Expand Down

0 comments on commit cae9a43

Please sign in to comment.