forked from eatvio/eatvio_app
feat(tests): tests coverage 67.2
This commit is contained in:
@@ -14,6 +14,7 @@ class MockPrefs extends Mock implements Prefs {}
|
||||
class FakeUserRegistrationSheet extends Fake implements UserRegistrationSheet {}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
setUpAll(() {
|
||||
registerFallbackValue(FakeUserRegistrationSheet());
|
||||
});
|
||||
@@ -184,5 +185,75 @@ void main() {
|
||||
|
||||
expect(() => cubit.getLocationsByCoordinates(latitude, longitude), throwsException);
|
||||
});
|
||||
|
||||
test('getLocationsByQuery handles empty query', () async {
|
||||
const query = '';
|
||||
const expectedLocations = <String>[];
|
||||
const locationModel = LocationModel(locations: expectedLocations, responseBody: '{"locations": []}');
|
||||
|
||||
when(() => mockRepository.getLocationsListByQuery(query)).thenAnswer((_) async => locationModel);
|
||||
|
||||
final result = await cubit.getLocationsByQuery(query);
|
||||
|
||||
expect(result, isEmpty);
|
||||
expect(cubit.state.sheet.responseBody, locationModel.responseBody);
|
||||
});
|
||||
|
||||
test('getLocationsByCoordinates handles empty strings', () async {
|
||||
const latitude = '';
|
||||
const longitude = '';
|
||||
const expectedLocations = <String>[];
|
||||
const locationModel = LocationModel(locations: expectedLocations, responseBody: '{"locations": []}');
|
||||
|
||||
when(() => mockRepository.getLocationsListByCoordinates(latitude, longitude)).thenAnswer((_) async => locationModel);
|
||||
|
||||
final result = await cubit.getLocationsByCoordinates(latitude, longitude);
|
||||
|
||||
expect(result, isEmpty);
|
||||
expect(cubit.state.sheet.responseBody, locationModel.responseBody);
|
||||
});
|
||||
|
||||
test('getLocationsByQuery handles special characters in query', () async {
|
||||
const query = 'São Paulo, Brasil';
|
||||
const expectedLocations = ['São Paulo, Brasil'];
|
||||
const locationModel = LocationModel(locations: expectedLocations, responseBody: '{"locations": ["São Paulo, Brasil"]}');
|
||||
|
||||
when(() => mockRepository.getLocationsListByQuery(query)).thenAnswer((_) async => locationModel);
|
||||
|
||||
final result = await cubit.getLocationsByQuery(query);
|
||||
|
||||
expect(result, expectedLocations);
|
||||
verify(() => mockRepository.getLocationsListByQuery(query)).called(1);
|
||||
});
|
||||
|
||||
test('getLocationsByQuery handles very long query', () async {
|
||||
final query = 'A' * 1000;
|
||||
const expectedLocations = <String>[];
|
||||
const locationModel = LocationModel(locations: expectedLocations, responseBody: '{"locations": []}');
|
||||
|
||||
when(() => mockRepository.getLocationsListByQuery(query)).thenAnswer((_) async => locationModel);
|
||||
|
||||
final result = await cubit.getLocationsByQuery(query);
|
||||
|
||||
expect(result, isEmpty);
|
||||
verify(() => mockRepository.getLocationsListByQuery(query)).called(1);
|
||||
});
|
||||
|
||||
test('getLocationsByCoordinates handles negative coordinates', () async {
|
||||
const latitude = '-90.0';
|
||||
const longitude = '-180.0';
|
||||
const expectedLocations = ['Antarctica'];
|
||||
const locationModel = LocationModel(locations: expectedLocations, responseBody: '{"locations": ["Antarctica"]}');
|
||||
|
||||
when(() => mockRepository.getLocationsListByCoordinates(latitude, longitude)).thenAnswer((_) async => locationModel);
|
||||
|
||||
final result = await cubit.getLocationsByCoordinates(latitude, longitude);
|
||||
|
||||
expect(result, expectedLocations);
|
||||
verify(() => mockRepository.getLocationsListByCoordinates(latitude, longitude)).called(1);
|
||||
});
|
||||
|
||||
// Тесты для tryRegistration пропущены, так как они требуют сложной настройки
|
||||
// AppMetrica, FirebaseApi, TokenStorage и AppRouter, что сложно в unit-тестах
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user