Initial commit
This commit is contained in:
6
integration_test/.gitignore
vendored
Normal file
6
integration_test/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
synapse/data/homeserver.db
|
||||
dendrite/data/server.*
|
||||
dendrite/data/matrix_key.pem
|
||||
dendrite/data/logs
|
||||
dendrite/data/jetstream
|
||||
dendrite/data/*.db
|
||||
19
integration_test/data/environment_constants.dart
Normal file
19
integration_test/data/environment_constants.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
const homeserver = String.fromEnvironment(
|
||||
'HOMESERVER',
|
||||
defaultValue: '10.0.2.2',
|
||||
);
|
||||
const user1Name = String.fromEnvironment('USER1_NAME', defaultValue: 'alice');
|
||||
const user1Pw = String.fromEnvironment(
|
||||
'USER1_PW',
|
||||
defaultValue: 'AliceInWonderland',
|
||||
);
|
||||
const user2Name = String.fromEnvironment('USER2_NAME', defaultValue: 'bob');
|
||||
const user2Pw = String.fromEnvironment(
|
||||
'USER2_PW',
|
||||
defaultValue: 'JoWirSchaffenDas',
|
||||
);
|
||||
|
||||
const passphrase1 = String.fromEnvironment(
|
||||
'PASSPHRASE_1',
|
||||
defaultValue: '1234567890aB%',
|
||||
);
|
||||
5
integration_test/data/integration_users.env
Normal file
5
integration_test/data/integration_users.env
Normal file
@@ -0,0 +1,5 @@
|
||||
HOMESERVER=localhost
|
||||
USER1_NAME=alice
|
||||
USER1_PW=AliceInWonderland
|
||||
USER2_NAME=bob
|
||||
USER2_PW=JoWirSchaffenDas
|
||||
75
integration_test/flows/auth_flows.dart
Normal file
75
integration_test/flows/auth_flows.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
|
||||
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'package:tatchat/pages/sign_in/view_model/model/public_homeserver_data.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../data/environment_constants.dart';
|
||||
import '../utils/tatu_chat_tester.dart';
|
||||
|
||||
Future<void> finalLogout(WidgetTester widgetTester) =>
|
||||
widgetTester.startTatuChatTest().then((tester) => tester.logout());
|
||||
|
||||
extension AuthFlows on TatuChatTester {
|
||||
Future<void> initCryptoIdentity({String username = user1Name}) async {
|
||||
final passphrase = userPassphrases[username];
|
||||
if (passphrase != null) {
|
||||
await waitFor('Restore Crypto Identity');
|
||||
await enterText(TextField, passphrase);
|
||||
await tapOn('Unlock');
|
||||
} else {
|
||||
await waitFor('Set Up Crypto Identity');
|
||||
await enterText(TextField, passphrase1, index: 0);
|
||||
await enterText(TextField, passphrase1, index: 1);
|
||||
await tapOn('Continue');
|
||||
await tapOn('Continue');
|
||||
userPassphrases[username] = passphrase1;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> login({
|
||||
String username = user1Name,
|
||||
String password = user1Pw,
|
||||
}) async {
|
||||
await waitFor('Sign in');
|
||||
await tapOn('Sign in');
|
||||
await enterText(TextField, 'http://$homeserver', index: 0);
|
||||
await tapOn(RadioListTile<PublicHomeserverData>, index: 0);
|
||||
await tapOn('Continue');
|
||||
await waitFor('Log in to http://$homeserver');
|
||||
await enterText(TextField, username, index: 0);
|
||||
await enterText(TextField, password, index: 1);
|
||||
await tapOn('Login');
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
await ensureLoggedIn();
|
||||
await tapOn(Key('accounts_and_settings_buttons'));
|
||||
await tapOn('Settings');
|
||||
await scrollUntilVisible('Logout');
|
||||
await tapOn('Logout');
|
||||
await tapOn(Key('ok_cancel_alert_dialog_ok_button'));
|
||||
await waitFor('Sign in');
|
||||
}
|
||||
|
||||
Future<void> skipNoNotificationsDialog() async {
|
||||
if (await isVisible('Push notifications not available')) {
|
||||
await tapOn('Do not show again');
|
||||
}
|
||||
}
|
||||
|
||||
static final Map<String, String> userPassphrases = {};
|
||||
|
||||
Future<bool> ensureLoggedIn() async {
|
||||
if (await isVisible('Sign in') == false) return false;
|
||||
|
||||
await login();
|
||||
await initCryptoIdentity();
|
||||
|
||||
await skipNoNotificationsDialog();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
29
integration_test/flows/basic_messaging.dart
Normal file
29
integration_test/flows/basic_messaging.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
|
||||
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../utils/tatu_chat_tester.dart';
|
||||
import 'auth_flows.dart';
|
||||
import 'chat_flows.dart';
|
||||
|
||||
Future<void> basicMessaging(WidgetTester widgetTester) => widgetTester
|
||||
.startTatuChatTest()
|
||||
.then((tester) => tester._basicMessaging());
|
||||
|
||||
extension on TatuChatTester {
|
||||
Future<void> _basicMessaging() async {
|
||||
await ensureLoggedIn();
|
||||
await ensureGroupChatCreated();
|
||||
|
||||
await tapOn(ChatFlows.groupChatName);
|
||||
const testMessage = 'Hello from integration test!';
|
||||
await enterText(Key('chat_input_field'), testMessage);
|
||||
await tapOn(Key('send_button'));
|
||||
await waitFor(testMessage);
|
||||
await goBack();
|
||||
}
|
||||
}
|
||||
42
integration_test/flows/chat_flows.dart
Normal file
42
integration_test/flows/chat_flows.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
|
||||
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'package:tatchat/pages/chat_list/chat_list.dart';
|
||||
import 'package:tatchat/widgets/chat_settings_popup_menu.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../utils/tatu_chat_tester.dart';
|
||||
import 'auth_flows.dart';
|
||||
|
||||
Future<void> archiveChats(WidgetTester widgetTester) =>
|
||||
widgetTester.startTatuChatTest().then((tester) => tester._archiveChats());
|
||||
|
||||
extension ChatFlows on TatuChatTester {
|
||||
static const String groupChatName = 'Test Group 01';
|
||||
|
||||
Future<void> ensureGroupChatCreated() async {
|
||||
if (await isVisible(groupChatName)) return;
|
||||
await tapOn(FloatingActionButton);
|
||||
await tapOn('Create group');
|
||||
await enterText(TextField, groupChatName);
|
||||
await scrollUntilVisible('Create a group and invite users');
|
||||
await tapOn('Create a group and invite users');
|
||||
await waitFor('Invite contact');
|
||||
await goBack();
|
||||
await goBack();
|
||||
}
|
||||
|
||||
Future<void> _archiveChats() async {
|
||||
await ensureLoggedIn();
|
||||
await ensureGroupChatCreated();
|
||||
await tapOn(groupChatName);
|
||||
await tapOn(ChatSettingsPopupMenu);
|
||||
await tapOn('Leave');
|
||||
await waitFor('Are you sure?');
|
||||
await tapOn('Leave');
|
||||
await waitFor(ChatList);
|
||||
}
|
||||
}
|
||||
64
integration_test/flows/login_and_chat_backup.dart
Normal file
64
integration_test/flows/login_and_chat_backup.dart
Normal file
@@ -0,0 +1,64 @@
|
||||
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
|
||||
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'package:tatchat/widgets/adaptive_dialogs/dialog_text_field.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../data/environment_constants.dart';
|
||||
import '../utils/tatu_chat_tester.dart';
|
||||
import 'auth_flows.dart';
|
||||
|
||||
Future<void> loginAndChatBackup(WidgetTester widgetTester) => widgetTester
|
||||
.startTatuChatTest()
|
||||
.then((tester) => tester._loginAndChatBackup());
|
||||
|
||||
extension on TatuChatTester {
|
||||
Future<void> _loginAndChatBackup() async {
|
||||
// Set up with only recovery key:
|
||||
await login();
|
||||
await tapOn('Skip', pumpAndSettle: false);
|
||||
await tapOn('Store in Android KeyStore');
|
||||
await tapOn('Continue');
|
||||
await skipNoNotificationsDialog();
|
||||
await logout();
|
||||
|
||||
// Restore with recovery key from keystore:
|
||||
await login();
|
||||
await tapOn('Unlock');
|
||||
await skipNoNotificationsDialog();
|
||||
await logout();
|
||||
|
||||
// Reset with passphrase:
|
||||
await login();
|
||||
await waitFor('Restore Crypto Identity');
|
||||
await tapOn('Reset account');
|
||||
await tapOn('Reset account', index: 1);
|
||||
await enterText(TextField, passphrase1, index: 0);
|
||||
await enterText(TextField, passphrase1, index: 1);
|
||||
await tapOn('Continue', pumpAndSettle: false);
|
||||
await waitFor('Please enter your password');
|
||||
await enterText(DialogTextField, user1Pw, pumpAndSettle: false);
|
||||
await tapOn('Ok');
|
||||
await tapOn('Continue');
|
||||
AuthFlows.userPassphrases[user1Name] = passphrase1;
|
||||
await logout();
|
||||
|
||||
// Restore with passphrase:
|
||||
await ensureLoggedIn();
|
||||
|
||||
// Reset passphrase
|
||||
await tapOn(Key('accounts_and_settings_buttons'));
|
||||
await tapOn('Settings');
|
||||
await tapOn('Chat backup');
|
||||
await tapOn('Reset recovery key');
|
||||
await enterText(TextField, passphrase1, index: 0);
|
||||
await enterText(TextField, passphrase1, index: 1);
|
||||
await tapOn('Continue', pumpAndSettle: false);
|
||||
await waitFor('You are ready to start!');
|
||||
await tapOn('Continue');
|
||||
AuthFlows.userPassphrases[user1Name] = passphrase1;
|
||||
}
|
||||
}
|
||||
37
integration_test/flows/multi_account.dart
Normal file
37
integration_test/flows/multi_account.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
|
||||
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
import '../data/environment_constants.dart';
|
||||
import '../utils/tatu_chat_tester.dart';
|
||||
import 'auth_flows.dart';
|
||||
|
||||
Future<void> multiAccount(WidgetTester widgetTester) => widgetTester
|
||||
.startTatuChatTest()
|
||||
.then((tester) => tester._multiAccountAndNotifications());
|
||||
|
||||
extension on TatuChatTester {
|
||||
Future<void> _multiAccountAndNotifications() async {
|
||||
await ensureLoggedIn();
|
||||
|
||||
// Login user 2
|
||||
await tapOn(Key('accounts_and_settings_buttons'));
|
||||
await tapOn('Add account');
|
||||
await login(username: user2Name, password: user2Pw);
|
||||
await initCryptoIdentity(username: user2Name);
|
||||
|
||||
// Logout user 2
|
||||
await tapOn(Key('accounts_and_settings_buttons'));
|
||||
await tapOn(user2Name);
|
||||
await tapOn(Key('accounts_and_settings_buttons'));
|
||||
await tapOn('Settings');
|
||||
await scrollUntilVisible('Logout');
|
||||
await tapOn('Logout');
|
||||
await tapOn(Key('ok_cancel_alert_dialog_ok_button'));
|
||||
await waitFor('One of your clients has been logged out');
|
||||
}
|
||||
}
|
||||
25
integration_test/mobile_test.dart
Normal file
25
integration_test/mobile_test.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
|
||||
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
|
||||
import 'flows/auth_flows.dart';
|
||||
import 'flows/basic_messaging.dart';
|
||||
import 'flows/chat_flows.dart';
|
||||
import 'flows/login_and_chat_backup.dart';
|
||||
import 'flows/multi_account.dart';
|
||||
|
||||
void main() {
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('FluffyChat Integration Tests', () {
|
||||
testWidgets('Login and logout flow', loginAndChatBackup);
|
||||
testWidgets('Basic Messaging', basicMessaging);
|
||||
testWidgets('Multi-Account', multiAccount);
|
||||
testWidgets('Archive chats', archiveChats);
|
||||
testWidgets('Final logout', finalLogout);
|
||||
});
|
||||
}
|
||||
2781
integration_test/synapse/data/homeserver.yaml
Normal file
2781
integration_test/synapse/data/homeserver.yaml
Normal file
File diff suppressed because it is too large
Load Diff
27
integration_test/synapse/data/localhost.log.config
Normal file
27
integration_test/synapse/data/localhost.log.config
Normal file
@@ -0,0 +1,27 @@
|
||||
version: 1
|
||||
|
||||
formatters:
|
||||
precise:
|
||||
format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
|
||||
|
||||
handlers:
|
||||
|
||||
|
||||
console:
|
||||
class: logging.StreamHandler
|
||||
formatter: precise
|
||||
|
||||
loggers:
|
||||
synapse.storage.SQL:
|
||||
# beware: increasing this to DEBUG will make synapse log sensitive
|
||||
# information such as access tokens.
|
||||
level: INFO
|
||||
|
||||
root:
|
||||
level: INFO
|
||||
|
||||
|
||||
handlers: [console]
|
||||
|
||||
|
||||
disable_existing_loggers: false
|
||||
1
integration_test/synapse/data/localhost.signing.key
Normal file
1
integration_test/synapse/data/localhost.signing.key
Normal file
@@ -0,0 +1 @@
|
||||
ed25519 a_SLrz 0Ho/81rZZve88zdRxhaXWHUT6K3OqzmP35rNMZBUr6I
|
||||
128
integration_test/utils/tatu_chat_tester.dart
Normal file
128
integration_test/utils/tatu_chat_tester.dart
Normal file
@@ -0,0 +1,128 @@
|
||||
// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
|
||||
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'package:tatchat/main.dart' as app;
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
extension type TatuChatTester(WidgetTester tester) {
|
||||
static int _printCounter = 1;
|
||||
|
||||
void _print(String message) {
|
||||
debugPrint(
|
||||
'[INTEGRATION TEST] ${DateTime.now().toIso8601String()} | Step ${_printCounter++} - $message',
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> isVisible(
|
||||
Object object, {
|
||||
Duration timeout = const Duration(seconds: 3),
|
||||
}) async {
|
||||
final end = DateTime.now().add(timeout);
|
||||
while (object.toFinder().evaluate().isEmpty) {
|
||||
if (DateTime.now().isAfter(end)) {
|
||||
return false;
|
||||
}
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> waitFor(
|
||||
Object object, {
|
||||
Duration timeout = const Duration(seconds: 30),
|
||||
}) async {
|
||||
_print('👀 Waiting for "$object" (${timeout.inSeconds}s)');
|
||||
final end = DateTime.now().add(timeout);
|
||||
while (object.toFinder().evaluate().isEmpty) {
|
||||
if (DateTime.now().isAfter(end)) {
|
||||
throw Exception('⏱️ Timed out waiting for "$object"!');
|
||||
}
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
}
|
||||
}
|
||||
|
||||
Future<Finder> _ensureVisible(Object object, {int? index}) async {
|
||||
var finder = object.toFinder();
|
||||
if (finder.evaluate().isEmpty) await waitFor(object);
|
||||
|
||||
if (finder.evaluate().length > 1) {
|
||||
if (index == null) {
|
||||
throw Exception(
|
||||
'⚠️ Found ${finder.evaluate().length} "$object" objects. Please specify an index!',
|
||||
);
|
||||
}
|
||||
if (finder.evaluate().length <= index) {
|
||||
throw Exception(
|
||||
'⚠️ Found ${finder.evaluate().length} "$object" objects. So index $index does not exist!',
|
||||
);
|
||||
}
|
||||
finder = finder.at(index);
|
||||
}
|
||||
return finder;
|
||||
}
|
||||
|
||||
Future<void> tapOn(
|
||||
Object object, {
|
||||
int? index,
|
||||
bool pumpAndSettle = true,
|
||||
}) async {
|
||||
final finder = await _ensureVisible(object, index: index);
|
||||
|
||||
_print('👆 Tapping on "$object"');
|
||||
await tester.tap(finder);
|
||||
if (pumpAndSettle) await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> goBack() => tapOn(find.byTooltip('Back'));
|
||||
|
||||
Future<void> enterText(
|
||||
Object object,
|
||||
String text, {
|
||||
int? index,
|
||||
bool pumpAndSettle = true,
|
||||
}) async {
|
||||
final finder = await _ensureVisible(object, index: index);
|
||||
|
||||
_print('⌨️ Enter "$text" into "$object"');
|
||||
await tester.enterText(finder, text);
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
if (pumpAndSettle) await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> scrollUntilVisible(
|
||||
Object object, {
|
||||
int? index,
|
||||
Object? scrollable,
|
||||
}) async {
|
||||
_print('📜 Scrolling to "$object"');
|
||||
await tester.scrollUntilVisible(
|
||||
object.toFinder(),
|
||||
500.0,
|
||||
scrollable: scrollable?.toFinder() ?? find.byType(Scrollable).last,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
}
|
||||
|
||||
extension on Object {
|
||||
Finder toFinder() => switch (this) {
|
||||
final Finder finder => finder,
|
||||
final String string => find.text(string),
|
||||
final Key key => find.byKey(key),
|
||||
final IconData icon => find.byIcon(icon),
|
||||
final Type type => find.byType(type),
|
||||
final Widget widget => find.byWidget(widget),
|
||||
_ => throw Exception('Unsupported finder type: $runtimeType'),
|
||||
};
|
||||
}
|
||||
|
||||
extension StartTest on WidgetTester {
|
||||
Future<TatuChatTester> startTatuChatTest() async {
|
||||
app.main(['integration_test']);
|
||||
|
||||
return TatuChatTester(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user