Skip to content

Commit f3f0ea4

Browse files
author
Ali Abdelfattah
authored
Merge pull request #187 from Instabug/fix/specs
[MOB-5592] Increase Test Coverage by 10.52%
2 parents 2bb8fd7 + 32917db commit f3f0ea4

File tree

5 files changed

+122
-24
lines changed

5 files changed

+122
-24
lines changed

codecov.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ coverage:
88
informational: false
99

1010
codecov:
11-
require_ci_to_pass: false
11+
require_ci_to_pass: false
12+
13+
ignore:
14+
- "lib/models/"

lib/BugReporting.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// ignore_for_file: avoid_classes_with_only_static_members
22

33
import 'dart:async';
4-
import 'dart:io' show Platform;
54

65
import 'package:flutter/services.dart';
76
import 'package:instabug_flutter/Instabug.dart';
7+
import 'package:instabug_flutter/utils/platform_manager.dart';
88

99
enum InvocationOption {
1010
commentFieldRequired,
@@ -183,7 +183,7 @@ class BugReporting {
183183
/// [iPhoneShakingThreshold] iPhoneShakingThreshold double
184184
static Future<void> setShakingThresholdForiPhone(
185185
double iPhoneShakingThreshold) async {
186-
if (Platform.isIOS) {
186+
if (PlatformManager.instance.isIOS()) {
187187
final List<dynamic> params = <dynamic>[iPhoneShakingThreshold];
188188
await _channel.invokeMethod<Object>(
189189
'setShakingThresholdForiPhone:', params);
@@ -195,7 +195,7 @@ class BugReporting {
195195
/// [iPadShakingThreshold] iPhoneShakingThreshold double
196196
static Future<void> setShakingThresholdForiPad(
197197
double iPadShakingThreshold) async {
198-
if (Platform.isIOS) {
198+
if (PlatformManager.instance.isIOS()) {
199199
final List<dynamic> params = <dynamic>[iPadShakingThreshold];
200200
await _channel.invokeMethod<Object>(
201201
'setShakingThresholdForiPad:', params);
@@ -209,7 +209,7 @@ class BugReporting {
209209
/// [androidThreshold] iPhoneShakingThreshold int
210210
static Future<void> setShakingThresholdForAndroid(
211211
int androidThreshold) async {
212-
if (Platform.isAndroid) {
212+
if (PlatformManager.instance.isAndroid()) {
213213
final List<dynamic> params = <dynamic>[androidThreshold];
214214
await _channel.invokeMethod<Object>(
215215
'setShakingThresholdForAndroid:', params);

lib/Replies.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ignore_for_file: avoid_classes_with_only_static_members
22

33
import 'dart:async';
4-
import 'dart:io' show Platform;
54

65
import 'package:flutter/services.dart';
6+
import 'package:instabug_flutter/utils/platform_manager.dart';
77

88
class Replies {
99
static Function? _hasChatsCallback;
@@ -78,7 +78,7 @@ class Replies {
7878
/// [isEnabled] A boolean to set whether notifications sound should be played.
7979
/// @android ONLY
8080
static Future<void> setInAppNotificationSound(bool isEnabled) async {
81-
if (Platform.isAndroid) {
81+
if (PlatformManager.instance.isAndroid()) {
8282
final List<dynamic> params = <dynamic>[isEnabled];
8383
await _channel.invokeMethod<Object>(
8484
'setEnableInAppNotificationSound:', params);

lib/Surveys.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ignore_for_file: avoid_classes_with_only_static_members
22

33
import 'dart:async';
4-
import 'dart:io' show Platform;
54

65
import 'package:flutter/services.dart';
6+
import 'package:instabug_flutter/utils/platform_manager.dart';
77

88
class Surveys {
99
static Function? _onShowCallback;
@@ -131,7 +131,7 @@ class Surveys {
131131
/// NPS Surveys or AppRating Surveys to AppStore to let users rate your app on AppStore itself.
132132
/// [appStoreURL] A String url for the published iOS app on AppStore
133133
static Future<void> setAppStoreURL(String appStoreURL) async {
134-
if (Platform.isIOS) {
134+
if (PlatformManager.instance.isIOS()) {
135135
final List<dynamic> params = <dynamic>[appStoreURL];
136136
await _channel.invokeMethod<Object>('setAppStoreURL:', params);
137137
}

test/instabug_flutter_test.dart

Lines changed: 110 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ void main() {
6868
log.clear();
6969
});
7070

71-
test('startWithToken:invocationEvents: should be called on iOS',
72-
() async {
71+
test('startWithToken:invocationEvents: should be called on iOS', () async {
7372
when(mockPlatform.isIOS()).thenAnswer((_) => true);
7473

7574
Instabug.start(appToken, invocationEvents);
@@ -433,6 +432,51 @@ void main() {
433432
]);
434433
});
435434

435+
test('setShakingThresholdForiPhone: Test', () async {
436+
const iPhoneShakingThreshold = 1.6;
437+
final List<dynamic> args = <dynamic>[iPhoneShakingThreshold];
438+
439+
when(mockPlatform.isIOS()).thenAnswer((_) => true);
440+
441+
BugReporting.setShakingThresholdForiPhone(iPhoneShakingThreshold);
442+
expect(log, <Matcher>[
443+
isMethodCall(
444+
'setShakingThresholdForiPhone:',
445+
arguments: args,
446+
)
447+
]);
448+
});
449+
450+
test('setShakingThresholdForiPad: Test', () async {
451+
const iPadShakingThreshold = 1.6;
452+
final List<dynamic> args = <dynamic>[iPadShakingThreshold];
453+
454+
when(mockPlatform.isIOS()).thenAnswer((_) => true);
455+
456+
BugReporting.setShakingThresholdForiPad(iPadShakingThreshold);
457+
expect(log, <Matcher>[
458+
isMethodCall(
459+
'setShakingThresholdForiPad:',
460+
arguments: args,
461+
)
462+
]);
463+
});
464+
465+
test('setShakingThresholdForAndroid: Test', () async {
466+
const androidThreshold = 1000;
467+
final List<dynamic> args = <dynamic>[androidThreshold];
468+
469+
when(mockPlatform.isAndroid()).thenAnswer((_) => true);
470+
471+
BugReporting.setShakingThresholdForAndroid(androidThreshold);
472+
expect(log, <Matcher>[
473+
isMethodCall(
474+
'setShakingThresholdForAndroid:',
475+
arguments: args,
476+
)
477+
]);
478+
});
479+
436480
test('setOnInvokeCallback Test', () async {
437481
BugReporting.setOnInvokeCallback(() => () {});
438482
expect(log, <Matcher>[
@@ -467,6 +511,17 @@ void main() {
467511
]);
468512
});
469513

514+
test('setInvocationEvents Test', () async {
515+
BugReporting.setInvocationEvents(null);
516+
final List<dynamic> args = <dynamic>[<String>[]];
517+
expect(log, <Matcher>[
518+
isMethodCall(
519+
'setInvocationEvents:',
520+
arguments: args,
521+
)
522+
]);
523+
});
524+
470525
test(
471526
'setEnabledAttachmentTypes:extraScreenShot:galleryImage:screenRecording: Test',
472527
() async {
@@ -521,6 +576,17 @@ void main() {
521576
]);
522577
});
523578

579+
test('setInvocationOptions Test: empty', () async {
580+
BugReporting.setInvocationOptions(null);
581+
final List<dynamic> args = <dynamic>[<String>[]];
582+
expect(log, <Matcher>[
583+
isMethodCall(
584+
'setInvocationOptions:',
585+
arguments: args,
586+
)
587+
]);
588+
});
589+
524590
test('showBugReportingWithReportTypeAndOptions:options Test', () async {
525591
BugReporting.show(
526592
ReportType.bug, <InvocationOption>[InvocationOption.emailFieldHidden]);
@@ -536,6 +602,18 @@ void main() {
536602
]);
537603
});
538604

605+
test('showBugReportingWithReportTypeAndOptions:options Test: empty options',
606+
() async {
607+
BugReporting.show(ReportType.bug, null);
608+
final List<dynamic> args = <dynamic>[ReportType.bug.toString(), <String>[]];
609+
expect(log, <Matcher>[
610+
isMethodCall(
611+
'showBugReportingWithReportTypeAndOptions:options:',
612+
arguments: args,
613+
)
614+
]);
615+
});
616+
539617
test('setSurveysEnabled: Test', () async {
540618
const isEnabled = false;
541619
final List<dynamic> args = <dynamic>[isEnabled];
@@ -626,6 +704,21 @@ void main() {
626704
]);
627705
});
628706

707+
test('setAppStoreURL Test', () async {
708+
const appStoreURL = 'appStoreURL';
709+
final List<dynamic> args = <dynamic>[appStoreURL];
710+
711+
when(mockPlatform.isIOS()).thenAnswer((_) => true);
712+
713+
Surveys.setAppStoreURL(appStoreURL);
714+
expect(log, <Matcher>[
715+
isMethodCall(
716+
'setAppStoreURL:',
717+
arguments: args,
718+
)
719+
]);
720+
});
721+
629722
test('showFeatureRequests Test', () async {
630723
FeatureRequests.show();
631724
expect(
@@ -677,6 +770,21 @@ void main() {
677770
]);
678771
});
679772

773+
test('setInAppNotificationSound: Test', () async {
774+
const isEnabled = false;
775+
final List<dynamic> args = <dynamic>[isEnabled];
776+
777+
when(mockPlatform.isAndroid()).thenAnswer((_) => true);
778+
779+
Replies.setInAppNotificationSound(isEnabled);
780+
expect(log, <Matcher>[
781+
isMethodCall(
782+
'setEnableInAppNotificationSound:',
783+
arguments: args,
784+
)
785+
]);
786+
});
787+
680788
test('showReplies Test', () async {
681789
Replies.show();
682790
expect(log, <Matcher>[isMethodCall('showReplies', arguments: null)]);
@@ -751,17 +859,4 @@ void main() {
751859
]);
752860
}
753861
});
754-
755-
///Since the below method only runs on android and has the [Platform.isAndroid] condition in it, it will fail when running outside android,
756-
/// therefore its commented.
757-
// test('setEnableInAppNotificationSound: Test', () async {
758-
// bool isEnabled = false;
759-
// final List<dynamic> args = <dynamic>[isEnabled];
760-
// Replies.setInAppNotificationSound(isEnabled);
761-
// expect(log, <Matcher>[
762-
// isMethodCall('setEnableInAppNotificationSound:',
763-
// arguments: args,
764-
// )
765-
// ]);
766-
// });
767862
}

0 commit comments

Comments
 (0)