Skip to content

Instantly share code, notes, and snippets.

@rafdls
Last active January 9, 2020 05:34
Show Gist options
  • Select an option

  • Save rafdls/85c2a6bcc3a0c44e6a1b93e2aba6e341 to your computer and use it in GitHub Desktop.

Select an option

Save rafdls/85c2a6bcc3a0c44e6a1b93e2aba6e341 to your computer and use it in GitHub Desktop.
Metaweather json parser util
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();
}
}
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'));
});
}
[
{
"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