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

Issue 915: Stop/start Location manager based on listeners registered. #999

Merged
merged 16 commits into from
Oct 2, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix unit tests
  • Loading branch information
soumyashisPR committed Aug 23, 2020
commit ed46202a674aa1948e44c1de965e5533abe8158e
37 changes: 19 additions & 18 deletions __tests__/components/UserLocation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,20 @@ describe('UserLocation', () => {
};

expect(ul.state).toStrictEqual(initialState);
expect(ul.locationManagerRunning).toStrictEqual(false);
expect(ul._isLocationManagerRequired).toStrictEqual(false);
});

// TODO: replace object { running: boolean } argument with simple boolean
// TODO: replace object { required: boolean } argument with simple boolean
describe('#setLocationManager', () => {
test('called with "running" true', async () => {
test('called with "required" true', async () => {
const lastKnownLocation = [4.1036916, 51.5462244];
const heading = 251.5358428955078;

expect(ul.locationManagerRunning).toStrictEqual(false);
expect(ul._isLocationManagerRequired).toStrictEqual(false);

await ul.setLocationManager({running: true});
await ul.setLocationManager({required: true});

expect(ul.locationManagerRunning).toStrictEqual(true);
expect(ul._isLocationManagerRequired).toStrictEqual(true);
expect(locationManager.start).toHaveBeenCalledTimes(1);
expect(locationManager.getLastKnownLocation).toHaveBeenCalledTimes(1);
expect(ul.setState).toHaveBeenCalledTimes(1);
Expand All @@ -195,48 +195,49 @@ describe('UserLocation', () => {
expect(locationManager.stop).not.toHaveBeenCalled();
});

test('called with "running" false', async () => {
test('called with "required" false', async () => {
// start
expect(ul.locationManagerRunning).toStrictEqual(false);
await ul.setLocationManager({running: true});
expect(ul.locationManagerRunning).toStrictEqual(true);
expect(ul._isLocationManagerRequired).toStrictEqual(false);
await ul.setLocationManager({required: true});
expect(ul._isLocationManagerRequired).toStrictEqual(true);

// stop
await ul.setLocationManager({running: false});
await ul.setLocationManager({required: false});

expect(ul.locationManagerRunning).toStrictEqual(false);
expect(ul._isLocationManagerRequired).toStrictEqual(false);
// only once from start
expect(locationManager.start).toHaveBeenCalledTimes(1);
expect(locationManager.stop).toHaveBeenCalledTimes(1);
// stop should not be called
expect(locationManager.stop).not.toHaveBeenCalled();
});
});

describe('#needsLocationManagerRunning', () => {
describe('#isLocationManagerRequired', () => {
test('returns true correctly', () => {
// default props "onUpdate: undefined, visible: true"
expect(ul.needsLocationManagerRunning()).toStrictEqual(true);
expect(ul.isLocationManagerRequired()).toStrictEqual(true);

ul.props = {
onUpdate: () => {},
visible: true,
};

expect(ul.needsLocationManagerRunning()).toStrictEqual(true);
expect(ul.isLocationManagerRequired()).toStrictEqual(true);

ul.props = {
onUpdate: () => {},
visible: false,
};

expect(ul.needsLocationManagerRunning()).toStrictEqual(true);
expect(ul.isLocationManagerRequired()).toStrictEqual(true);
});

test('returns false correctly', () => {
ul.props = {
visible: false,
};

expect(ul.needsLocationManagerRunning()).toStrictEqual(false);
expect(ul.isLocationManagerRequired()).toStrictEqual(false);
});
});

Expand Down