mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: default text direction not synced (#5405)
* fix: default text direction not synced * test: annotate visibleForTesting
This commit is contained in:
committed by
GitHub
parent
13a35672ab
commit
13b3439bd6
@ -125,7 +125,7 @@ class SettingsWorkspaceView extends StatelessWidget {
|
|||||||
title:
|
title:
|
||||||
LocaleKeys.settings_workspacePage_textDirection_title.tr(),
|
LocaleKeys.settings_workspacePage_textDirection_title.tr(),
|
||||||
children: const [
|
children: const [
|
||||||
_TextDirectionSelect(),
|
TextDirectionSelect(),
|
||||||
EnableRTLItemsSwitcher(),
|
EnableRTLItemsSwitcher(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -387,19 +387,25 @@ class _WorkspaceIconSetting extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _TextDirectionSelect extends StatelessWidget {
|
@visibleForTesting
|
||||||
const _TextDirectionSelect();
|
class TextDirectionSelect extends StatelessWidget {
|
||||||
|
const TextDirectionSelect({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<AppearanceSettingsCubit, AppearanceSettingsState>(
|
return BlocBuilder<AppearanceSettingsCubit, AppearanceSettingsState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final selectedItem = state.textDirection ?? AppFlowyTextDirection.auto;
|
final selectedItem = state.textDirection ?? AppFlowyTextDirection.ltr;
|
||||||
|
|
||||||
return SettingsRadioSelect<AppFlowyTextDirection>(
|
return SettingsRadioSelect<AppFlowyTextDirection>(
|
||||||
onChanged: (item) => context
|
onChanged: (item) {
|
||||||
|
context
|
||||||
.read<AppearanceSettingsCubit>()
|
.read<AppearanceSettingsCubit>()
|
||||||
.setTextDirection(item.value),
|
.setTextDirection(item.value);
|
||||||
|
context
|
||||||
|
.read<DocumentAppearanceCubit>()
|
||||||
|
.syncDefaultTextDirection(item.value.name);
|
||||||
|
},
|
||||||
items: [
|
items: [
|
||||||
SettingsRadioItem(
|
SettingsRadioItem(
|
||||||
value: AppFlowyTextDirection.ltr,
|
value: AppFlowyTextDirection.ltr,
|
||||||
|
@ -0,0 +1,159 @@
|
|||||||
|
import 'package:appflowy/workspace/presentation/settings/pages/settings_workspace_view.dart';
|
||||||
|
import 'package:appflowy/workspace/presentation/settings/shared/settings_radio_select.dart';
|
||||||
|
import 'package:flowy_infra/theme.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
|
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
|
||||||
|
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
|
import 'package:appflowy_backend/protobuf/flowy-user/user_setting.pb.dart';
|
||||||
|
import 'package:appflowy/user/application/user_settings_service.dart';
|
||||||
|
|
||||||
|
import '../util.dart';
|
||||||
|
|
||||||
|
class MockAppearanceSettingsBloc
|
||||||
|
extends MockBloc<AppearanceSettingsCubit, AppearanceSettingsState>
|
||||||
|
implements AppearanceSettingsCubit {}
|
||||||
|
|
||||||
|
class MockDocumentAppearanceCubit extends Mock
|
||||||
|
implements DocumentAppearanceCubit {}
|
||||||
|
|
||||||
|
class MockDocumentAppearance extends Mock implements DocumentAppearance {}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late AppearanceSettingsPB appearanceSettings;
|
||||||
|
late DateTimeSettingsPB dateTimeSettings;
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
await AppFlowyUnitTest.ensureInitialized();
|
||||||
|
appearanceSettings =
|
||||||
|
await UserSettingsBackendService().getAppearanceSetting();
|
||||||
|
dateTimeSettings = await UserSettingsBackendService().getDateTimeSettings();
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('TextDirectionSelect update default text direction setting',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
final appearanceSettingsState = AppearanceSettingsState.initial(
|
||||||
|
AppTheme.fallback,
|
||||||
|
appearanceSettings.themeMode,
|
||||||
|
appearanceSettings.font,
|
||||||
|
appearanceSettings.monospaceFont,
|
||||||
|
appearanceSettings.layoutDirection,
|
||||||
|
appearanceSettings.textDirection,
|
||||||
|
appearanceSettings.enableRtlToolbarItems,
|
||||||
|
appearanceSettings.locale,
|
||||||
|
appearanceSettings.isMenuCollapsed,
|
||||||
|
appearanceSettings.menuOffset,
|
||||||
|
dateTimeSettings.dateFormat,
|
||||||
|
dateTimeSettings.timeFormat,
|
||||||
|
dateTimeSettings.timezoneId,
|
||||||
|
appearanceSettings.documentSetting.cursorColor.isEmpty
|
||||||
|
? null
|
||||||
|
: Color(
|
||||||
|
int.parse(appearanceSettings.documentSetting.cursorColor),
|
||||||
|
),
|
||||||
|
appearanceSettings.documentSetting.selectionColor.isEmpty
|
||||||
|
? null
|
||||||
|
: Color(
|
||||||
|
int.parse(
|
||||||
|
appearanceSettings.documentSetting.selectionColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
1.0,
|
||||||
|
);
|
||||||
|
final mockAppearanceSettingsBloc = MockAppearanceSettingsBloc();
|
||||||
|
when(() => mockAppearanceSettingsBloc.state).thenReturn(
|
||||||
|
appearanceSettingsState,
|
||||||
|
);
|
||||||
|
|
||||||
|
final mockDocumentAppearanceCubit = MockDocumentAppearanceCubit();
|
||||||
|
when(() => mockDocumentAppearanceCubit.stream).thenAnswer(
|
||||||
|
(_) => Stream.fromIterable([MockDocumentAppearance()]),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MultiBlocProvider(
|
||||||
|
providers: [
|
||||||
|
BlocProvider<AppearanceSettingsCubit>.value(
|
||||||
|
value: mockAppearanceSettingsBloc,
|
||||||
|
),
|
||||||
|
BlocProvider<DocumentAppearanceCubit>.value(
|
||||||
|
value: mockDocumentAppearanceCubit,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
child: MaterialApp(
|
||||||
|
theme: appearanceSettingsState.lightTheme,
|
||||||
|
home: MultiBlocProvider(
|
||||||
|
providers: [
|
||||||
|
BlocProvider<AppearanceSettingsCubit>.value(
|
||||||
|
value: mockAppearanceSettingsBloc,
|
||||||
|
),
|
||||||
|
BlocProvider<DocumentAppearanceCubit>.value(
|
||||||
|
value: mockDocumentAppearanceCubit,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
child: const Scaffold(
|
||||||
|
body: TextDirectionSelect(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
find.text(
|
||||||
|
LocaleKeys.settings_workspacePage_textDirection_leftToRight.tr(),
|
||||||
|
),
|
||||||
|
findsOne,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
find.text(
|
||||||
|
LocaleKeys.settings_workspacePage_textDirection_rightToLeft.tr(),
|
||||||
|
),
|
||||||
|
findsOne,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
find.text(
|
||||||
|
LocaleKeys.settings_workspacePage_textDirection_auto.tr(),
|
||||||
|
),
|
||||||
|
findsOne,
|
||||||
|
);
|
||||||
|
|
||||||
|
final radioSelectFinder =
|
||||||
|
find.byType(SettingsRadioSelect<AppFlowyTextDirection>);
|
||||||
|
expect(radioSelectFinder, findsOne);
|
||||||
|
|
||||||
|
when(
|
||||||
|
() => mockAppearanceSettingsBloc.setTextDirection(
|
||||||
|
any<AppFlowyTextDirection?>(),
|
||||||
|
),
|
||||||
|
).thenAnswer((_) async => {});
|
||||||
|
when(
|
||||||
|
() => mockDocumentAppearanceCubit.syncDefaultTextDirection(
|
||||||
|
any<String?>(),
|
||||||
|
),
|
||||||
|
).thenAnswer((_) async {});
|
||||||
|
|
||||||
|
final radioSelect = tester.widget(radioSelectFinder)
|
||||||
|
as SettingsRadioSelect<AppFlowyTextDirection>;
|
||||||
|
final rtlSelect = radioSelect.items
|
||||||
|
.firstWhere((select) => select.value == AppFlowyTextDirection.rtl);
|
||||||
|
radioSelect.onChanged(rtlSelect);
|
||||||
|
|
||||||
|
verify(
|
||||||
|
() => mockAppearanceSettingsBloc.setTextDirection(
|
||||||
|
any<AppFlowyTextDirection?>(),
|
||||||
|
),
|
||||||
|
).called(1);
|
||||||
|
verify(
|
||||||
|
() => mockDocumentAppearanceCubit.syncDefaultTextDirection(
|
||||||
|
any<String?>(),
|
||||||
|
),
|
||||||
|
).called(1);
|
||||||
|
});
|
||||||
|
}
|
Reference in New Issue
Block a user