Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve noted issues #780

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/at_backupkey_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class _MyAppState extends State<MyApp> {
Future<AtClientPreference> futurePreference = loadAtClientPreference();
AtClientPreference? atClientPreference;


@override
Widget build(BuildContext context) {
return StreamBuilder<ThemeMode>(
Expand All @@ -55,17 +54,17 @@ class _MyAppState extends State<MyApp> {
primaryColor: const Color(0xFFf4533d),
colorScheme: ThemeData.light().colorScheme.copyWith(
primary: const Color(0xFFf4533d),
background: Colors.white,
),
backgroundColor: Colors.white,
scaffoldBackgroundColor: Colors.white,
),
darkTheme: ThemeData().copyWith(
brightness: Brightness.dark,
primaryColor: Colors.blue,
colorScheme: ThemeData.dark().colorScheme.copyWith(
primary: Colors.blue,
background: Colors.grey[850],
),
backgroundColor: Colors.grey[850],
scaffoldBackgroundColor: Colors.grey[850],
),
themeMode: themeMode,
Expand Down Expand Up @@ -188,15 +187,17 @@ class _HomeScreenState extends State<HomeScreen> {
/// Use the AtClientManager instance to get the current atsign
Text(
'Current @sign: ${atClientManager.atClient.getCurrentAtSign()}'),

ElevatedButton.icon(
icon: const Icon(
Icons.file_copy,
color: Colors.white,
),
label: const Text('Backup your key'),
onPressed: () async {
BackupKeyWidget(atsign: atClientManager.atClient.getCurrentAtSign() ?? '')
BackupKeyWidget(
atsign:
atClientManager.atClient.getCurrentAtSign() ?? '')
.showBackupDialog(context);
},
),
Expand Down
6 changes: 4 additions & 2 deletions packages/at_backupkey_flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ environment:

dependencies:
at_app_flutter: ^5.2.0
at_backupkey_flutter:
path: ../
at_client_mobile: ^3.2.12
at_onboarding_flutter: ^6.1.3
cupertino_icons: ^1.0.6
Expand All @@ -24,6 +22,10 @@ dependencies:
dev_dependencies:
flutter_lints: ^2.0.3

dependency_overrides:
at_backupkey_flutter:
path: ../

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
Expand Down
16 changes: 12 additions & 4 deletions packages/at_backupkey_flutter/test/at_backupkey_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();

setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return '42';
});
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
channel,
(MethodCall methodCall) async {
return '42';
},
);
});

tearDown(() {
channel.setMockMethodCallHandler(null);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
channel,
null,
);
});
}
31 changes: 17 additions & 14 deletions packages/at_backupkey_flutter/test/backupkey_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,46 @@ void main() {

group('Fetching AESKey', () {
test('for registered @sign', () async {
MockDataService _mockDataService = MockDataService(atsign);
String aesKey = _mockDataService.getAESKey;
MockDataService mockDataService = MockDataService(atsign);
String aesKey = mockDataService.getAESKey;
expect(aesKey.length == 44, true);
});

test('for unregistered @sign', () async {
MockDataService _mockDataService = MockDataService(atsign + '123');
String? aesKey = _mockDataService.getAESKey;
MockDataService mockDataService = MockDataService('${atsign}123');
String? aesKey = mockDataService.getAESKey;
expect(aesKey, null);
});
});

group('Fetch EncryptedKeys', () {
test('for registerd @sign', () async {
MockDataService _mockDataService = MockDataService(atsign);
var map = _mockDataService.getEncryptedKeys();
MockDataService mockDataService = MockDataService(atsign);
var map = mockDataService.getEncryptedKeys();
expect(map.length, greaterThan(0));
});

test('for unregisterd @sign', () async {
MockDataService _mockDataService = MockDataService(atsign + '123');
var map = _mockDataService.getEncryptedKeys();
MockDataService mockDataService = MockDataService('${atsign}123');
var map = mockDataService.getEncryptedKeys();
expect(map, {});
});
});

group('generate backupkey file', () {
test('for registered @sign', () async {
MockDataService _mockDataService = MockDataService(atsign);
var aesEncryptedKeys = _mockDataService.getEncryptedKeys();
MockDataService mockDataService = MockDataService(atsign);
var aesEncryptedKeys = mockDataService.getEncryptedKeys();
expect(aesEncryptedKeys.isNotEmpty, true);
var result = await _generateFile(atsign, aesEncryptedKeys);
expect(result, true);
expect(await File('test/backup/${atsign}_key.atKeys').exists(), true);
});

test('for unregistered @sign', () async {
String atSign = atsign + '123';
MockDataService _mockDataService = MockDataService(atSign);
var aesEncryptedKeys = _mockDataService.getEncryptedKeys();
String atSign = '${atsign}123';
MockDataService mockDataService = MockDataService(atSign);
var aesEncryptedKeys = mockDataService.getEncryptedKeys();
expect(aesEncryptedKeys.isNotEmpty, false);
var result = await _generateFile(atSign, aesEncryptedKeys);
expect(result, false);
Expand Down Expand Up @@ -82,7 +82,9 @@ Future<void> setUpFunc(String atsign) async {

// To setup encryption keys
await atClient.getLocalSecondary()!.putValue(
AT_ENCRYPTION_PRIVATE_KEY, demo_data.encryptionPrivateKeyMap[atsign]!);
AtConstants.atEncryptionPrivateKey,
demo_data.encryptionPrivateKeyMap[atsign]!,
);
}

AtClientPreference getAtSignPreference(String atsign) {
Expand Down Expand Up @@ -113,6 +115,7 @@ class MockDataService {
late String atsign;

MockDataService(this.atsign);

get getAESKey => demo_data.aesKeyMap[atsign];

Map<String, String> getEncryptedKeys() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
Widget _wrapWidgetWithMaterialApp({required Widget backupKeyWidget}) {
Widget wrapWidgetWithMaterialApp({required Widget backupKeyWidget}) {
return TestMaterialApp(
home: Builder(
builder: (BuildContext context) {
Expand All @@ -28,31 +28,31 @@ void main() {
// Test case to check backupkey widget is displayed
testWidgets('BackupKey widget is used', (WidgetTester tester) async {
await tester.pumpWidget(
_wrapWidgetWithMaterialApp(backupKeyWidget: backupKeyWidget));
wrapWidgetWithMaterialApp(backupKeyWidget: backupKeyWidget));
expect(find.byType(BackupKeyWidget), findsOneWidget);
});
// Test case to identify atsign text
testWidgets("Identify atsign text", (WidgetTester tester) async {
await tester.pumpWidget(
_wrapWidgetWithMaterialApp(backupKeyWidget: backupKeyWidget));
wrapWidgetWithMaterialApp(backupKeyWidget: backupKeyWidget));
expect(backupKeyWidget.atsign, 'bluebellrelated86');
});
// Test case to identify button text
testWidgets("Identify button text", (WidgetTester tester) async {
await tester.pumpWidget(
_wrapWidgetWithMaterialApp(backupKeyWidget: backupKeyWidget));
wrapWidgetWithMaterialApp(backupKeyWidget: backupKeyWidget));
expect(backupKeyWidget.buttonText, 'Click here');
});
// Test case to check icon Color
testWidgets('Test case to check icon color', (WidgetTester tester) async {
await tester.pumpWidget(
_wrapWidgetWithMaterialApp(backupKeyWidget: backupKeyWidget));
wrapWidgetWithMaterialApp(backupKeyWidget: backupKeyWidget));
expect(backupKeyWidget.iconColor, Colors.purple);
});
// Test case to check button Color
testWidgets('Test case to check button color', (WidgetTester tester) async {
await tester.pumpWidget(
_wrapWidgetWithMaterialApp(backupKeyWidget: backupKeyWidget));
wrapWidgetWithMaterialApp(backupKeyWidget: backupKeyWidget));
expect(backupKeyWidget.buttonColor, Colors.white);
});
});
Expand Down
85 changes: 46 additions & 39 deletions packages/at_chat_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';

import 'package:at_chat_flutter_example/second_screen.dart';
import 'package:flutter/material.dart';
import 'package:at_client_mobile/at_client_mobile.dart';
import 'package:at_onboarding_flutter/at_onboarding_flutter.dart';
import 'package:at_utils/at_logger.dart' show AtSignLogger;
import 'package:path_provider/path_provider.dart'
Expand All @@ -27,8 +26,9 @@ Future<AtClientPreference> loadAtClientPreference() async {

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);

@override
_MyAppState createState() => _MyAppState();
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
Expand Down Expand Up @@ -70,44 +70,51 @@ class _MyAppState extends State<MyApp> {
setState(() {
atClientPreference = preference;
});
final result = await AtOnboarding.onboard(
context: context,
config: AtOnboardingConfig(
atClientPreference: atClientPreference!,
domain: AtEnv.rootDomain,
appAPIKey: '477b-876u-bcez-c42z-6a3d',
rootEnvironment: AtEnv.rootEnvironment,
),
);
switch (result.status) {
case AtOnboardingResultStatus.success:
await Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => const SecondScreen(),
));
break;
case AtOnboardingResultStatus.error:
_logger.severe(
'Onboarding throws ${result.errorCode} error');
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: const Text('Something went wrong'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('ok'))
],
if (mounted) {
final result = await AtOnboarding.onboard(
context: context,
config: AtOnboardingConfig(
atClientPreference: atClientPreference!,
domain: AtEnv.rootDomain,
appAPIKey: '477b-876u-bcez-c42z-6a3d',
rootEnvironment: AtEnv.rootEnvironment,
),
);

switch (result.status) {
case AtOnboardingResultStatus.success:
if (mounted) {
await Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => const SecondScreen(),
));
}
break;
case AtOnboardingResultStatus.error:
_logger.severe(
'Onboarding throws ${result.errorCode} error');
if (mounted) {
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: const Text('Something went wrong'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('ok'))
],
);
},
);
},
);
break;
case AtOnboardingResultStatus.cancel:
break;
}
break;
case AtOnboardingResultStatus.cancel:
break;
}
}
},
child: const Text('Start onboarding'),
Expand Down
11 changes: 6 additions & 5 deletions packages/at_chat_flutter/example/lib/second_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SecondScreen extends StatefulWidget {
const SecondScreen({Key? key}) : super(key: key);

@override
_SecondScreenState createState() => _SecondScreenState();
State<SecondScreen> createState() => _SecondScreenState();
}

class _SecondScreenState extends State<SecondScreen> {
Expand All @@ -26,6 +26,7 @@ class _SecondScreenState extends State<SecondScreen> {

/// Get the AtClientManager instance
var atClientManager = AtClientManager.getInstance();

@override
void initState() {
getAtSignAndInitializeChat();
Expand Down Expand Up @@ -222,8 +223,8 @@ class _SecondScreenState extends State<SecondScreen> {
if (member1.trim() != '' && member2.trim() != '' && groupId != '') {
setChatWithAtSign(null, isGroup: true, groupId: groupId, groupMembers: [
activeAtSign!,
member1.startsWith('@') ? member1 : '@' + member1,
member2.startsWith('@') ? member2 : '@' + member2
member1.startsWith('@') ? member1 : '@$member1',
member2.startsWith('@') ? member2 : '@$member2'
]);
Navigator.push(context,
MaterialPageRoute(builder: (context) => const ThirdScreen()));
Expand All @@ -238,8 +239,8 @@ class _SecondScreenState extends State<SecondScreen> {
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Row(
children: const [Text('Some details are missing!')],
title: const Row(
children: [Text('Some details are missing!')],
),
content: const Text('Please enter all fields'),
actions: <Widget>[
Expand Down
8 changes: 5 additions & 3 deletions packages/at_chat_flutter/example/lib/third_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ThirdScreen extends StatefulWidget {
const ThirdScreen({Key? key}) : super(key: key);

@override
_ThirdScreenState createState() => _ThirdScreenState();
State<ThirdScreen> createState() => _ThirdScreenState();
}

class _ThirdScreenState extends State<ThirdScreen> {
Expand All @@ -28,8 +28,10 @@ class _ThirdScreenState extends State<ThirdScreen> {

var result = await deleteMessages();
var message = result ? 'Messages are deleted' : 'Failed to delete';
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(message)));
if (mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(message)));
}
},
),
]),
Expand Down
Loading