Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Location support #195

Merged
merged 4 commits into from
Aug 6, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions detox/test/e2e/o-location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe('location', () => {
it('Location should be unavabilable', async () => {
await device.relaunchApp({permissions: {location: 'never'}});
await element(by.label('Location')).tap();
await element(by.id('getLocationButton')).tap();
await expect(element(by.id('error'))).toBeVisible();
});

it('Should receive location (20,20)', async () => {
await device.relaunchApp({permissions: {location: 'always'}});
await device.setLocation(20, 20);
await element(by.label('Location')).tap();
await element(by.id('getLocationButton')).tap();
await expect(element(by.text('Latitude: 20'))).toBeVisible();
await expect(element(by.text('Longitude: 20'))).toBeVisible();
});
});
67 changes: 67 additions & 0 deletions detox/test/src/Screens/LocationScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { Component } from 'react';
import {
Text,
View,
Button
} from 'react-native';

export default class LocationScreen extends Component {

constructor(props) {
super(props);
this.state = {
locationRequested: false,
coordinates: null
}

this.getLocation();
}

async getLocation() {
function success(pos) {
this.setState({
coordinates: pos.coords
});
};

function error(err) {
this.setState({
coordinates: null
});
};

await navigator.geolocation.getCurrentPosition(success.bind(this), error.bind(this));
}

render() {
if(!this.state.locationRequested) {
return (
<View style={{ flex: 1, paddingTop: 20, justifyContent: 'center', alignItems: 'center' }}>
<Button
testID="getLocationButton"
title="get location"
onPress={async () => {
await this.getLocation();
this.setState({locationRequested: true});
}}
/>
</View>
);
}

if (this.state.coordinates) {
return (
<View style={{ flex: 1, paddingTop: 20, justifyContent: 'center', alignItems: 'center' }}>
<Text testID="latitude" style={{ marginBottom: 20 }}>Latitude: {this.state.coordinates.latitude}</Text>
<Text testID="longitude" style={{ marginBottom: 20 }}>Longitude: {this.state.coordinates.longitude}</Text>
</View>
);
} else {
return (
<View style={{ flex: 1, paddingTop: 20, justifyContent: 'center', alignItems: 'center' }}>
<Text testID="error" style={{ marginBottom: 20 }}>Location unavailable</Text>
</View>
);
}
}
}
4 changes: 3 additions & 1 deletion detox/test/src/Screens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Orientation from './Orientation';
import Permissions from './Permissions';
import NetworkScreen from './NetworkScreen';
import AnimationsScreen from './AnimationsScreen';
import LocationScreen from './LocationScreen';

export {
SanityScreen,
Expand All @@ -23,5 +24,6 @@ export {
Orientation,
Permissions,
NetworkScreen,
AnimationsScreen
AnimationsScreen,
LocationScreen
};
1 change: 1 addition & 0 deletions detox/test/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class example extends Component {
{this.renderScreenButton('Permissions', Screens.Permissions)}
{this.renderScreenButton('Network', Screens.NetworkScreen)}
{this.renderScreenButton('Animations', Screens.AnimationsScreen)}
{this.renderScreenButton('Location', Screens.LocationScreen)}
</View>
);
}
Expand Down