From e17cbab81d233ee5018617907ca8fe486cbbd81c Mon Sep 17 00:00:00 2001 From: zhu-xiaowei Date: Thu, 11 Apr 2024 14:34:09 +0800 Subject: [PATCH] tests: add case for ClickstreamInterface UnimplementedError --- ...tream_flutter_platform_interface_test.dart | 85 +++++++++++++++++++ test/mock_method_channel.dart | 63 ++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 test/clickstream_flutter_platform_interface_test.dart create mode 100644 test/mock_method_channel.dart diff --git a/test/clickstream_flutter_platform_interface_test.dart b/test/clickstream_flutter_platform_interface_test.dart new file mode 100644 index 0000000..8210d81 --- /dev/null +++ b/test/clickstream_flutter_platform_interface_test.dart @@ -0,0 +1,85 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import 'package:flutter_test/flutter_test.dart'; + +import 'mock_method_channel.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + MockMethodChannel platform = MockMethodChannel(); + + test('init method for UnimplementedError', () async { + Map initConfig = { + 'appId': 'testApp', + 'endpoint': "", + }; + expect(() async { + await platform.init(initConfig); + }, throwsA(isInstanceOf())); + }); + + test('record method for UnimplementedError', () async { + Map attributes = { + "category": "shoes", + "currency": "CNY", + "value": 279.9 + }; + expect(platform.record(attributes), + throwsA(isInstanceOf())); + }); + + test('setUserId method for UnimplementedError', () async { + Map attributes = { + "userId": "1234", + }; + expect(platform.setUserId(attributes), + throwsA(isInstanceOf())); + }); + + test('setUserAttributes method for UnimplementedError', () async { + Map attributes = {"_user_age": 21, "_user_name": "carl"}; + expect(platform.setUserAttributes(attributes), + throwsA(isInstanceOf())); + }); + + test('addGlobalAttributes method for UnimplementedError', () async { + Map attributes = { + "channel": "Play Store", + "level": 5.1, + "class": 6 + }; + expect(platform.addGlobalAttributes(attributes), + throwsA(isInstanceOf())); + }); + + test('deleteGlobalAttributes method for UnimplementedError', () async { + Map attributes = { + "attributes": ["attr1", "attr2"], + }; + expect(platform.deleteGlobalAttributes(attributes), + throwsA(isInstanceOf())); + }); + + test('updateConfigure method for UnimplementedError', () async { + Map attributes = { + "appId": "newAppId", + "endpoint": "https://example.com/collect", + }; + expect(platform.updateConfigure(attributes), + throwsA(isInstanceOf())); + }); + + test('flushEvents method for UnimplementedError', () async { + expect(platform.flushEvents(), throwsA(isInstanceOf())); + }); + + test('disable method for UnimplementedError', () async { + expect(platform.disable(), throwsA(isInstanceOf())); + }); + + test('enable method for UnimplementedError', () async { + expect(platform.enable(), throwsA(isInstanceOf())); + }); +} diff --git a/test/mock_method_channel.dart b/test/mock_method_channel.dart new file mode 100644 index 0000000..e09c6be --- /dev/null +++ b/test/mock_method_channel.dart @@ -0,0 +1,63 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import 'package:clickstream_analytics/clickstream_analytics_platform_interface.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +/// An implementation of [ClickstreamFlutterPlatform] that uses method channels. +class MockMethodChannel extends ClickstreamInterface { + /// The method channel used to interact with the native platform. + @visibleForTesting + final methodChannel = const MethodChannel('clickstream_flutter'); + + @override + Future init(Map configure) async { + return super.init(configure); + } + + @override + Future record(Map attributes) async { + return super.record(attributes); + } + + @override + Future setUserId(Map userId) async { + return super.setUserId(userId); + } + + @override + Future setUserAttributes(Map attributes) async { + return super.setUserAttributes(attributes); + } + + @override + Future addGlobalAttributes(Map attributes) async { + return super.addGlobalAttributes(attributes); + } + + @override + Future deleteGlobalAttributes(Map attributes) async { + return super.deleteGlobalAttributes(attributes); + } + + @override + Future updateConfigure(Map configure) async { + return super.updateConfigure(configure); + } + + @override + Future flushEvents() async { + return super.flushEvents(); + } + + @override + Future disable() async { + return super.disable(); + } + + @override + Future enable() async { + return super.enable(); + } +}