Skip to content

Commit

Permalink
test: fix up async geolocation test
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed Jul 9, 2020
1 parent 11a7a5c commit 4ccef3e
Showing 1 changed file with 39 additions and 41 deletions.
80 changes: 39 additions & 41 deletions tests/Resources/ti.geolocation.addontest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,48 @@
'use strict';
const should = require('./utilities/assertions');

describe.android('Titanium.Geolocation', function () {
// Methods
describe('Titanium.Geolocation', function () {
this.timeout(6e4); // 60 sec

it('async #forwardGeocoder()', () => {
this.timeout(6e4); // 60 sec

should(Ti.Geolocation.forwardGeocoder).be.a.Function;
return Ti.Geolocation.forwardGeocoder('440 N Bernardo Ave, Mountain View')
.then((data) => {
should(data).have.property('success').which.is.a.Boolean;
should(data.success).be.eql(true);
should(data).have.property('code').which.is.a.Number;
should(data.code).be.eql(0);
should(data.latitude).be.approximately(37.387, 0.002); // iOS gives: 37.38605, Windows does 37.3883645
should(data.longitude).be.approximately(-122.065, 0.02); // WIndows gives: -122.0512682, iOS gives -122.08385
return;
});
// NOTE: Because we're using ti-mocha, which is based on a very old mcoah, we can't use async/await or return a Promise
// for async tests. We have to use a callback and have the promise call the callback
it.android('async #forwardGeocoder()', finish => {
should(Ti.Geolocation.forwardGeocoder).be.a.Function();
const result = Ti.Geolocation.forwardGeocoder('440 N Bernardo Ave, Mountain View');
result.should.be.a.Promise();
result.then(data => {
should(data).have.property('success').which.is.a.Boolean();
should(data.success).be.eql(true);
should(data).have.property('code').which.is.a.Number();
should(data.code).be.eql(0);
should(data.latitude).be.approximately(37.387, 0.004); // iOS: 37.38605, Windows: 37.3883645, Android: 37.3909049
should(data.longitude).be.approximately(-122.065, 0.02); // Windows: -122.0512682, iOS: -122.08385, Android: -122.
return finish();
}).catch(e => finish(e));
});

// FIXME The address object is different from platform to platform! https://jira.appcelerator.org/browse/TIMOB-23496
it('async #reverseGeocoder()', () => {
this.timeout(6e4); // 60 sec

should(Ti.Geolocation.reverseGeocoder).be.a.Function;
return Ti.Geolocation.reverseGeocoder(37.3883645, -122.0512682)
.then((data) => {
should(data).have.property('success').which.is.a.Boolean;
should(data.success).be.eql(true);
should(data).have.property('code').which.is.a.Number;
should(data.code).be.eql(0);
// FIXME error property is missing altogether on success for iOS...
// should(data).have.property('error'); // undefined on success, holds error message as String otherwise.
should(data).have.property('places').which.is.an.Array;
it.android('async #reverseGeocoder()', finish => {
should(Ti.Geolocation.reverseGeocoder).be.a.Function();
const result = Ti.Geolocation.reverseGeocoder(37.3883645, -122.0512682);
result.should.be.a.Promise();
result.then(data => {
should(data).have.property('success').which.is.a.Boolean();
should(data.success).be.eql(true);
should(data).have.property('code').which.is.a.Number();
should(data.code).be.eql(0);
// FIXME error property is missing altogether on success for iOS...
// should(data).have.property('error'); // undefined on success, holds error message as String otherwise.
should(data).have.property('places').which.is.an.Array();

should(data.places[0].postalCode).be.eql('94043');
should(data.places[0].zipcode).be.eql('94043');
should(data.places[0]).have.property('latitude').which.is.a.Number; // docs say String!
should(data.places[0]).have.property('longitude').which.is.a.Number; // docs say String!
should(data.places[0].country).be.eql('USA');
should(data.places[0].state).be.eql('California');
should(data.places[0].country_code).be.eql('US');
should(data.places[0]).have.property('city').which.is.a.String;
should(data.places[0]).have.property('address').which.is.a.String;
return;
});
should(data.places[0].postalCode).be.eql('94043');
should(data.places[0]).have.property('latitude').which.is.a.Number();
should(data.places[0]).have.property('longitude').which.is.a.Number();
should(data.places[0].country).be.oneOf('USA', 'United States of America');
should(data.places[0].state).be.eql('California');
should(data.places[0].countryCode).be.eql('US');
should(data.places[0]).have.property('city').which.is.a.String();
should(data.places[0]).have.property('address').which.is.a.String();
return finish();
}).catch(e => finish(e));
});
});

0 comments on commit 4ccef3e

Please sign in to comment.