-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
219 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,26 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart'; | ||
import 'package:http/testing.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:simple_weather/service_locator.dart'; | ||
import 'package:simple_weather/src/app.dart'; | ||
import 'package:simple_weather/src/app_config.dart'; | ||
import 'package:simple_weather/src/client/mocked/mock_weather_api_impl.dart'; | ||
import 'package:simple_weather/src/client/implementations/weather_api_impl.dart'; | ||
import 'package:simple_weather/src/client/weather_api.dart'; | ||
import 'package:simple_weather/src/services/implementations/location_service_impl.dart'; | ||
import 'package:simple_weather/src/services/location_service.dart'; | ||
import 'package:simple_weather/src/services/mocked/mock_location_service_impl.dart'; | ||
|
||
main() async { | ||
await registerDependencies(); | ||
runApp( | ||
AppConfig( | ||
environment: Environment.development, | ||
environment: Environment.production, | ||
child: App(), | ||
), | ||
); | ||
} | ||
|
||
const weatherJsonResponse = '''{ | ||
"coord": { | ||
"lon": -79.39, | ||
"lat": 43.65 | ||
}, | ||
"weather": [ | ||
{ | ||
"id": 800, | ||
"main": "Clear", | ||
"description": "clear sky", | ||
"icon": "01d" | ||
} | ||
], | ||
"base": "stations", | ||
"main": { | ||
"temp": 297.45, | ||
"pressure": 1019, | ||
"humidity": 60, | ||
"temp_min": 296.15, | ||
"temp_max": 299.15 | ||
}, | ||
"visibility": 14484, | ||
"wind": { | ||
"speed": 4.1, | ||
"deg": 180 | ||
}, | ||
"clouds": { | ||
"all": 1 | ||
}, | ||
"dt": 1532019600, | ||
"sys": { | ||
"type": 1, | ||
"id": 3721, | ||
"message": 0.0046, | ||
"country": "CA", | ||
"sunrise": 1531994053, | ||
"sunset": 1532047985 | ||
}, | ||
"id": 6167863, | ||
"name": "Downtown Toronto", | ||
"cod": 200 | ||
}'''; | ||
|
||
registerDependencies() async { | ||
ServiceLocator.reset(); | ||
final _mockSharedPrefs = MockSharedPreferences(); | ||
|
||
when(_mockSharedPrefs.getBool(typed(any))).thenReturn(true); | ||
when(_mockSharedPrefs.setBool(typed(any), typed(any))) | ||
.thenAnswer((_) => Future.value(true)); | ||
|
||
ServiceLocator.registerSingleton<SharedPreferences>(_mockSharedPrefs); | ||
ServiceLocator.registerSingleton<LocationService>(MockLocationService()); | ||
ServiceLocator.registerSingleton<WeatherApi>( | ||
MockWeatherApi( | ||
MockClient( | ||
(request) async => Response(weatherJsonResponse, 200), | ||
), | ||
"", | ||
), | ||
); | ||
ServiceLocator.registerSingleton<SharedPreferences>( | ||
await SharedPreferences.getInstance()); | ||
ServiceLocator.registerSingleton<LocationService>(LocationServiceImpl()); | ||
ServiceLocator.registerSingleton<WeatherApi>(WeatherApiImpl()); | ||
} | ||
|
||
class MockSharedPreferences extends Mock implements SharedPreferences {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart'; | ||
import 'package:http/testing.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:simple_weather/service_locator.dart'; | ||
import 'package:simple_weather/src/app.dart'; | ||
import 'package:simple_weather/src/app_config.dart'; | ||
import 'package:simple_weather/src/client/mocked/mock_weather_api_impl.dart'; | ||
import 'package:simple_weather/src/client/weather_api.dart'; | ||
import 'package:simple_weather/src/services/location_service.dart'; | ||
import 'package:simple_weather/src/services/mocked/mock_location_service_impl.dart'; | ||
|
||
main() async { | ||
await registerDependencies(); | ||
runApp( | ||
AppConfig( | ||
environment: Environment.development, | ||
child: App(), | ||
), | ||
); | ||
} | ||
|
||
registerDependencies() async { | ||
ServiceLocator.reset(); | ||
final _mockSharedPrefs = MockSharedPreferences(); | ||
|
||
when(_mockSharedPrefs.getBool(typed(any))).thenReturn(true); | ||
when(_mockSharedPrefs.setBool(typed(any), typed(any))) | ||
.thenAnswer((_) => Future.value(true)); | ||
|
||
ServiceLocator.registerSingleton<SharedPreferences>(_mockSharedPrefs); | ||
ServiceLocator.registerSingleton<LocationService>(MockLocationService()); | ||
ServiceLocator.registerSingleton<WeatherApi>( | ||
MockWeatherApi( | ||
MockClient( | ||
(request) async => Response(weatherJsonResponse, 200), | ||
), | ||
"", | ||
), | ||
); | ||
} | ||
|
||
class MockSharedPreferences extends Mock implements SharedPreferences {} | ||
|
||
const weatherJsonResponse = '''{ | ||
"coord": { | ||
"lon": -79.39, | ||
"lat": 43.65 | ||
}, | ||
"weather": [ | ||
{ | ||
"id": 800, | ||
"main": "Clear", | ||
"description": "clear sky", | ||
"icon": "01d" | ||
} | ||
], | ||
"base": "stations", | ||
"main": { | ||
"temp": 297.45, | ||
"pressure": 1019, | ||
"humidity": 60, | ||
"temp_min": 296.15, | ||
"temp_max": 299.15 | ||
}, | ||
"visibility": 14484, | ||
"wind": { | ||
"speed": 4.1, | ||
"deg": 180 | ||
}, | ||
"clouds": { | ||
"all": 1 | ||
}, | ||
"dt": 1532019600, | ||
"sys": { | ||
"type": 1, | ||
"id": 3721, | ||
"message": 0.0046, | ||
"country": "CA", | ||
"sunrise": 1531994053, | ||
"sunset": 1532047985 | ||
}, | ||
"id": 6167863, | ||
"name": "Downtown Toronto", | ||
"cod": 200 | ||
}'''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart'; | ||
import 'package:http/testing.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:simple_weather/service_locator.dart'; | ||
import 'package:simple_weather/src/app.dart'; | ||
import 'package:simple_weather/src/app_config.dart'; | ||
import 'package:simple_weather/src/client/mocked/mock_weather_api_impl.dart'; | ||
import 'package:simple_weather/src/client/weather_api.dart'; | ||
import 'package:simple_weather/src/services/location_service.dart'; | ||
import 'package:simple_weather/src/services/mocked/mock_location_service_impl.dart'; | ||
|
||
main() async { | ||
await registerDependencies(); | ||
runApp( | ||
AppConfig( | ||
environment: Environment.tests, | ||
child: App(), | ||
), | ||
); | ||
} | ||
|
||
const weatherJsonResponse = '''{ | ||
"coord": { | ||
"lon": -79.39, | ||
"lat": 43.65 | ||
}, | ||
"weather": [ | ||
{ | ||
"id": 800, | ||
"main": "Clear", | ||
"description": "clear sky", | ||
"icon": "01d" | ||
} | ||
], | ||
"base": "stations", | ||
"main": { | ||
"temp": 297.45, | ||
"pressure": 1019, | ||
"humidity": 60, | ||
"temp_min": 296.15, | ||
"temp_max": 299.15 | ||
}, | ||
"visibility": 14484, | ||
"wind": { | ||
"speed": 4.1, | ||
"deg": 180 | ||
}, | ||
"clouds": { | ||
"all": 1 | ||
}, | ||
"dt": 1532019600, | ||
"sys": { | ||
"type": 1, | ||
"id": 3721, | ||
"message": 0.0046, | ||
"country": "CA", | ||
"sunrise": 1531994053, | ||
"sunset": 1532047985 | ||
}, | ||
"id": 6167863, | ||
"name": "Downtown Toronto", | ||
"cod": 200 | ||
}'''; | ||
|
||
registerDependencies() async { | ||
ServiceLocator.reset(); | ||
final _mockSharedPrefs = MockSharedPreferences(); | ||
|
||
when(_mockSharedPrefs.getBool(typed(any))).thenReturn(true); | ||
when(_mockSharedPrefs.setBool(typed(any), typed(any))) | ||
.thenAnswer((_) => Future.value(true)); | ||
|
||
ServiceLocator.registerSingleton<SharedPreferences>(_mockSharedPrefs); | ||
ServiceLocator.registerSingleton<LocationService>(MockLocationService()); | ||
ServiceLocator.registerSingleton<WeatherApi>( | ||
MockWeatherApi( | ||
MockClient( | ||
(request) async => Response(weatherJsonResponse, 200), | ||
), | ||
"", | ||
), | ||
); | ||
} | ||
|
||
class MockSharedPreferences extends Mock implements SharedPreferences {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class AppConstants { | ||
static const apiKey = "OWM_API_KEY"; | ||
static const imageUrl = 'http://openweathermap.org/img/w/'; | ||
static const apiKey = "9330c38e200912fe46e8abd5f99d98e0"; | ||
static const imageUrl = 'https://openweathermap.org/img/w/'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.