forked from eatvio/eatvio_app
fix(personal-diet): open client chat after diet assignment
- navigate to the client chat after a successful attach or reattach - reset the stack so back returns to the chat list - keep the diet screen on missing chat id and cover the flow with tests
This commit is contained in:
@@ -35,6 +35,7 @@ void main() {
|
||||
|
||||
final mockConsultation = ConsultationModel(
|
||||
id: 1,
|
||||
chatId: 'chat-1',
|
||||
chosenPlanState: ChosenPlanStateEnum.stateInProgress,
|
||||
planTitle: 'Test Plan',
|
||||
userName: 'Test User',
|
||||
@@ -69,6 +70,32 @@ void main() {
|
||||
path: '/personal-diet-suggestion',
|
||||
builder: (context, state) => const Scaffold(body: Text('Personal Diet')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/chat-select-screen',
|
||||
name: 'chatSelectScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('Chats')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/chat-screen',
|
||||
name: 'chatScreen',
|
||||
builder: (context, state) {
|
||||
final uuid = state.uri.queryParameters['uuid'];
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: BackButton(
|
||||
onPressed: () {
|
||||
if (context.canPop()) {
|
||||
GoRouter.of(context).pop();
|
||||
return;
|
||||
}
|
||||
GoRouter.of(context).go('/chat-select-screen');
|
||||
},
|
||||
),
|
||||
),
|
||||
body: Text('Chat $uuid'),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -202,7 +229,7 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('shows success bottom sheet after successful diet attachment', (tester) async {
|
||||
testWidgets('opens chat after successful diet attachment', (tester) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
final cubit = MockPersonalDietSuggestionCubit();
|
||||
|
||||
@@ -227,16 +254,22 @@ void main() {
|
||||
await tester.tap(offerButton);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('«Test Diet» предложена пользователю Test User'), findsOneWidget);
|
||||
expect(find.text('Chat chat-1'), findsOneWidget);
|
||||
verify(cubit.attachDietToConsultation(consultationId: 1)).called(1);
|
||||
|
||||
await tester.tap(find.byType(BackButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Chats'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('shows success bottom sheet after successful diet reattachment', (tester) async {
|
||||
testWidgets('opens chat after successful diet reattachment', (tester) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
final cubit = MockPersonalDietSuggestionCubit();
|
||||
final consultationWithDiet = ConsultationModel(
|
||||
id: 1,
|
||||
chatId: 'chat-2',
|
||||
chosenPlanState: ChosenPlanStateEnum.stateInProgress,
|
||||
planTitle: 'Test Plan',
|
||||
userName: 'Test User',
|
||||
@@ -274,9 +307,47 @@ void main() {
|
||||
await tester.tap(offerButton);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('«Test Diet» предложена пользователю Test User'), findsOneWidget);
|
||||
expect(find.text('Chat chat-2'), findsOneWidget);
|
||||
verify(cubit.reattachDietToConsultation(consultationId: 1)).called(1);
|
||||
verifyNever(cubit.attachDietToConsultation(consultationId: 1));
|
||||
|
||||
await tester.tap(find.byType(BackButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Chats'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('stays on screen when chat id is missing after success', (tester) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
final cubit = MockPersonalDietSuggestionCubit();
|
||||
|
||||
when(cubit.state).thenReturn(PersonalDietSuggestionState());
|
||||
when(cubit.stream).thenAnswer((_) => const Stream.empty());
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.attachDietToConsultation(consultationId: 1)).thenAnswer((_) async => true);
|
||||
|
||||
await tester.pumpWidget(
|
||||
BlocProvider<PersonalDietSuggestionCubit>.value(
|
||||
value: cubit,
|
||||
child: wrap(
|
||||
ConsultationWidget(
|
||||
consultationModel: mockConsultation.copyWith(chatId: null),
|
||||
dietName: 'Test Diet',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Предложить диету'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(S.of(tester.element(find.byType(ConsultationWidget))).toOffer));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('Chat '), findsNothing);
|
||||
expect(find.text('Test User'), findsOneWidget);
|
||||
verify(cubit.attachDietToConsultation(consultationId: 1)).called(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user