Skip to content

Commit

Permalink
Merge branch 'main' into template-type-usage-test
Browse files Browse the repository at this point in the history
  • Loading branch information
dbauszus-glx authored Sep 26, 2024
2 parents f957a92 + 7de8ccf commit c40f299
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 8 deletions.
8 changes: 7 additions & 1 deletion lib/location/get.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The getInfoj() method is awaited before the location is decorated.
@param {object} list Object in which locations are stored as properties.
@property {layer} location.layer The layer to which the location belongs.
@property {string} location.id The ID must be unique for the layer dataset.
@property {Array} [layer.infoj] The infoj array from the layer, this is required to decorate the location.
@property {mapview} layer.mapview
@property {object} mapview.interaction The current [highlight] interaction.
@property {boolean} mapview.hooks Hooks are enabled for the location.layer.mapview.
Expand All @@ -45,8 +46,13 @@ export async function get(location, list = location.layer.mapview.locations) {
return;
}

// Location has no layer or id, return.
if (!location.layer || !location.id) return;

// Location has no infoj to decorate, return.
if (!location.layer.infoj) return;

// Build location hook from layer key and location id.
location.hook ??= `${location.layer.key}!${location.id}`;

if (list[location.hook]) {
Expand Down Expand Up @@ -76,7 +82,7 @@ export async function get(location, list = location.layer.mapview.locations) {

// Hooks are enabled for the mapview
if (mapview.hooks) {

mapp.hooks.push('locations', location.hook)
}

Expand Down
1 change: 1 addition & 0 deletions lib/ui/layers/filters.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ async function generateMinMax(layer, filter) {
layer: layer.key,
table: layer.tableCurrent(),
field: filter.field,
filter: layer.filter?.current
})}`);

// Assign min, max from response if not a number.
Expand Down
40 changes: 38 additions & 2 deletions tests/lib/location/get.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
export async function getTest(mapview) {
await codi.describe('Location: getTest', async () => {

const location_layer = mapview.layers['location_get_test'];

const location_layer_no_infoj = mapview.layers['location_get_test_no_infoj'];

/**
* This tests the functionality to mock a location by passing in a template that returns values from the query
* @function it
*/
await codi.it('We should be able to mock a location get.', async () => {
const locationLayer = mapview.layers['location_get_test'];

//Get the location with the id returned from the query above
const location = await mapp.location.get({
layer: locationLayer,
layer: location_layer,
getTemplate: 'get_location_mock',
id: 6,
});
Expand All @@ -33,5 +36,38 @@ export async function getTest(mapview) {

codi.assertTrue(!location.removeCallbacks, 'removeCallbacks should have removed themselves.');
});

/**
* This tests that no location is returned if no infoj is provided
* @function it
*/
await codi.it('Location get should return undefined if location.layer.info is undefined.', async () => {

//Get the location with the id returned from the query above
const location = await mapp.location.get({
layer: location_layer_no_infoj,
getTemplate: 'get_location_mock',
id: 6,
});

codi.assertEqual(location, undefined, 'The Location should be undefined');

});

/**
* This tests that no location is returned if no infoj is provided
* @function it
*/
await codi.it('The getInfoj method should return an infoj if none is provided on the layer present.', async () => {

//Get the location with the id returned from the query above
const infoj = await mapp.location.getInfoj({
layer: location_layer_no_infoj,
getTemplate: 'get_location_mock',
id: 6,
});

codi.assertTrue(infoj !== undefined, 'The Location should be undefined');
});
});
}
19 changes: 18 additions & 1 deletion tests/lib/ui/layers/filters.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function filtersTest(mapview) {
//Delete the min value from the filter
delete filter.min;

//Delte the lte value of the current filter otherwise it will not be changed in the next test
//Delete the lte value of the current filter otherwise it will not be changed in the next test
delete layer.filter.current[filter.field].lte;
});

Expand All @@ -67,5 +67,22 @@ export async function filtersTest(mapview) {
codi.assertEqual(minInput.value, '100', 'The min should return 100.');
codi.assertEqual(maxInput.value, '1000', 'The max should return 1000');
});

await codi.it('Numeric Filter: layer.current specified as `lte: 200` and `gte: 800`', async () => {

layer.filter.current[filter.field].lte = 800
layer.filter.current[filter.field].gte = 200

const numericFilter = await mapp.ui.layers.filters.numeric(layer, filter);
const minInput = numericFilter.querySelector('div > input[type=range]:nth-child(3)');
const maxInput = numericFilter.querySelector('div > input[type=range]:nth-child(4)');

codi.assertEqual(minInput.value, '200', 'The min should return 200.');
codi.assertEqual(maxInput.value, '800', 'The max should return 800');

//Delete the lte/gte value of the current filter otherwise it will not be changed in the next test
delete layer.filter.current[filter.field].lte;
delete layer.filter.current[filter.field].gte;
})
});
}
12 changes: 8 additions & 4 deletions tests/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
"type": "module",
"src": "file:/tests/assets/queries/foo.js"
},
"location_get": {
"type": "module",
"src": "file:/tests/assets/queries/foo.js"
},
"template_1": {
"src": "file:/tests/assets/infoj/template_infoj.json"
},
Expand Down Expand Up @@ -309,6 +305,14 @@
"src": "file:/tests/assets/layers/location_mock/infoj.json"
}
]
},
"location_get_test_no_infoj": {
"hidden": true,
"templates": [
{
"src": "file:/tests/assets/layers/location_mock/layer.json"
}
]
}
}
}
Expand Down

0 comments on commit c40f299

Please sign in to comment.