Skip to content

Commit 5025e39

Browse files
Add test coverage for BugReporting
1 parent e3e339a commit 5025e39

File tree

2 files changed

+84
-6
lines changed

2 files changed

+84
-6
lines changed

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);

test/instabug_flutter_test.dart

Lines changed: 80 additions & 2 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];

0 commit comments

Comments
 (0)