Skip to content

Commit cb41b56

Browse files
dab246hoangdat
authored andcommitted
TF-4308 Add E2E tests for ChooseLabelModal and NoLabelYetWidget
Signed-off-by: dab246 <tdvu@linagora.com>
1 parent a693ceb commit cb41b56

8 files changed

Lines changed: 263 additions & 0 deletions
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:tmail_ui_user/features/labels/presentation/widgets/choose_label_modal.dart';
3+
import 'package:tmail_ui_user/features/labels/presentation/widgets/no_label_yet_widget.dart';
4+
import 'package:tmail_ui_user/features/mailbox/presentation/widgets/labels/label_list_item.dart';
5+
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
6+
7+
import '../../base/core_robot.dart';
8+
9+
class ChooseLabelModalRobot extends CoreRobot {
10+
ChooseLabelModalRobot(super.$);
11+
12+
Future<void> tapCreateALabelButton() async {
13+
await $(ChooseLabelModal)
14+
.$(find.text(AppLocalizations().createALabel))
15+
.tap();
16+
}
17+
18+
Future<void> tapLabelByName(String name) async {
19+
final item = $(ChooseLabelModal).$(LabelListItem).$(name);
20+
await $.scrollUntilVisible(finder: item);
21+
await item.tap();
22+
}
23+
24+
Future<void> tapAddLabelButton() async {
25+
await $(ChooseLabelModal)
26+
.$(find.text(AppLocalizations().addLabel))
27+
.tap();
28+
}
29+
30+
bool get isNoLabelYetWidgetVisible =>
31+
$(ChooseLabelModal).$(NoLabelYetWidget).visible;
32+
33+
bool get isLabelListVisible =>
34+
$(ChooseLabelModal).$(LabelListItem).visible;
35+
}

integration_test/robots/thread_robot.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ class ThreadRobot extends CoreRobot {
117117
await $.pumpAndSettle(duration: const Duration(seconds: 2));
118118
}
119119

120+
Future<void> tapLabelAsButton() async {
121+
await $(#moreAction_selected_email_button).tap();
122+
await $.pumpAndTrySettle();
123+
await $(#labelAs_action).tap();
124+
}
125+
120126
Future<void> tapEmptySpamAfterLongPress() async {
121127
await $(AppLocalizations().deleteAllSpamEmails).tap();
122128
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:labels/labels.dart';
3+
import 'package:tmail_ui_user/features/labels/presentation/models/label_action_type.dart';
4+
import 'package:tmail_ui_user/features/labels/presentation/widgets/no_label_yet_widget.dart';
5+
import 'package:tmail_ui_user/features/mailbox/presentation/widgets/labels/label_list_view.dart';
6+
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
7+
8+
import '../../base/base_test_scenario.dart';
9+
import '../../mixin/provisioning_label_scenario_mixin.dart';
10+
import '../../robots/labels/choose_label_modal_robot.dart';
11+
import '../../robots/labels/create_label_modal_robot.dart';
12+
import '../../robots/thread_robot.dart';
13+
14+
class CreateLabelFromChooseLabelModalWithExistingLabelsScenario
15+
extends BaseTestScenario with ProvisioningLabelScenarioMixin {
16+
const CreateLabelFromChooseLabelModalWithExistingLabelsScenario(super.$);
17+
18+
@override
19+
Future<void> runTestLogic() async {
20+
const emailUser = String.fromEnvironment('BASIC_AUTH_EMAIL');
21+
expect(emailUser, isNotEmpty, reason: 'BASIC_AUTH_EMAIL must be set');
22+
23+
final threadRobot = ThreadRobot($);
24+
final chooseLabelModalRobot = ChooseLabelModalRobot($);
25+
final createLabelModalRobot = CreateLabelModalRobot($);
26+
27+
final labels = await provisionLabelsByDisplayNames(['Existing Label 1']);
28+
await $.pumpAndSettle();
29+
expect(labels, isNotEmpty, reason: 'Provisioning label failed');
30+
31+
final existingLabel = labels.first;
32+
33+
await provisionEmail(
34+
buildEmailsForLabel(
35+
label: existingLabel,
36+
toEmail: emailUser,
37+
count: 1,
38+
),
39+
requestReadReceipt: false,
40+
);
41+
await $.pumpAndSettle(duration: const Duration(seconds: 2));
42+
43+
await threadRobot.openMailbox();
44+
await expectViewVisible($(LabelListView));
45+
await $.native.pressBack();
46+
47+
await threadRobot.longPressEmailWithSubject(
48+
'Email 1 subject ${existingLabel.safeDisplayName}',
49+
);
50+
await $.pumpAndTrySettle();
51+
52+
await threadRobot.tapLabelAsButton();
53+
await $.pumpAndTrySettle();
54+
55+
expect(chooseLabelModalRobot.isLabelListVisible, isTrue);
56+
expect($(NoLabelYetWidget).visible, isFalse);
57+
await expectViewVisible($(find.text(AppLocalizations().createALabel)));
58+
59+
await chooseLabelModalRobot.tapCreateALabelButton();
60+
await $.pumpAndTrySettle();
61+
62+
await expectViewVisible($(#create_new_label_modal));
63+
64+
final uniqueSuffix = DateTime.now().microsecondsSinceEpoch;
65+
final newLabelName = 'New label from modal $uniqueSuffix';
66+
await createLabelModalRobot.enterNewLabelName(newLabelName);
67+
await createLabelModalRobot.tapPositiveActionButton(LabelActionType.create);
68+
await $.pumpAndTrySettle();
69+
70+
await expectViewVisible(
71+
$(find.text(AppLocalizations().createLabelSuccessfullyMessage(newLabelName))),
72+
);
73+
await expectViewVisible($(newLabelName));
74+
}
75+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:tmail_ui_user/features/labels/presentation/models/label_action_type.dart';
3+
import 'package:tmail_ui_user/features/labels/presentation/widgets/no_label_yet_widget.dart';
4+
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
5+
6+
import '../../base/base_test_scenario.dart';
7+
import '../../models/provisioning_email.dart';
8+
import '../../robots/labels/choose_label_modal_robot.dart';
9+
import '../../robots/labels/create_label_modal_robot.dart';
10+
import '../../robots/thread_robot.dart';
11+
12+
class CreateLabelFromNoLabelYetWidgetScenario extends BaseTestScenario {
13+
const CreateLabelFromNoLabelYetWidgetScenario(super.$);
14+
15+
@override
16+
Future<void> runTestLogic() async {
17+
const emailUser = String.fromEnvironment('BASIC_AUTH_EMAIL');
18+
expect(emailUser, isNotEmpty, reason: 'BASIC_AUTH_EMAIL must be set');
19+
20+
final threadRobot = ThreadRobot($);
21+
final chooseLabelModalRobot = ChooseLabelModalRobot($);
22+
final createLabelModalRobot = CreateLabelModalRobot($);
23+
24+
await provisionEmail(
25+
[
26+
ProvisioningEmail(
27+
toEmail: emailUser,
28+
subject: 'Test email for create label from no-label widget',
29+
content: 'Content',
30+
),
31+
],
32+
requestReadReceipt: false,
33+
);
34+
await $.pumpAndSettle(duration: const Duration(seconds: 2));
35+
36+
await threadRobot.longPressEmailWithSubject(
37+
'Test email for create label from no-label widget',
38+
);
39+
await $.pumpAndTrySettle();
40+
41+
await threadRobot.tapLabelAsButton();
42+
await $.pumpAndTrySettle();
43+
44+
await expectViewVisible($(NoLabelYetWidget));
45+
46+
await chooseLabelModalRobot.tapCreateALabelButton();
47+
await $.pumpAndTrySettle();
48+
49+
await expectViewVisible($(#create_new_label_modal));
50+
51+
final uniqueSuffix = DateTime.now().microsecondsSinceEpoch;
52+
final newLabelName = 'Label from no-label widget $uniqueSuffix';
53+
await createLabelModalRobot.enterNewLabelName(newLabelName);
54+
await createLabelModalRobot.tapPositiveActionButton(LabelActionType.create);
55+
await $.pumpAndTrySettle();
56+
57+
await expectViewVisible(
58+
$(find.text(AppLocalizations().createLabelSuccessfullyMessage(newLabelName))),
59+
);
60+
expect(chooseLabelModalRobot.isLabelListVisible, isTrue);
61+
await expectViewVisible($(newLabelName));
62+
expect($(NoLabelYetWidget).visible, isFalse);
63+
}
64+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:tmail_ui_user/features/labels/presentation/widgets/no_label_yet_widget.dart';
3+
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
4+
5+
import '../../base/base_test_scenario.dart';
6+
import '../../models/provisioning_email.dart';
7+
import '../../robots/labels/choose_label_modal_robot.dart';
8+
import '../../robots/thread_robot.dart';
9+
10+
class DisplayNoLabelYetWidgetWhenOpenChooseLabelModalScenario
11+
extends BaseTestScenario {
12+
const DisplayNoLabelYetWidgetWhenOpenChooseLabelModalScenario(super.$);
13+
14+
@override
15+
Future<void> runTestLogic() async {
16+
const emailUser = String.fromEnvironment('BASIC_AUTH_EMAIL');
17+
expect(emailUser, isNotEmpty, reason: 'BASIC_AUTH_EMAIL must be set');
18+
19+
final threadRobot = ThreadRobot($);
20+
final chooseLabelModalRobot = ChooseLabelModalRobot($);
21+
22+
await provisionEmail(
23+
[
24+
ProvisioningEmail(
25+
toEmail: emailUser,
26+
subject: 'Test email for no-label modal',
27+
content: 'Content',
28+
),
29+
],
30+
requestReadReceipt: false,
31+
);
32+
await $.pumpAndSettle(duration: const Duration(seconds: 2));
33+
34+
await threadRobot.longPressEmailWithSubject('Test email for no-label modal');
35+
await $.pumpAndTrySettle();
36+
37+
await threadRobot.tapLabelAsButton();
38+
await $.pumpAndTrySettle();
39+
40+
await _expectNoLabelYetWidgetVisible(chooseLabelModalRobot);
41+
}
42+
43+
Future<void> _expectNoLabelYetWidgetVisible(
44+
ChooseLabelModalRobot chooseLabelModalRobot,
45+
) async {
46+
await expectViewVisible($(NoLabelYetWidget));
47+
await expectViewVisible($(find.text(AppLocalizations().noLabelsYet)));
48+
await expectViewVisible($(find.text(AppLocalizations().createALabel)));
49+
expect(chooseLabelModalRobot.isLabelListVisible, isFalse);
50+
}
51+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import '../../base/test_base.dart';
2+
import '../../scenarios/labels/create_label_from_choose_label_modal_with_existing_labels_scenario.dart';
3+
4+
void main() {
5+
TestBase().runPatrolTest(
6+
description:
7+
'Should show "Create a label" button in Choose Label modal when labels exist, and create a new label successfully',
8+
scenarioBuilder: ($) =>
9+
CreateLabelFromChooseLabelModalWithExistingLabelsScenario($),
10+
);
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import '../../base/test_base.dart';
2+
import '../../scenarios/labels/create_label_from_no_label_yet_widget_scenario.dart';
3+
4+
void main() {
5+
TestBase().runPatrolTest(
6+
description:
7+
'Should create a label from NoLabelYetWidget and show it in the Choose Label modal list',
8+
scenarioBuilder: ($) => CreateLabelFromNoLabelYetWidgetScenario($),
9+
);
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import '../../base/test_base.dart';
2+
import '../../scenarios/labels/display_no_label_yet_widget_when_open_choose_label_modal_scenario.dart';
3+
4+
void main() {
5+
TestBase().runPatrolTest(
6+
description:
7+
'Should display NoLabelYetWidget when opening Choose Label modal with no labels',
8+
scenarioBuilder: ($) =>
9+
DisplayNoLabelYetWidgetWhenOpenChooseLabelModalScenario($),
10+
);
11+
}

0 commit comments

Comments
 (0)