chore: add integration tests

Signed-off-by: TheOneWithTheBraid <the-one@with-the-braid.cf>
This commit is contained in:
TheOneWithTheBraid 2022-12-29 15:02:29 +01:00
commit 1992d18a64
18 changed files with 491 additions and 103 deletions

View file

@ -104,8 +104,13 @@ class ClientChooserButton extends StatelessWidget {
.map(
(client) => PopupMenuItem(
value: client,
child: FutureBuilder<Profile>(
future: client!.fetchOwnProfile(),
child: FutureBuilder<Profile?>(
// analyzer does not understand this type cast for error
// handling
//
// ignore: unnecessary_cast
future: (client!.fetchOwnProfile() as Future<Profile?>)
.onError((e, s) => null),
builder: (context, snapshot) => Row(
children: [
Avatar(

View file

@ -28,6 +28,7 @@ class ConnectPageView extends StatelessWidget {
),
),
body: ListView(
key: const Key('ConnectPageListView'),
children: [
if (Matrix.of(context).loginRegistrationSupported ?? false) ...[
Padding(

View file

@ -8,6 +8,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/widgets/matrix.dart';
import '../../utils/platform_infos.dart';
import 'login_view.dart';
@ -30,7 +31,7 @@ class LoginController extends State<Login> {
void toggleShowPassword() =>
setState(() => showPassword = !loading && !showPassword);
void login([_]) async {
void login() async {
final matrix = Matrix.of(context);
if (usernameController.text.isEmpty) {
setState(() => usernameError = L10n.of(context)!.pleaseEnterYourUsername);
@ -48,6 +49,9 @@ class LoginController extends State<Login> {
}
setState(() => loading = true);
_coolDown?.cancel();
try {
final username = usernameController.text;
AuthenticationIdentifier identifier;
@ -97,8 +101,8 @@ class LoginController extends State<Login> {
void _checkWellKnown(String userId) async {
if (mounted) setState(() => usernameError = null);
if (!userId.isValidMatrixId) return;
final oldHomeserver = Matrix.of(context).getLoginClient().homeserver;
try {
final oldHomeserver = Matrix.of(context).getLoginClient().homeserver;
var newDomain = Uri.https(userId.domain!, '');
Matrix.of(context).getLoginClient().homeserver = newDomain;
DiscoveryInformation? wellKnownInformation;
@ -112,14 +116,11 @@ class LoginController extends State<Login> {
// do nothing, newDomain is already set to a reasonable fallback
}
if (newDomain != oldHomeserver) {
await showFutureLoadingDialog(
context: context,
// do nothing if we error, we'll handle it below
future: () => Matrix.of(context)
.getLoginClient()
.checkHomeserver(newDomain)
.catchError((e) {}),
);
Matrix.of(context)
.getLoginClient()
.checkHomeserver(newDomain)
.catchError((e) {});
if (Matrix.of(context).getLoginClient().homeserver == null) {
Matrix.of(context).getLoginClient().homeserver = oldHomeserver;
// okay, the server we checked does not appear to be a matrix server
@ -140,15 +141,18 @@ class LoginController extends State<Login> {
return;
}
}
if (mounted) setState(() => usernameError = null);
usernameError = null;
if (mounted) setState(() {});
} else {
Matrix.of(context).getLoginClient().homeserver = oldHomeserver;
if (mounted) {
setState(() =>
Matrix.of(context).getLoginClient().homeserver = oldHomeserver);
setState(() {});
}
}
} catch (e) {
if (mounted) setState(() => usernameError = e.toString());
Matrix.of(context).getLoginClient().homeserver = oldHomeserver;
usernameError = e.toLocalizedString(context);
if (mounted) setState(() {});
}
}

View file

@ -60,7 +60,7 @@ class LoginView extends StatelessWidget {
controller: controller.passwordController,
textInputAction: TextInputAction.go,
obscureText: !controller.showPassword,
onSubmitted: controller.login,
onSubmitted: (_) => controller.login(),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.lock_outlined),
errorText: controller.passwordError,
@ -87,9 +87,7 @@ class LoginView extends StatelessWidget {
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
),
onPressed: controller.loading
? null
: () => controller.login(context),
onPressed: controller.loading ? null : controller.login,
icon: const Icon(Icons.login_outlined),
label: controller.loading
? const LinearProgressIndicator()

View file

@ -38,6 +38,7 @@ class SettingsView extends StatelessWidget {
body: ListTileTheme(
iconColor: Theme.of(context).colorScheme.onBackground,
child: ListView(
key: const Key('SettingsListViewContent'),
children: <Widget>[
AnimatedContainer(
height: controller.showChatBackupBanner ? 54 : 0,

View file

@ -11,6 +11,7 @@ class ContentBanner extends StatelessWidget {
final void Function()? onEdit;
final Client? client;
final double opacity;
final WidgetBuilder? placeholder;
const ContentBanner(
{this.mxContent,
@ -19,6 +20,7 @@ class ContentBanner extends StatelessWidget {
this.onEdit,
this.client,
this.opacity = 0.75,
this.placeholder,
Key? key})
: super(key: key);
@ -54,6 +56,7 @@ class ContentBanner extends StatelessWidget {
uri: mxContent,
animated: true,
fit: BoxFit.cover,
placeholder: placeholder,
height: 400,
width: 800,
),

View file

@ -327,15 +327,15 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
);
if (state != LoginState.loggedIn) {
widget.router!.currentState!.to(
widget.router?.currentState?.to(
'/rooms',
queryParameters: widget.router!.currentState!.queryParameters,
queryParameters: widget.router?.currentState?.queryParameters ?? {},
);
}
} else {
widget.router!.currentState!.to(
widget.router?.currentState?.to(
state == LoginState.loggedIn ? '/rooms' : '/home',
queryParameters: widget.router!.currentState!.queryParameters,
queryParameters: widget.router?.currentState?.queryParameters ?? {},
);
}
});

View file

@ -15,6 +15,7 @@ import '../utils/localized_exception_extension.dart';
class ProfileBottomSheet extends StatelessWidget {
final String userId;
final BuildContext outerContext;
const ProfileBottomSheet({
required this.userId,
required this.outerContext,
@ -78,6 +79,13 @@ class ProfileBottomSheet extends StatelessWidget {
mxContent: profile.avatarUrl,
defaultIcon: Icons.account_circle_outlined,
client: Matrix.of(context).client,
placeholder: (context) => Center(
child: Text(
userId.localpart ?? userId,
style:
Theme.of(context).textTheme.headline3,
),
),
),
),
ListTile(

View file

@ -6,6 +6,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:system_theme/system_theme.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/platform_infos.dart';
class ThemeBuilder extends StatefulWidget {
final Widget Function(
@ -34,6 +35,7 @@ class ThemeController extends State<ThemeBuilder> {
Color? _primaryColor;
ThemeMode get themeMode => _themeMode ?? ThemeMode.system;
Color? get primaryColor => _primaryColor;
static ThemeController of(BuildContext context) =>
@ -87,10 +89,18 @@ class ThemeController extends State<ThemeBuilder> {
super.initState();
}
Color? get systemAccentColor {
final color = SystemTheme.accentColor.accent;
if (color == kDefaultSystemAccentColor) return AppConfig.chatColor;
return color;
Color get systemAccentColor {
if (PlatformInfos.isLinux) return AppConfig.chatColor;
try {
// a bad plugin implementation
// https://github.com/bdlukaa/system_theme/issues/10
final accentColor = SystemTheme.accentColor;
final color = accentColor.accent;
if (color == kDefaultSystemAccentColor) return AppConfig.chatColor;
return color;
} catch (_) {
return AppConfig.chatColor;
}
}
@override