forked from eatvio/eatvio_app
feat(video_calls, welcome_screen): ios mic fix, welcome scrin layoute fix
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,9 @@ import 'chat_screen_loaded_smoke_test.mocks.dart';
|
||||
void main() {
|
||||
group('ChatScreen loaded smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
dotenv.loadFromString(
|
||||
envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost',
|
||||
);
|
||||
await initializeDateFormatting('ru', null);
|
||||
await initializeDateFormatting('ru_RU', null);
|
||||
await initializeDateFormatting('RU', null);
|
||||
@@ -37,7 +39,11 @@ void main() {
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
sl.registerLazySingleton<AppConfig>(
|
||||
() =>
|
||||
AppConfig(buildType: AppBuildType.tests)
|
||||
..setBaseUrl('http://localhost'),
|
||||
);
|
||||
sl.registerLazySingleton<WsManager>(() => _FakeWsManager());
|
||||
});
|
||||
|
||||
@@ -47,7 +53,9 @@ void main() {
|
||||
</svg>
|
||||
''';
|
||||
|
||||
final fakeBundle = _FakeAssetBundle({'assets/icons/error_icon.svg': fakeSvg});
|
||||
final fakeBundle = _FakeAssetBundle({
|
||||
'assets/icons/error_icon.svg': fakeSvg,
|
||||
});
|
||||
|
||||
Widget wrap(Widget child, ChatsCubit chatsCubit) {
|
||||
return DefaultAssetBundle(
|
||||
@@ -70,8 +78,18 @@ void main() {
|
||||
id: '1',
|
||||
chatRoomSettings: ChatRoomSettingsModel(name: 'room', state: 'active'),
|
||||
users: Users(
|
||||
sender: ChatUserModel(id: 1, name: 'Me', slug: 'me', profilePhotoUrl: null),
|
||||
receiver: ChatUserModel(id: 2, name: 'User Two', slug: 'user-two', profilePhotoUrl: null),
|
||||
sender: ChatUserModel(
|
||||
id: 1,
|
||||
name: 'Me',
|
||||
slug: 'me',
|
||||
profilePhotoUrl: null,
|
||||
),
|
||||
receiver: ChatUserModel(
|
||||
id: 2,
|
||||
name: 'User Two',
|
||||
slug: 'user-two',
|
||||
profilePhotoUrl: null,
|
||||
),
|
||||
),
|
||||
chosenPlanId: null,
|
||||
chosenPlan: null,
|
||||
@@ -147,12 +165,19 @@ void main() {
|
||||
);
|
||||
|
||||
when(chatRoomCubit.state).thenReturn(state);
|
||||
when(chatRoomCubit.stream).thenAnswer((_) => const Stream<ChatRoomState>.empty());
|
||||
when(
|
||||
chatRoomCubit.stream,
|
||||
).thenAnswer((_) => const Stream<ChatRoomState>.empty());
|
||||
when(chatRoomCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(chatRoomCubit.initChat(any, sendInitialMessage: anyNamed('sendInitialMessage'), orderId: anyNamed('orderId')))
|
||||
.thenAnswer((_) async => 'uuid');
|
||||
when(
|
||||
chatRoomCubit.initChat(
|
||||
any,
|
||||
sendInitialMessage: anyNamed('sendInitialMessage'),
|
||||
orderId: anyNamed('orderId'),
|
||||
),
|
||||
).thenAnswer((_) async => 'uuid');
|
||||
when(chatRoomCubit.setTimer()).thenReturn(null);
|
||||
|
||||
when(chatRoomCubit.refreshChat()).thenAnswer((_) async {});
|
||||
|
||||
sl.registerFactory<ChatRoomCubit>(() => chatRoomCubit);
|
||||
|
||||
@@ -160,11 +185,17 @@ void main() {
|
||||
when(chatsCubit.stream).thenAnswer((_) => const Stream.empty());
|
||||
when(chatsCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
await tester.pumpWidget(wrap(const ChatScreen(uuid: 'uuid', sendInitialMessage: false), chatsCubit));
|
||||
await tester.pumpWidget(
|
||||
wrap(
|
||||
const ChatScreen(uuid: 'uuid', sendInitialMessage: false),
|
||||
chatsCubit,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
|
||||
expect(find.byType(ChatScreen), findsOneWidget);
|
||||
expect(find.byType(RefreshIndicator), findsOneWidget);
|
||||
expect(find.text('User Two'), findsOneWidget);
|
||||
expect(find.text('hello'), findsOneWidget);
|
||||
expect(find.text('hi'), findsOneWidget);
|
||||
|
||||
@@ -82,12 +82,65 @@ void main() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setPrice(1500.0);
|
||||
expect(cubit.state.planData.options[0].price, 1500.0);
|
||||
expect(cubit.state.validationState.optionsValidationState[0].priceHasError, false);
|
||||
expect(
|
||||
cubit.state.validationState.optionsValidationState[0].priceHasError,
|
||||
false,
|
||||
);
|
||||
|
||||
cubit.setPrice(1000.0);
|
||||
expect(cubit.state.validationState.optionsValidationState[0].priceHasError, true);
|
||||
expect(
|
||||
cubit.state.validationState.optionsValidationState[0].priceHasError,
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'option title, description, price and content stay independent per option',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('Economy');
|
||||
cubit.setPrice(1500.0);
|
||||
cubit.setOptionDescription('Economy description');
|
||||
cubit.setOptionContent('Economy item', 0);
|
||||
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionTitle('Standard');
|
||||
cubit.setPrice(2500.0);
|
||||
cubit.setOptionDescription('Standard description');
|
||||
cubit.setOptionContent('Standard item', 0);
|
||||
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionTitle('Comfort');
|
||||
cubit.setPrice(3500.0);
|
||||
cubit.setOptionDescription('Comfort description');
|
||||
cubit.setOptionContent('Comfort item', 0);
|
||||
|
||||
expect(cubit.state.planData.options[0].short, 'Economy');
|
||||
expect(cubit.state.planData.options[0].price, 1500.0);
|
||||
expect(
|
||||
cubit.state.planData.options[0].description,
|
||||
'Economy description',
|
||||
);
|
||||
expect(cubit.state.planData.options[0].items, ['Economy item']);
|
||||
|
||||
expect(cubit.state.planData.options[1].short, 'Standard');
|
||||
expect(cubit.state.planData.options[1].price, 2500.0);
|
||||
expect(
|
||||
cubit.state.planData.options[1].description,
|
||||
'Standard description',
|
||||
);
|
||||
expect(cubit.state.planData.options[1].items, ['Standard item']);
|
||||
|
||||
expect(cubit.state.planData.options[2].short, 'Comfort');
|
||||
expect(cubit.state.planData.options[2].price, 3500.0);
|
||||
expect(
|
||||
cubit.state.planData.options[2].description,
|
||||
'Comfort description',
|
||||
);
|
||||
expect(cubit.state.planData.options[2].items, ['Comfort item']);
|
||||
},
|
||||
);
|
||||
|
||||
test('setOptionDescription updates description and validates', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionDescription('Test description');
|
||||
@@ -129,11 +182,17 @@ void main() {
|
||||
test('validateSelectedOptionItems validates items', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
expect(cubit.validateSelectedOptionItems(), false);
|
||||
expect(cubit.state.validationState.optionsValidationState[0].isItemsEmpty, true);
|
||||
expect(
|
||||
cubit.state.validationState.optionsValidationState[0].isItemsEmpty,
|
||||
true,
|
||||
);
|
||||
|
||||
cubit.setOptionContent('Valid item', 0);
|
||||
expect(cubit.validateSelectedOptionItems(), true);
|
||||
expect(cubit.state.validationState.optionsValidationState[0].isItemsEmpty, false);
|
||||
expect(
|
||||
cubit.state.validationState.optionsValidationState[0].isItemsEmpty,
|
||||
false,
|
||||
);
|
||||
|
||||
cubit.setOptionContent('AB', 1);
|
||||
expect(cubit.validateSelectedOptionItems(), false);
|
||||
@@ -225,18 +284,27 @@ void main() {
|
||||
expect(cubit.state.validationState.imageHasError, false);
|
||||
});
|
||||
|
||||
test('validateSelectedOptionPrice returns false for price less than 1200', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setPrice(1000.0);
|
||||
expect(cubit.validateSelectedOptionPrice(), false);
|
||||
expect(cubit.state.validationState.optionsValidationState[0].priceHasError, true);
|
||||
});
|
||||
test(
|
||||
'validateSelectedOptionPrice returns false for price less than 1200',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setPrice(1000.0);
|
||||
expect(cubit.validateSelectedOptionPrice(), false);
|
||||
expect(
|
||||
cubit.state.validationState.optionsValidationState[0].priceHasError,
|
||||
true,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateSelectedOptionPrice returns true for price >= 1200', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setPrice(1200.0);
|
||||
expect(cubit.validateSelectedOptionPrice(), true);
|
||||
expect(cubit.state.validationState.optionsValidationState[0].priceHasError, false);
|
||||
expect(
|
||||
cubit.state.validationState.optionsValidationState[0].priceHasError,
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('setImage updates image and validates', () {
|
||||
@@ -260,28 +328,37 @@ void main() {
|
||||
expect(cubit.state.planData.options[0].items[0], 'Item 1');
|
||||
});
|
||||
|
||||
test('validatePriceOfAllFilledOptions returns false when some prices are invalid', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setPrice(1500.0);
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setPrice(1000.0); // Invalid
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setPrice(1500.0);
|
||||
expect(cubit.validatePriceOfAllFilledOptions(), false);
|
||||
});
|
||||
test(
|
||||
'validatePriceOfAllFilledOptions returns false when some prices are invalid',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setPrice(1500.0);
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setPrice(1000.0); // Invalid
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setPrice(1500.0);
|
||||
expect(cubit.validatePriceOfAllFilledOptions(), false);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateSelectedOptionTitle returns false for short title', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('AB');
|
||||
expect(cubit.validateSelectedOptionTitle(), false);
|
||||
expect(cubit.state.validationState.optionsValidationState[0].titleHasError, true);
|
||||
expect(
|
||||
cubit.state.validationState.optionsValidationState[0].titleHasError,
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('validateSelectedOptionTitle returns true for valid title', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('Valid Title');
|
||||
expect(cubit.validateSelectedOptionTitle(), true);
|
||||
expect(cubit.state.validationState.optionsValidationState[0].titleHasError, false);
|
||||
expect(
|
||||
cubit.state.validationState.optionsValidationState[0].titleHasError,
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('validateTitlesOfAllFilledOptions validates all options', () {
|
||||
@@ -294,37 +371,63 @@ void main() {
|
||||
expect(cubit.validateTitlesOfAllFilledOptions(), true);
|
||||
});
|
||||
|
||||
test('validateTitlesOfAllFilledOptions returns false when some titles are invalid', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('Valid Title');
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionTitle('AB'); // Invalid
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionTitle('Valid Title');
|
||||
expect(cubit.validateTitlesOfAllFilledOptions(), false);
|
||||
});
|
||||
test(
|
||||
'validateTitlesOfAllFilledOptions returns false when some titles are invalid',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('Valid Title');
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionTitle('AB'); // Invalid
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionTitle('Valid Title');
|
||||
expect(cubit.validateTitlesOfAllFilledOptions(), false);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateTitlesOfAllFilledOptions returns early when selectedOptionIndex is null', () {
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
cubit.setOptionTitle('Title 1');
|
||||
final result = cubit.validateTitlesOfAllFilledOptions();
|
||||
// Should only validate first option when selectedOptionIndex is null
|
||||
expect(result, isA<bool>());
|
||||
});
|
||||
test(
|
||||
'validateTitlesOfAllFilledOptions returns early when selectedOptionIndex is null',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
cubit.setOptionTitle('Title 1');
|
||||
final result = cubit.validateTitlesOfAllFilledOptions();
|
||||
// Should only validate first option when selectedOptionIndex is null
|
||||
expect(result, isA<bool>());
|
||||
},
|
||||
);
|
||||
|
||||
test('validateSelectedOptionDescription returns false for short description', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionDescription('AB');
|
||||
expect(cubit.validateSelectedOptionDescription(), false);
|
||||
expect(cubit.state.validationState.optionsValidationState[0].descriptionHasError, true);
|
||||
});
|
||||
test(
|
||||
'validateSelectedOptionDescription returns false for short description',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionDescription('AB');
|
||||
expect(cubit.validateSelectedOptionDescription(), false);
|
||||
expect(
|
||||
cubit
|
||||
.state
|
||||
.validationState
|
||||
.optionsValidationState[0]
|
||||
.descriptionHasError,
|
||||
true,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateSelectedOptionDescription returns true for valid description', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionDescription('Valid description');
|
||||
expect(cubit.validateSelectedOptionDescription(), true);
|
||||
expect(cubit.state.validationState.optionsValidationState[0].descriptionHasError, false);
|
||||
});
|
||||
test(
|
||||
'validateSelectedOptionDescription returns true for valid description',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionDescription('Valid description');
|
||||
expect(cubit.validateSelectedOptionDescription(), true);
|
||||
expect(
|
||||
cubit
|
||||
.state
|
||||
.validationState
|
||||
.optionsValidationState[0]
|
||||
.descriptionHasError,
|
||||
false,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateDescriptionsOfAllOptions validates all options', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
@@ -336,23 +439,29 @@ void main() {
|
||||
expect(cubit.validateDescriptionsOfAllOptions(), true);
|
||||
});
|
||||
|
||||
test('validateDescriptionsOfAllOptions returns false when some descriptions are invalid', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionDescription('Valid description');
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionDescription('AB'); // Invalid
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionDescription('Valid description');
|
||||
expect(cubit.validateDescriptionsOfAllOptions(), false);
|
||||
});
|
||||
test(
|
||||
'validateDescriptionsOfAllOptions returns false when some descriptions are invalid',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionDescription('Valid description');
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionDescription('AB'); // Invalid
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionDescription('Valid description');
|
||||
expect(cubit.validateDescriptionsOfAllOptions(), false);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateDescriptionsOfAllOptions returns early when selectedOptionIndex is null', () {
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
cubit.setOptionDescription('Description 1');
|
||||
final result = cubit.validateDescriptionsOfAllOptions();
|
||||
// Should only validate first option when selectedOptionIndex is null
|
||||
expect(result, isA<bool>());
|
||||
});
|
||||
test(
|
||||
'validateDescriptionsOfAllOptions returns early when selectedOptionIndex is null',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
cubit.setOptionDescription('Description 1');
|
||||
final result = cubit.validateDescriptionsOfAllOptions();
|
||||
// Should only validate first option when selectedOptionIndex is null
|
||||
expect(result, isA<bool>());
|
||||
},
|
||||
);
|
||||
|
||||
test('validateItemsOfAllFilledOptions validates all options', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
@@ -364,29 +473,41 @@ void main() {
|
||||
expect(cubit.validateItemsOfAllFilledOptions(), true);
|
||||
});
|
||||
|
||||
test('validateItemsOfAllFilledOptions returns false when some items are invalid', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionContent('Valid item', 0);
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionContent('AB', 0); // Invalid
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionContent('Valid item', 0);
|
||||
expect(cubit.validateItemsOfAllFilledOptions(), false);
|
||||
});
|
||||
test(
|
||||
'validateItemsOfAllFilledOptions returns false when some items are invalid',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionContent('Valid item', 0);
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionContent('AB', 0); // Invalid
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionContent('Valid item', 0);
|
||||
expect(cubit.validateItemsOfAllFilledOptions(), false);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateItemsOfAllFilledOptions returns false when items are empty', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
expect(cubit.validateItemsOfAllFilledOptions(), false);
|
||||
expect(cubit.state.validationState.optionsValidationState[0].isItemsEmpty, true);
|
||||
});
|
||||
test(
|
||||
'validateItemsOfAllFilledOptions returns false when items are empty',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
expect(cubit.validateItemsOfAllFilledOptions(), false);
|
||||
expect(
|
||||
cubit.state.validationState.optionsValidationState[0].isItemsEmpty,
|
||||
true,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateItemsOfAllFilledOptions returns early when selectedOptionIndex is null', () {
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
cubit.setOptionContent('Item 1', 0);
|
||||
final result = cubit.validateItemsOfAllFilledOptions();
|
||||
// Should only validate first option when selectedOptionIndex is null
|
||||
expect(result, isA<bool>());
|
||||
});
|
||||
test(
|
||||
'validateItemsOfAllFilledOptions returns early when selectedOptionIndex is null',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
cubit.setOptionContent('Item 1', 0);
|
||||
final result = cubit.validateItemsOfAllFilledOptions();
|
||||
// Should only validate first option when selectedOptionIndex is null
|
||||
expect(result, isA<bool>());
|
||||
},
|
||||
);
|
||||
|
||||
test('validateAllFields returns false when name is invalid', () {
|
||||
cubit.setName('AB');
|
||||
@@ -456,20 +577,20 @@ void main() {
|
||||
cubit.setPlanType([true, false, false, false]);
|
||||
final image = XFile('test_image.jpg');
|
||||
cubit.setImage(image);
|
||||
|
||||
|
||||
// Заполняем все три опции, так как validateItemsOfAllFilledOptions проверяет все
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('Valid Title 1');
|
||||
cubit.setPrice(1500.0);
|
||||
cubit.setOptionDescription('Valid description 1');
|
||||
cubit.setOptionContent('Valid item 1', 0);
|
||||
|
||||
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionTitle('Valid Title 2');
|
||||
cubit.setPrice(2000.0);
|
||||
cubit.setOptionDescription('Valid description 2');
|
||||
cubit.setOptionContent('Valid item 2', 0);
|
||||
|
||||
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionTitle('Valid Title 3');
|
||||
cubit.setPrice(2500.0);
|
||||
@@ -527,21 +648,24 @@ void main() {
|
||||
expect(cubit.validateAllFields(), false);
|
||||
});
|
||||
|
||||
test('validateAllFields returns false when option description is invalid', () {
|
||||
cubit.setName('Valid Name');
|
||||
cubit.setDetails('Valid description');
|
||||
cubit.setDuration(0);
|
||||
cubit.setPlanType([true, false, false, false]);
|
||||
final image = XFile('test_image.jpg');
|
||||
cubit.setImage(image);
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('Valid Title');
|
||||
cubit.setPrice(1500.0);
|
||||
cubit.setOptionDescription('AB'); // Invalid
|
||||
cubit.setOptionContent('Valid item', 0);
|
||||
test(
|
||||
'validateAllFields returns false when option description is invalid',
|
||||
() {
|
||||
cubit.setName('Valid Name');
|
||||
cubit.setDetails('Valid description');
|
||||
cubit.setDuration(0);
|
||||
cubit.setPlanType([true, false, false, false]);
|
||||
final image = XFile('test_image.jpg');
|
||||
cubit.setImage(image);
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('Valid Title');
|
||||
cubit.setPrice(1500.0);
|
||||
cubit.setOptionDescription('AB'); // Invalid
|
||||
cubit.setOptionContent('Valid item', 0);
|
||||
|
||||
expect(cubit.validateAllFields(), false);
|
||||
});
|
||||
expect(cubit.validateAllFields(), false);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateAllFields returns false when option items are invalid', () {
|
||||
cubit.setName('Valid Name');
|
||||
@@ -611,115 +735,143 @@ void main() {
|
||||
expect(cubit.state.planData.options[0].items.length, 1);
|
||||
});
|
||||
|
||||
test('setOptionContent - добавляет новый элемент когда индекс больше длины', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
expect(cubit.state.planData.options[0].items.length, 0);
|
||||
test(
|
||||
'setOptionContent - добавляет новый элемент когда индекс больше длины',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
expect(cubit.state.planData.options[0].items.length, 0);
|
||||
|
||||
cubit.setOptionContent('Item 1', 0);
|
||||
expect(cubit.state.planData.options[0].items.length, 1);
|
||||
cubit.setOptionContent('Item 1', 0);
|
||||
expect(cubit.state.planData.options[0].items.length, 1);
|
||||
|
||||
cubit.setOptionContent('Item 2', 1);
|
||||
expect(cubit.state.planData.options[0].items.length, 2);
|
||||
});
|
||||
cubit.setOptionContent('Item 2', 1);
|
||||
expect(cubit.state.planData.options[0].items.length, 2);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateTitlesOfAllFilledOptions - возвращает true когда selectedOptionIndex == null и все опции валидны', () {
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
cubit.setOptionTitle('Valid Title 1');
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('Valid Title 1');
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionTitle('Valid Title 2');
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionTitle('Valid Title 3');
|
||||
test(
|
||||
'validateTitlesOfAllFilledOptions - возвращает true когда selectedOptionIndex == null и все опции валидны',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
cubit.setOptionTitle('Valid Title 1');
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('Valid Title 1');
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionTitle('Valid Title 2');
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionTitle('Valid Title 3');
|
||||
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
final result = cubit.validateTitlesOfAllFilledOptions();
|
||||
expect(result, true);
|
||||
});
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
final result = cubit.validateTitlesOfAllFilledOptions();
|
||||
expect(result, true);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateTitlesOfAllFilledOptions - возвращает false когда selectedOptionIndex == null и опция 0 невалидна', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('AB'); // невалидное название
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
test(
|
||||
'validateTitlesOfAllFilledOptions - возвращает false когда selectedOptionIndex == null и опция 0 невалидна',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionTitle('AB'); // невалидное название
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
|
||||
final result = cubit.validateTitlesOfAllFilledOptions();
|
||||
expect(result, false);
|
||||
});
|
||||
final result = cubit.validateTitlesOfAllFilledOptions();
|
||||
expect(result, false);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateDescriptionsOfAllOptions - возвращает true когда selectedOptionIndex == null и все описания валидны', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionDescription('Valid Description 1');
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionDescription('Valid Description 2');
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionDescription('Valid Description 3');
|
||||
test(
|
||||
'validateDescriptionsOfAllOptions - возвращает true когда selectedOptionIndex == null и все описания валидны',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionDescription('Valid Description 1');
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionDescription('Valid Description 2');
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionDescription('Valid Description 3');
|
||||
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
final result = cubit.validateDescriptionsOfAllOptions();
|
||||
expect(result, true);
|
||||
});
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
final result = cubit.validateDescriptionsOfAllOptions();
|
||||
expect(result, true);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateDescriptionsOfAllOptions - возвращает false когда selectedOptionIndex == null и опция 0 невалидна', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionDescription('AB'); // невалидное описание
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
test(
|
||||
'validateDescriptionsOfAllOptions - возвращает false когда selectedOptionIndex == null и опция 0 невалидна',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionDescription('AB'); // невалидное описание
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
|
||||
final result = cubit.validateDescriptionsOfAllOptions();
|
||||
expect(result, false);
|
||||
});
|
||||
final result = cubit.validateDescriptionsOfAllOptions();
|
||||
expect(result, false);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateItemsOfAllFilledOptions - возвращает true когда selectedOptionIndex == null и все items валидны', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionContent('Valid Item 1', 0);
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionContent('Valid Item 2', 0);
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionContent('Valid Item 3', 0);
|
||||
test(
|
||||
'validateItemsOfAllFilledOptions - возвращает true когда selectedOptionIndex == null и все items валидны',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setOptionContent('Valid Item 1', 0);
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setOptionContent('Valid Item 2', 0);
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setOptionContent('Valid Item 3', 0);
|
||||
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
final result = cubit.validateItemsOfAllFilledOptions();
|
||||
expect(result, true);
|
||||
});
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
final result = cubit.validateItemsOfAllFilledOptions();
|
||||
expect(result, true);
|
||||
},
|
||||
);
|
||||
|
||||
test('validateItemsOfAllFilledOptions - возвращает false когда selectedOptionIndex == null и опция 0 имеет пустые items', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
// items пустые
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
test(
|
||||
'validateItemsOfAllFilledOptions - возвращает false когда selectedOptionIndex == null и опция 0 имеет пустые items',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
// items пустые
|
||||
cubit.setSelectedOptionIndex(null);
|
||||
|
||||
final result = cubit.validateItemsOfAllFilledOptions();
|
||||
expect(result, false);
|
||||
});
|
||||
final result = cubit.validateItemsOfAllFilledOptions();
|
||||
expect(result, false);
|
||||
},
|
||||
);
|
||||
|
||||
test('validatePriceOfAllFilledOptions - возвращает true когда все цены валидны', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setPrice(1500.0);
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setPrice(2000.0);
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setPrice(2500.0);
|
||||
test(
|
||||
'validatePriceOfAllFilledOptions - возвращает true когда все цены валидны',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setPrice(1500.0);
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setPrice(2000.0);
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setPrice(2500.0);
|
||||
|
||||
final result = cubit.validatePriceOfAllFilledOptions();
|
||||
expect(result, true);
|
||||
});
|
||||
final result = cubit.validatePriceOfAllFilledOptions();
|
||||
expect(result, true);
|
||||
},
|
||||
);
|
||||
|
||||
test('validatePriceOfAllFilledOptions - возвращает false когда опция 1 имеет невалидную цену', () {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setPrice(1500.0);
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setPrice(1000.0); // невалидная цена
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setPrice(2500.0);
|
||||
|
||||
final result = cubit.validatePriceOfAllFilledOptions();
|
||||
expect(result, false);
|
||||
});
|
||||
|
||||
test('setPlanType - не валидирует когда type.any((elem) => elem) == false', () {
|
||||
cubit.setPlanType([false, false, false, false]);
|
||||
expect(cubit.state.planData.type, [false, false, false, false]);
|
||||
// Валидация не должна вызываться, так как все элементы false
|
||||
});
|
||||
test(
|
||||
'validatePriceOfAllFilledOptions - возвращает false когда опция 1 имеет невалидную цену',
|
||||
() {
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
cubit.setPrice(1500.0);
|
||||
cubit.setSelectedOptionIndex(1);
|
||||
cubit.setPrice(1000.0); // невалидная цена
|
||||
cubit.setSelectedOptionIndex(2);
|
||||
cubit.setPrice(2500.0);
|
||||
|
||||
final result = cubit.validatePriceOfAllFilledOptions();
|
||||
expect(result, false);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'setPlanType - не валидирует когда type.any((elem) => elem) == false',
|
||||
() {
|
||||
cubit.setPlanType([false, false, false, false]);
|
||||
expect(cubit.state.planData.type, [false, false, false, false]);
|
||||
// Валидация не должна вызываться, так как все элементы false
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/create_plan/presentation/cubit/create_plan_cubit.dart';
|
||||
import 'package:eatvio_app/features/create_plan/presentation/cubit/create_plan_state.dart';
|
||||
import 'package:eatvio_app/features/create_plan/presentation/widgets/option_widget.dart';
|
||||
import 'package:eatvio_app/features/create_plan/presentation/widgets/select_exact_option_widget.dart';
|
||||
import 'package:eatvio_app/features/create_plan/repositories/create_plan_repository.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -12,12 +13,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'option_widget_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<CreatePlanCubit>()])
|
||||
void main() {
|
||||
group('OptionWidget smoke', () {
|
||||
setUpAll(() async {
|
||||
@@ -47,18 +43,8 @@ void main() {
|
||||
tester.view.physicalSize = const Size(800, 1200);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
|
||||
final cubit = MockCreatePlanCubit();
|
||||
final state = CreatePlanState.initial();
|
||||
|
||||
when(cubit.state).thenReturn(state);
|
||||
when(cubit.stream).thenAnswer((_) => Stream.value(state));
|
||||
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(cubit.setOptionTitle(any)).thenReturn(null);
|
||||
when(cubit.setOptionDescription(any)).thenReturn(null);
|
||||
when(cubit.setPrice(any)).thenReturn(null);
|
||||
when(cubit.setOptionContent(any, any)).thenReturn(null);
|
||||
when(cubit.removeOptionContentItem(any)).thenReturn(null);
|
||||
when(cubit.togglePersonalizedDietOptionState()).thenReturn(null);
|
||||
final cubit = CreatePlanCubit(createPlanRepository: _FakeCreatePlanRepository());
|
||||
addTearDown(cubit.close);
|
||||
|
||||
await tester.pumpWidget(BlocProvider<CreatePlanCubit>.value(value: cubit, child: wrap(const OptionWidget())));
|
||||
await tester.pump();
|
||||
@@ -66,5 +52,61 @@ void main() {
|
||||
|
||||
expect(find.byType(OptionWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('keeps title and price independent when switching options', (tester) async {
|
||||
tester.view.physicalSize = const Size(800, 1600);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
|
||||
final cubit = CreatePlanCubit(createPlanRepository: _FakeCreatePlanRepository());
|
||||
cubit.setSelectedOptionIndex(0);
|
||||
addTearDown(cubit.close);
|
||||
|
||||
await tester.pumpWidget(
|
||||
BlocProvider<CreatePlanCubit>.value(
|
||||
value: cubit,
|
||||
child: wrap(
|
||||
const Column(
|
||||
children: [
|
||||
SelectExactOptionWidget(),
|
||||
Expanded(child: SingleChildScrollView(child: OptionWidget())),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
|
||||
final firstFields = find.byType(TextFormField);
|
||||
await tester.enterText(firstFields.at(0), 'Economy title');
|
||||
await tester.enterText(firstFields.at(3), '1500');
|
||||
await tester.pump();
|
||||
|
||||
await tester.tap(find.text('2'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(cubit.state.selectedOptionIndex, 1);
|
||||
|
||||
final secondFields = find.byType(TextFormField);
|
||||
await tester.enterText(secondFields.at(0), 'Standard title');
|
||||
await tester.enterText(secondFields.at(3), '2500');
|
||||
await tester.pump();
|
||||
|
||||
expect(cubit.state.planData.options[0].short, 'Economy title');
|
||||
expect(cubit.state.planData.options[1].short, 'Standard title');
|
||||
expect(cubit.state.planData.options[0].price, 1500.0);
|
||||
expect(cubit.state.planData.options[1].price, 2500.0);
|
||||
|
||||
await tester.tap(find.text('1'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Economy title'), findsOneWidget);
|
||||
expect(cubit.state.planData.options[1].short, 'Standard title');
|
||||
expect(cubit.state.planData.options[1].price, 2500.0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class _FakeCreatePlanRepository extends Fake implements CreatePlanRepository {}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import 'package:eatvio_app/features/video_calls/services/video_call_audio_session_coordinator.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('VideoCallAudioSessionCoordinator iOS', () {
|
||||
test('start and stop go through the WebRTC audio session', () async {
|
||||
final calls = <String>[];
|
||||
final coordinator = VideoCallAudioSessionCoordinator(
|
||||
isIos: true,
|
||||
iosCallAudioSession: (method) async {
|
||||
calls.add(method);
|
||||
},
|
||||
);
|
||||
|
||||
expect(coordinator.isActive, isFalse);
|
||||
|
||||
await coordinator.start();
|
||||
expect(coordinator.isActive, isTrue);
|
||||
|
||||
final resumed = await coordinator.reactivate();
|
||||
expect(resumed, isTrue);
|
||||
|
||||
await coordinator.stop();
|
||||
expect(coordinator.isActive, isFalse);
|
||||
expect(calls, ['activate', 'activate', 'deactivate']);
|
||||
});
|
||||
|
||||
test('stop clears the active session when deactivate fails', () async {
|
||||
final coordinator = VideoCallAudioSessionCoordinator(
|
||||
isIos: true,
|
||||
iosCallAudioSession: (method) async {
|
||||
if (method == 'deactivate') {
|
||||
throw StateError('audio session busy');
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
await coordinator.start();
|
||||
await coordinator.stop();
|
||||
|
||||
expect(coordinator.isActive, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:eatvio_app/app_keys.dart';
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
@@ -18,28 +19,48 @@ import 'welcome_screen_test.mocks.dart';
|
||||
void main() {
|
||||
group('WelcomeScreen smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
dotenv.loadFromString(
|
||||
envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost',
|
||||
);
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
sl.registerLazySingleton<AppConfig>(
|
||||
() =>
|
||||
AppConfig(buildType: AppBuildType.tests)
|
||||
..setBaseUrl('http://localhost'),
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await sl.reset();
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
Widget wrap(Widget child, {double textScale = 1}) {
|
||||
return MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
builder: (context, appChild) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: appChild ?? const SizedBox.shrink(),
|
||||
);
|
||||
},
|
||||
routerConfig: GoRouter(
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(path: '/', builder: (context, state) => child),
|
||||
GoRoute(path: '/feed-screen', builder: (context, state) => const SizedBox.shrink()),
|
||||
GoRoute(path: '/auth-screen', builder: (context, state) => const SizedBox.shrink()),
|
||||
GoRoute(
|
||||
path: '/feed-screen',
|
||||
builder: (context, state) => const SizedBox.shrink(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/auth-screen',
|
||||
builder: (context, state) => const SizedBox.shrink(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -48,7 +69,9 @@ void main() {
|
||||
testWidgets('renders welcome screen', (tester) async {
|
||||
final prefs = MockPrefs();
|
||||
when(prefs.getBool(any)).thenReturn(false);
|
||||
when(prefs.setBool(any, any)).thenAnswer((_) async => Future<void>.value());
|
||||
when(
|
||||
prefs.setBool(any, any),
|
||||
).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
sl.registerLazySingleton<Prefs>(() => prefs);
|
||||
|
||||
@@ -59,5 +82,35 @@ void main() {
|
||||
expect(find.text('Добро пожаловать!'), findsOneWidget);
|
||||
expect(find.text('Начать пользоваться'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('start button stays tappable when system text is enlarged', (
|
||||
tester,
|
||||
) async {
|
||||
final prefs = MockPrefs();
|
||||
when(prefs.getBool(any)).thenReturn(false);
|
||||
when(
|
||||
prefs.setBool(any, any),
|
||||
).thenAnswer((_) async => Future<void>.value());
|
||||
sl.registerLazySingleton<Prefs>(() => prefs);
|
||||
|
||||
tester.view.physicalSize = const Size(390, 700);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(wrap(const WelcomeScreen(), textScale: 2.4));
|
||||
await tester.pump();
|
||||
|
||||
final button = find.byKey(AppKeys.welcomeScreenButton);
|
||||
await tester.ensureVisible(button);
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.tap(button);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Начать пользоваться'), findsNothing);
|
||||
verify(prefs.setBool(any, true)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user