Last active
January 9, 2020 05:34
-
-
Save rafdls/85c2a6bcc3a0c44e6a1b93e2aba6e341 to your computer and use it in GitHub Desktop.
Metaweather json parser util
This file contains hidden or 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
| import 'package:flutter/material.dart'; | |
| import 'package:flutter_unit_testing/bloc/weather_model.dart'; | |
| import 'package:intl/intl.dart'; | |
| import 'package:weather_icons/weather_icons.dart'; | |
| class MetaweatherUtil { | |
| String jsonToLocationId(List<dynamic> jsonList) { | |
| return jsonList[0]['woeid'].toString(); | |
| } | |
| } |
This file contains hidden or 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
| import 'dart:convert'; | |
| import 'package:flutter_test/flutter_test.dart'; | |
| import 'package:flutter_unit_testing/repository/metaweather_util.dart'; | |
| void main() { | |
| test('jsonToLocationId should get current location id', () { | |
| final MetaweatherUtil metaweatherUtil = MetaweatherUtil(); | |
| final List<dynamic> locationResults = json.decode( | |
| '[{"distance":1836,"title":"Santa Cruz","location_type":"City","woeid":2488853,"latt_long":"36.974018,-122.030952"}]'); | |
| final actualResult = metaweatherUtil.jsonToLocationId(locationResults); | |
| expect(actualResult, equals('2488853')); | |
| }); | |
| } |
This file contains hidden or 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
| [ | |
| { | |
| "distance":1836, | |
| "title":"Santa Cruz", | |
| "location_type":"City", | |
| "woeid":2488853, | |
| "latt_long":"36.974018,-122.030952" | |
| } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment