Skip to content

Commit

Permalink
Merge pull request GEOLYTIX#1770 from simon-leech/infoj_order-layer
Browse files Browse the repository at this point in the history
Infoj Order Can Be Specified on a Layer
  • Loading branch information
RobAndrewHurst authored Dec 9, 2024
2 parents b390f92 + efa0e3c commit 2e53367
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/ui/locations/infoj.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default function infoj(location, infoj_order) {
// Create object to hold view groups.
groups = {}


// The infoj_order may be assigned to the layer.
infoj_order ??= location?.layer?.infoj_order

// infoj argument is provided as an array of strings to filter the location infoj entries.
const infoj = Array.isArray(infoj_order) ?
infoj_order
Expand Down
72 changes: 70 additions & 2 deletions tests/lib/ui/locations/infoj.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ export function infojTest() {
/**
* ### It should create an infoj with a correct order
* 1. We define an infoj with a combination of different entries with keys, fields and queries
* 2. We assert against the order
* 2. We assert against the order when calling the infoj method
* 3. We assert against the order when calling the infoj method with a different order as defined in the layer
* @function it
*/
codi.it('It should create an infoj with certain order', () => {
codi.it('It should create an infoj with certain order as specified directly to the method', () => {

const location = {
infoj: [
Expand Down Expand Up @@ -74,5 +75,72 @@ export function infojTest() {
codi.assertEqual(results, expected, 'The infoj order needs to be as defined in the expected');

});

codi.it('It should create an infoj with certain order as defined on the layer', () => {

const location = {
infoj: [
{
field: 'field_1',
key: 'key_1',
label: 'test_1',
value: 'test 1 value'
},
{
field: 'field_2',
label: 'test_2',
value: 'value_2'
},
{
field: 'field_3',
label: 'test_3',
value: 'value_3'
},
{
key: 'key_4',
value: 'value_4'
},
{
query: 'query_5',
value: 'value_5',
location: {}
}
]
};

// Set the order on the layer
location.layer = {};
location.layer.infoj_order = [
'_field_1',
'field_2',
'field_3',
'key_4',
'query_5',
{
field: 'field6',
value: 'value_6'
}
];

// Get listview element from the infoj object
const infoj = mapp.ui.locations.infoj(location);

// Get textvalues from location listview elements.
const results = Array.from(infoj.children)
.map(el => el.firstChild.innerText.trim())

// Expected results
const expected = [
'value_2',
'value_3',
'value_4',
'value_5',
'value_6'
];

// Asserting we get the expected results and order
codi.assertEqual(results, expected, 'The infoj order needs to be as defined in the expected');

});
});
}

0 comments on commit 2e53367

Please sign in to comment.