Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Release/1.1.1 #84

Merged
merged 20 commits into from
Sep 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: objective-c
install:
- brew remove --force xctool
- brew install xctool --HEAD
osx_image: xcode7
xcode_project: Example/HNKGooglePlacesAutocomplete-Example.xcworkspace
xcode_scheme: HNKGooglePlacesAutocomplete-Example
podfile: Example/Podfile

script:
- xctool test -workspace Example/HNKGooglePlacesAutocomplete-Example.xcworkspace -scheme HNKGooglePlacesAutocomplete-Example -sdk iphonesimulator8.1
- xcodebuild test -workspace Example/HNKGooglePlacesAutocomplete-Example.xcworkspace -scheme HNKGooglePlacesAutocomplete-Example -sdk iphonesimulator
- pod lib lint --quick
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ @implementation HNKDemoAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[HNKGooglePlacesAutocompleteQuery setupSharedQueryWithAPIKey:kHNKDemoGooglePlacesAutocompleteApiKey];
[HNKGooglePlacesAutocompleteQuery setupSharedQueryWithAPIKey: kHNKDemoGooglePlacesAutocompleteApiKey];

return YES;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
completion:^(NSArray *places, NSError *error) {
if (error) {
NSLog(@"ERROR: %@", error);
[self handleSearchError:error];
} else {
self.searchResults = places;
[self.tableView reloadData];
Expand Down Expand Up @@ -134,4 +135,15 @@ - (void)recenterMapToPlacemark:(CLPlacemark *)placemark
[self.mapView setRegion:region animated:YES];
}

- (void)handleSearchError:(NSError *)error
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error"
message:error.localizedDescription
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];

[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,56 @@

describe(@"HNKGooglePlacesAutocompleteQueryConfig", ^{

describe(@"configWithConfig", ^{

__block HNKGooglePlacesAutocompleteQueryConfig *testInstance;

beforeEach(^{

HNKGooglePlacesAutocompleteQueryConfig *testConfig = [[HNKGooglePlacesAutocompleteQueryConfig alloc] init];
testConfig.country = @"fr";
testConfig.filter = HNKGooglePlaceTypeAutocompleteFilterCity;
testConfig.language = @"pt";
testConfig.latitude = 100;
testConfig.longitude = 50;
testConfig.offset = 3;
testConfig.searchRadius = 100000;

testInstance = [HNKGooglePlacesAutocompleteQueryConfig configWithConfig:testConfig];

});

it(@"Should return a new config with same config values", ^{

[[testInstance.country should] equal:@"fr"];
[[theValue(testInstance.filter) should] equal:theValue(HNKGooglePlaceTypeAutocompleteFilterCity)];
[[testInstance.language should] equal:@"pt"];
[[theValue(testInstance.latitude) should] equal:theValue(100)];
[[theValue(testInstance.longitude) should] equal:theValue(50)];
[[theValue(testInstance.offset) should] equal:theValue(3)];
[[theValue(testInstance.searchRadius) should] equal:theValue(100000)];

});
});

describe(@"defaultConfig", ^{

it(@"Should have default config values", ^{

HNKGooglePlacesAutocompleteQueryConfig *defaultConfig = [HNKGooglePlacesAutocompleteQueryConfig defaultConfig];

[[defaultConfig.country should] beNil];
[[theValue(defaultConfig.filter) should] equal:theValue(HNKGooglePlaceTypeAutocompleteFilterAll)];
[[defaultConfig.language should] beNil];
[[theValue(defaultConfig.latitude) should] equal:theValue(0)];
[[theValue(defaultConfig.longitude) should] equal:theValue(0)];
[[theValue(defaultConfig.offset) should] equal:theValue(NSNotFound)];
[[theValue(defaultConfig.searchRadius) should] equal:theValue(20000000)];

});

});

describe(@"translateToServerRequestParameters",
^{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

SPEC_BEGIN(HNKGooglePlacesAutocompleteQueryResponseSpec)

__block HNKGooglePlacesAutocompleteQueryResponse *testInstance;
__block NSDictionary *json;
__block NSDictionary *errorJSON;

beforeAll(^{

Expand All @@ -35,52 +35,82 @@
}
],
@"status" : @"OK"
};

testInstance = [HNKGooglePlacesAutocompleteQueryResponse modelFromJSONDictionary:json];
};

errorJSON = @{
@"error_message" : @"The provided API key is invalid.",
@"predictions" : @[],
@"status" : @"REQUEST_DENIED"
};

});

describe(@"HNKGooglePlacesAutocompleteQueryResponse", ^{

specify(^{

[[testInstance should] beNonNil];

});

describe(@"Deserialization",
^{

it(@"Should assign properties correctly",
^{
[[theValue(testInstance.status) should]
equal:theValue(HNKGooglePlacesAutocompleteQueryResponseStatusOK)];

HNKGooglePlacesAutocompletePlace *place = testInstance.places[0];
[[place.name should] equal:@"Victoria, BC, Canadá"];

HNKGooglePlacesAutocompletePlaceSubstring *substring = place.substrings[0];
[[theValue(substring.length) should] equal:theValue(4)];
[[theValue(substring.offset) should] equal:theValue(0)];

[[place.placeId should] equal:@"ChIJcWGw3Ytzj1QR7Ui7HnTz6Dg"];

HNKGooglePlacesAutocompletePlaceTerm *term1 = place.terms[0];
HNKGooglePlacesAutocompletePlaceTerm *term2 = place.terms[1];
HNKGooglePlacesAutocompletePlaceTerm *term3 = place.terms[2];
[[theValue(term1.offset) should] equal:theValue(0)];
[[term1.value should] equal:@"Victoria"];
[[theValue(term2.offset) should] equal:theValue(10)];
[[term2.value should] equal:@"BC"];
[[theValue(term3.offset) should] equal:theValue(14)];
[[term3.value should] equal:@"Canadá"];

[[place.types[0] should] equal:theValue(HNKGooglePlaceTypeLocality)];
[[place.types[1] should] equal:theValue(HNKGooglePlaceTypePolitical)];
[[place.types[2] should] equal:theValue(HNKGooglePlaceTypeGeocode)];

});

context(@"Places returned", ^ {

__block HNKGooglePlacesAutocompleteQueryResponse *testInstance;

beforeEach(^ {

testInstance = [HNKGooglePlacesAutocompleteQueryResponse modelFromJSONDictionary:json];

});

it(@"Should assign properties correctly",
^{
[[theValue(testInstance.status) should]
equal:theValue(HNKGooglePlacesAutocompleteQueryResponseStatusOK)];
[[testInstance.errorMessage should] beNil];

HNKGooglePlacesAutocompletePlace *place = testInstance.places[0];
[[place.name should] equal:@"Victoria, BC, Canadá"];

HNKGooglePlacesAutocompletePlaceSubstring *substring = place.substrings[0];
[[theValue(substring.length) should] equal:theValue(4)];
[[theValue(substring.offset) should] equal:theValue(0)];

[[place.placeId should] equal:@"ChIJcWGw3Ytzj1QR7Ui7HnTz6Dg"];

HNKGooglePlacesAutocompletePlaceTerm *term1 = place.terms[0];
HNKGooglePlacesAutocompletePlaceTerm *term2 = place.terms[1];
HNKGooglePlacesAutocompletePlaceTerm *term3 = place.terms[2];
[[theValue(term1.offset) should] equal:theValue(0)];
[[term1.value should] equal:@"Victoria"];
[[theValue(term2.offset) should] equal:theValue(10)];
[[term2.value should] equal:@"BC"];
[[theValue(term3.offset) should] equal:theValue(14)];
[[term3.value should] equal:@"Canadá"];

[[place.types[0] should] equal:theValue(HNKGooglePlaceTypeLocality)];
[[place.types[1] should] equal:theValue(HNKGooglePlaceTypePolitical)];
[[place.types[2] should] equal:theValue(HNKGooglePlaceTypeGeocode)];

});
});

context(@"Error returned", ^ {

__block HNKGooglePlacesAutocompleteQueryResponse *testInstance;

beforeEach(^ {

testInstance = [HNKGooglePlacesAutocompleteQueryResponse modelFromJSONDictionary:errorJSON];

});

it(@"Should assign properties correctly",
^{
[[theValue(testInstance.status) should]
equal:theValue(HNKGooglePlacesAutocompleteQueryResponseStatusRequestDenied)];
[[testInstance.errorMessage should] equal:@"The provided API key is invalid."];
[[testInstance.places should] beEmpty];

});
});

});

Expand Down