Update OSM data when opening saved places
All checks were successful
CI / Lint (pull_request) Successful in 49s
CI / Test (pull_request) Successful in 57s
Release Drafter / Update release notes draft (pull_request) Successful in 19s

This commit is contained in:
2026-03-18 14:33:27 +04:00
parent f7c40095d5
commit bdd5db157c
4 changed files with 354 additions and 1 deletions

View File

@@ -125,4 +125,60 @@ module('Unit | Route | place', function (hooks) {
assert.notOk(fetchCalled, 'fetchOsmObject should NOT be called for nodes');
});
test('setupController triggers checkUpdates', async function (assert) {
let route = this.owner.lookup('route:place');
// Stub Storage Service
let refreshPlaceCalled = false;
class StorageStub extends Service {
async refreshPlace(place) {
refreshPlaceCalled = true;
assert.strictEqual(place.id, '123', 'Passed correct place to storage');
return {
...place,
title: 'Updated Title',
};
}
}
// Stub MapUi Service
let selectPlaceCalled = false;
class MapUiStub extends Service {
selectPlace(place, options) {
selectPlaceCalled = true;
assert.strictEqual(
place.title,
'Updated Title',
'Selected updated place'
);
assert.ok(options.preventZoom, 'Prevented zoom on update');
}
stopSearch() {}
}
this.owner.register('service:storage', StorageStub);
this.owner.register('service:map-ui', MapUiStub);
let model = {
id: '123',
osmId: '456',
osmType: 'node',
title: 'Original Title',
};
let controller = {};
// Trigger setupController
route.setupController(controller, model);
// checkUpdates is async and not awaited in setupController, so we need to wait a tick
await new Promise((resolve) => setTimeout(resolve, 10));
assert.ok(refreshPlaceCalled, 'refreshPlace should be called');
assert.ok(
selectPlaceCalled,
'mapUi.selectPlace should be called with update'
);
});
});

View File

@@ -0,0 +1,202 @@
import { module, test } from 'qunit';
import { setupTest } from 'marco/tests/helpers';
import Service from '@ember/service';
module('Unit | Service | storage', function (hooks) {
setupTest(hooks);
test('refreshPlace skips invalid places', async function (assert) {
let service = this.owner.lookup('service:storage');
let result = await service.refreshPlace({});
assert.strictEqual(result, null);
});
test('refreshPlace detects coordinate drift', async function (assert) {
let service = this.owner.lookup('service:storage');
// Stub OSM Service
class OsmStub extends Service {
async fetchOsmObject(id, type) {
return {
osmId: id,
osmType: type,
lat: 52.5201, // Changed significantly from 52.5200
lon: 13.405,
osmTags: { name: 'Foo' },
};
}
}
this.owner.register('service:osm', OsmStub);
// Mock storage update
let updatePlaceCalled = false;
service.updatePlace = async (place) => {
updatePlaceCalled = true;
return place;
};
let place = {
id: '123',
osmId: '456',
osmType: 'node',
lat: 52.52,
lon: 13.405,
osmTags: { name: 'Foo' },
title: 'Foo',
};
let result = await service.refreshPlace(place);
assert.ok(updatePlaceCalled, 'updatePlace should be called');
assert.strictEqual(result.lat, 52.5201, 'Latitude updated');
});
test('refreshPlace ignores tiny coordinate drift', async function (assert) {
let service = this.owner.lookup('service:storage');
class OsmStub extends Service {
async fetchOsmObject(id, type) {
return {
osmId: id,
osmType: type,
lat: 52.5200005, // Tiny change (< 0.00001)
lon: 13.405,
osmTags: { name: 'Foo' },
};
}
}
this.owner.register('service:osm', OsmStub);
let updatePlaceCalled = false;
service.updatePlace = async () => {
updatePlaceCalled = true;
};
let place = {
id: '123',
osmId: '456',
osmType: 'node',
lat: 52.52,
lon: 13.405,
osmTags: { name: 'Foo' },
title: 'Foo',
};
await service.refreshPlace(place);
assert.notOk(updatePlaceCalled, 'updatePlace should NOT be called');
});
test('refreshPlace detects tag changes', async function (assert) {
let service = this.owner.lookup('service:storage');
class OsmStub extends Service {
async fetchOsmObject(id, type) {
return {
osmId: id,
osmType: type,
lat: 52.52,
lon: 13.405,
osmTags: { name: 'Bar' }, // Changed name
};
}
}
this.owner.register('service:osm', OsmStub);
let updatePlaceCalled = false;
service.updatePlace = async (place) => {
updatePlaceCalled = true;
return place;
};
let place = {
id: '123',
osmId: '456',
osmType: 'node',
lat: 52.52,
lon: 13.405,
osmTags: { name: 'Foo' },
title: 'Foo',
};
let result = await service.refreshPlace(place);
assert.ok(updatePlaceCalled, 'updatePlace should be called');
assert.strictEqual(result.osmTags.name, 'Bar', 'Tags updated');
});
test('refreshPlace updates title if it was default', async function (assert) {
let service = this.owner.lookup('service:storage');
class OsmStub extends Service {
async fetchOsmObject(id, type) {
return {
osmId: id,
osmType: type,
lat: 52.52,
lon: 13.405,
osmTags: { name: 'New Name' },
};
}
}
this.owner.register('service:osm', OsmStub);
service.updatePlace = async (place) => place;
let place = {
id: '123',
osmId: '456',
osmType: 'node',
lat: 52.52,
lon: 13.405,
osmTags: { name: 'Old Name' },
title: 'Old Name', // Matches default
};
let result = await service.refreshPlace(place);
assert.strictEqual(result.title, 'New Name', 'Title should update');
});
test('refreshPlace preserves custom title', async function (assert) {
let service = this.owner.lookup('service:storage');
class OsmStub extends Service {
async fetchOsmObject(id, type) {
return {
osmId: id,
osmType: type,
lat: 52.52,
lon: 13.405,
osmTags: { name: 'New Name' },
};
}
}
this.owner.register('service:osm', OsmStub);
service.updatePlace = async (place) => place;
let place = {
id: '123',
osmId: '456',
osmType: 'node',
lat: 52.52,
lon: 13.405,
osmTags: { name: 'Old Name' },
title: 'My Custom Place', // User renamed it
};
let result = await service.refreshPlace(place);
assert.strictEqual(
result.title,
'My Custom Place',
'Title should NOT update'
);
assert.strictEqual(
result.osmTags.name,
'New Name',
'Tags should still update'
);
});
});