TF-4136 Add config Sentry
This commit is contained in:
@@ -10,9 +10,7 @@ import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'application_manager_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([
|
||||
MockSpec<DeviceInfoPlugin>()
|
||||
])
|
||||
@GenerateNiceMocks([MockSpec<DeviceInfoPlugin>()])
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
@@ -21,55 +19,73 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
mockDeviceInfoPlugin = MockDeviceInfoPlugin();
|
||||
applicationManager = ApplicationManager(mockDeviceInfoPlugin);
|
||||
ApplicationManager.debugDeviceInfoOverride = mockDeviceInfoPlugin;
|
||||
|
||||
applicationManager = ApplicationManager();
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
ApplicationManager.debugDeviceInfoOverride = null;
|
||||
PlatformInfo.isTestingForWeb = false;
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('fk_user_agent'),
|
||||
null,
|
||||
);
|
||||
|
||||
FkUserAgent.release();
|
||||
});
|
||||
|
||||
group('ApplicationManager::getUserAgent test', () {
|
||||
test('WHEN platform is Web THEN getUserAgent should be return user agent for web', () async {
|
||||
test(
|
||||
'WHEN platform is Web THEN getUserAgent should return user agent for web',
|
||||
() async {
|
||||
const webUserAgent = 'User-Agent-Twake-Mail-Web';
|
||||
|
||||
PlatformInfo.isTestingForWeb = true;
|
||||
|
||||
when(mockDeviceInfoPlugin.webBrowserInfo)
|
||||
.thenAnswer((_) async => WebBrowserInfo(
|
||||
userAgent: webUserAgent,
|
||||
appCodeName: '',
|
||||
appName: '',
|
||||
appVersion: '',
|
||||
deviceMemory: null,
|
||||
language: '',
|
||||
languages: [],
|
||||
platform: '',
|
||||
product: '',
|
||||
productSub: '',
|
||||
vendor: '',
|
||||
vendorSub: '',
|
||||
maxTouchPoints: null,
|
||||
hardwareConcurrency: null,
|
||||
));
|
||||
when(mockDeviceInfoPlugin.webBrowserInfo).thenAnswer(
|
||||
(_) async => WebBrowserInfo(
|
||||
userAgent: webUserAgent,
|
||||
appCodeName: '',
|
||||
appName: '',
|
||||
appVersion: '',
|
||||
deviceMemory: null,
|
||||
language: '',
|
||||
languages: [],
|
||||
platform: '',
|
||||
product: '',
|
||||
productSub: '',
|
||||
vendor: '',
|
||||
vendorSub: '',
|
||||
maxTouchPoints: null,
|
||||
hardwareConcurrency: null,
|
||||
),
|
||||
);
|
||||
|
||||
final userAgent = await applicationManager.getUserAgent();
|
||||
|
||||
expect(userAgent, webUserAgent);
|
||||
|
||||
PlatformInfo.isTestingForWeb = false;
|
||||
});
|
||||
|
||||
test('WHEN platform is Android THEN getUserAgent should be return user agent for Android', () async {
|
||||
test(
|
||||
'WHEN platform is Android THEN getUserAgent should return user agent for Android',
|
||||
() async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
||||
|
||||
const androidUserAgent = 'User-Agent-Twake-Mail-Android';
|
||||
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('fk_user_agent'),
|
||||
(message) async {
|
||||
if (message.method == 'getProperties') {
|
||||
return {
|
||||
'userAgent': androidUserAgent
|
||||
};
|
||||
return {'userAgent': androidUserAgent};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
await FkUserAgent.init();
|
||||
@@ -77,42 +93,35 @@ void main() {
|
||||
final userAgent = await applicationManager.getUserAgent();
|
||||
|
||||
expect(userAgent, androidUserAgent);
|
||||
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
FkUserAgent.release();
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
const MethodChannel('fk_user_agent'),
|
||||
null);
|
||||
});
|
||||
|
||||
test('WHEN platform is Web\n'
|
||||
'AND mockDeviceInfoPlugin.webBrowserInfo throw exception\n'
|
||||
'THEN getUserAgent should be return empty string',
|
||||
() async {
|
||||
test(
|
||||
'WHEN platform is Web AND mockDeviceInfoPlugin.webBrowserInfo throws exception THEN return empty string',
|
||||
() async {
|
||||
PlatformInfo.isTestingForWeb = true;
|
||||
|
||||
when(mockDeviceInfoPlugin.webBrowserInfo).thenThrow(Exception('Failed to get web browser info'));
|
||||
when(mockDeviceInfoPlugin.webBrowserInfo)
|
||||
.thenThrow(Exception('Failed to get web browser info'));
|
||||
|
||||
final userAgent = await applicationManager.getUserAgent();
|
||||
|
||||
expect(userAgent, '');
|
||||
|
||||
PlatformInfo.isTestingForWeb = false;
|
||||
});
|
||||
|
||||
test('WHEN platform is Android\n'
|
||||
'AND FkUserAgent.userAgent return empty string\n'
|
||||
'THEN getUserAgent should be return empty string',
|
||||
() async {
|
||||
test(
|
||||
'WHEN platform is Android AND FkUserAgent.userAgent empty THEN return empty string',
|
||||
() async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('fk_user_agent'),
|
||||
(message) async {
|
||||
if (message.method == 'getProperties') {
|
||||
return {};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
await FkUserAgent.init();
|
||||
@@ -120,12 +129,6 @@ void main() {
|
||||
final userAgent = await applicationManager.getUserAgent();
|
||||
|
||||
expect(userAgent, '');
|
||||
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
FkUserAgent.release();
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
const MethodChannel('fk_user_agent'),
|
||||
null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user