Skip to content

Commit e6cfc1c

Browse files
committed
chore: add some tests
1 parent 326cb38 commit e6cfc1c

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

frontend/appflowy_flutter/integration_test/mobile/document/page_style_test.dart

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
import 'package:appflowy/generated/flowy_svgs.g.dart';
2+
import 'package:appflowy/generated/locale_keys.g.dart';
23
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
34
import 'package:appflowy/mobile/presentation/base/view_page/app_bar_buttons.dart';
45
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_buttons.dart';
6+
import 'package:appflowy/mobile/presentation/mobile_bottom_navigation_bar.dart';
57
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
68
import 'package:appflowy/plugins/document/presentation/editor_plugins/cover/document_immersive_cover.dart';
9+
import 'package:appflowy/plugins/document/presentation/editor_plugins/page_style/_page_style_icon.dart';
10+
import 'package:appflowy/shared/icon_emoji_picker/recent_icons.dart';
11+
import 'package:easy_localization/easy_localization.dart';
712
import 'package:flutter/material.dart';
813
import 'package:flutter_test/flutter_test.dart';
914
import 'package:integration_test/integration_test.dart';
1015

16+
import '../../shared/emoji.dart';
1117
import '../../shared/util.dart';
1218

1319
void main() {
14-
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
20+
setUpAll(() {
21+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
22+
RecentIcons.enable = false;
23+
});
24+
25+
tearDownAll(() {
26+
RecentIcons.enable = true;
27+
});
1528

1629
group('document page style:', () {
1730
double getCurrentEditorFontSize() {
@@ -114,5 +127,37 @@ void main() {
114127
);
115128
expect(builtInCover, findsOneWidget);
116129
});
130+
131+
testWidgets('page style icon', (tester) async {
132+
await tester.launchInAnonymousMode();
133+
134+
final createPageButton =
135+
find.byKey(BottomNavigationBarItemType.add.valueKey);
136+
await tester.tapButton(createPageButton);
137+
138+
/// toggle the preset button
139+
await tester.tapSvgButton(FlowySvgs.m_layout_s);
140+
141+
/// select document plugins emoji
142+
final pageStyleIcon = find.byType(PageStyleIcon);
143+
144+
/// there should be none of emoji
145+
final noneText = find.text(LocaleKeys.pageStyle_none.tr());
146+
expect(noneText, findsOneWidget);
147+
await tester.tapButton(pageStyleIcon);
148+
149+
/// select an emoji
150+
const emoji = '😄';
151+
await tester.tapEmoji(emoji);
152+
await tester.tapSvgButton(FlowySvgs.m_layout_s);
153+
expect(noneText, findsNothing);
154+
expect(
155+
find.descendant(
156+
of: pageStyleIcon,
157+
matching: find.text(emoji),
158+
),
159+
findsOneWidget,
160+
);
161+
});
117162
});
118163
}

frontend/appflowy_flutter/integration_test/shared/base.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,33 @@ extension AppFlowyTestBase on WidgetTester {
175175
}
176176
}
177177

178+
Future<void> tapDown(
179+
Finder finder, {
180+
int? pointer,
181+
int buttons = kPrimaryButton,
182+
PointerDeviceKind kind = PointerDeviceKind.touch,
183+
bool pumpAndSettle = true,
184+
int milliseconds = 500,
185+
}) async {
186+
final location = getCenter(finder);
187+
final TestGesture gesture = await startGesture(
188+
location,
189+
pointer: pointer,
190+
buttons: buttons,
191+
kind: kind,
192+
);
193+
await gesture.cancel();
194+
await gesture.down(location);
195+
await gesture.cancel();
196+
if (pumpAndSettle) {
197+
await this.pumpAndSettle(
198+
Duration(milliseconds: milliseconds),
199+
EnginePhase.sendSemanticsUpdate,
200+
const Duration(seconds: 15),
201+
);
202+
}
203+
}
204+
178205
Future<void> tapButtonWithName(
179206
String tr, {
180207
int milliseconds = 500,

frontend/appflowy_flutter/integration_test/shared/emoji.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ extension EmojiTestExtension on WidgetTester {
4242
),
4343
);
4444
expect(find.byType(IconColorPicker), findsNothing);
45+
46+
/// test for tapping down, it should not display the ColorPicker unless tapping up
47+
await tapDown(selectedSvg);
48+
expect(find.byType(IconColorPicker), findsNothing);
49+
4550
await tapButton(selectedSvg);
4651
final colorPicker = find.byType(IconColorPicker);
4752
expect(colorPicker, findsOneWidget);

0 commit comments

Comments
 (0)