Skip to content

Commit

Permalink
prevent empty baselayers group error, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mind84 committed Jun 14, 2024
1 parent 07ba0db commit e592f4d
Show file tree
Hide file tree
Showing 6 changed files with 2,242 additions and 257 deletions.
6 changes: 5 additions & 1 deletion assets/src/modules/config/LayerTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ function buildLayerTreeGroupConfigItems(wmsCapaLayerGroup, layersCfg, level) {
const groupItems = buildLayerTreeGroupConfigItems(wmsCapaLayer, layersCfg, level+1);
items.push(new LayerTreeGroupConfig(cfg.name, level+1, groupItems, wmsCapaLayer, cfg));
} else {
items.push(new LayerTreeLayerConfig(cfg.name, level+1, wmsCapaLayer, cfg));
// avoid to add the baseLayers group to the map if doesn't contains any layer.
if(wmsName.toLowerCase() != 'baselayers') {
items.push(new LayerTreeLayerConfig(cfg.name, level+1, wmsCapaLayer, cfg));
}

}
}
return items;
Expand Down
39 changes: 39 additions & 0 deletions tests/end2end/playwright/google-basemap.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

const { test, expect } = require('@playwright/test');
const { gotoMap } = require('./globals');

test.describe('Google Maps Baselayers', () => {
test('Load map with no API Key', async ({ page }) => {
const url = '/index.php/view/map?repository=testsrepository&project=google_basemap';
await gotoMap(url, page);

// baselayers group should be hidden since it is empty due to the default STRICT_GOOGLE_TOS_CHECK env variable value = TRUE
await expect(page.locator('#switcher-baselayer.hide')).toHaveCount(1);

});

test('Load map with dummy API Key', async ({ page }) => {
// listen to the requests to intercept failing ones
let initGoogleRequestsCount = 0;
page.on('response', response => {
if(response.url().includes('createSession?key=dummy') && response.status() != 200) {
initGoogleRequestsCount++;
}
});

const url = '/index.php/view/map?repository=testsrepository&project=google_apikey_basemap';
await gotoMap(url, page);

// there are three Google base layers in the project, so the expected number of failing requests is three
expect(initGoogleRequestsCount).toBe(3);
// baselayers group should be visible...
await expect(page.locator('#switcher-baselayer')).toBeVisible();

//.. and should contains the three Google base layers (not loaded)
let options = page.locator('#switcher-baselayer').getByRole('combobox').locator('option');
await expect(options).toHaveCount(3);
expect(await options.nth(0).getAttribute('value')).toBe('Google Streets');
expect(await options.nth(1).getAttribute('value')).toBe('Google Satellite');
expect(await options.nth(2).getAttribute('value')).toBe('Google Hybrid');
});
});
Loading

0 comments on commit e592f4d

Please sign in to comment.