diff --git a/assets/src/legacy/switcher-layers-actions.js b/assets/src/legacy/switcher-layers-actions.js index 74495b599a..49149f8f35 100644 --- a/assets/src/legacy/switcher-layers-actions.js +++ b/assets/src/legacy/switcher-layers-actions.js @@ -323,9 +323,12 @@ var lizLayerActionButtons = function() { lizMap.mainLizmap.state.baseLayers.selectedBaseLayerName = "project-background-color"; } else { for (const baseLayer of lizMap.mainLizmap.state.baseLayers.getBaseLayers()) { + if (!baseLayer.layerConfig) { + continue; + } if (themeSelected?.layers?.[baseLayer.layerConfig.id]) { lizMap.mainLizmap.state.baseLayers.selectedBaseLayerName = baseLayer.name; - continue; + break; } } } @@ -350,9 +353,14 @@ var lizLayerActionButtons = function() { ); // Activate first map theme on load - if ('activateFirstMapTheme' in lizMap.config.options && lizMap.config.options.activateFirstMapTheme == 'True') { + if (lizMap.mainLizmap.initialConfig.options.activateFirstMapTheme) { $('#theme-selector li.theme:nth-child(1)').click(); } + const urlParameters = (new URL(document.location)).searchParams; + if (urlParameters.has('mapTheme')) { + const urlMapTheme = urlParameters.get('mapTheme'); + $('#theme-selector li.theme').filter((i, e) => e.textContent == urlMapTheme).click(); + } } featureTypes = lizMap.getVectorLayerFeatureTypes(); diff --git a/assets/src/modules/Config.js b/assets/src/modules/Config.js index 27a949fdee..c0b95f51cb 100644 --- a/assets/src/modules/Config.js +++ b/assets/src/modules/Config.js @@ -18,8 +18,9 @@ import { TooltipLayersConfig } from './config/Tooltip.js'; import { EditionLayersConfig } from './config/Edition.js'; import { TimeManagerLayersConfig } from './config/TimeManager.js'; import { FormFilterConfig } from './config/FormFilter.js'; +import { ThemesConfig } from './config/Theme.js'; import { DatavizOptionsConfig, DatavizLayersConfig } from './config/Dataviz.js'; -import { buildLayerTreeConfig } from './config/LayerTree.js'; +import { buildLayerTreeConfig, LayerTreeGroupConfig } from './config/LayerTree.js'; import { buildLayersOrder } from './config/LayersOrder.js'; /** @@ -59,15 +60,25 @@ export class Config { this._hasMetadata = true; this._metadata = null; this._hasLocateByLayer = true; + this._locateByLayer = null; this._hasAttributeLayers = true; + this._attributeLayers = null; this._hasTimemanagerLayers = true; + this._timemanagerLayers = null; this._hasRelations = true; this._hasPrintTemplates = true; this._hasTooltipLayers = true; + this._tooltipLayers = null; this._hasEditionLayers = true; + this._editionLayers = null; this._hasFormFilterLayers = true; + this._formFilterLayers = null; this._hasLoginFilteredLayers = true; + this._hasThemes = true; + this._themes = null; this._hasDatavizConfig = true; + this._datavizLayers = null; + this._datavizOptions = null; const theConfig = deepFreeze(cfg); @@ -107,7 +118,8 @@ export class Config { 'tooltipLayers', 'editionLayers', 'formFilterLayers', - 'loginFilteredLayers' + 'loginFilteredLayers', + 'themes' ]; for (const prop of optionalConfigProperties) { if (!theConfig.hasOwnProperty(prop) @@ -230,13 +242,13 @@ export class Config { /** * Config locateByLayer - * @type {LocateByLayerConfig} + * @type {LocateByLayerConfig|null} */ get locateByLayer() { - if (this._locateByLayer != null) { - return this._locateByLayer; - } if (this._hasLocateByLayer) { + if (this._locateByLayer != null) { + return this._locateByLayer; + } this._locateByLayer = new LocateByLayerConfig(this._theConfig.locateByLayer); } return this._locateByLayer; @@ -252,13 +264,13 @@ export class Config { /** * Config attribueLayers - * @type {AttributeLayersConfig} + * @type {AttributeLayersConfig|null} */ get attributeLayers() { - if (this._attributeLayers != null) { - return this._attributeLayers; - } if (this._hasAttributeLayers) { + if (this._attributeLayers != null) { + return this._attributeLayers; + } this._attributeLayers = new AttributeLayersConfig(this._theConfig.attributeLayers); } return this._attributeLayers; @@ -274,13 +286,13 @@ export class Config { /** * Config timemanagerLayers - * @type {AttributeLayersConfig} + * @type {AttributeLayersConfig|null} */ get timemanagerLayers() { - if (this._timemanagerLayers != null) { - return this._timemanagerLayers; - } if (this._hasTimemanagerLayers) { + if (this._timemanagerLayers != null) { + return this._timemanagerLayers; + } this._timemanagerLayers = new TimeManagerLayersConfig(this._theConfig.timemanagerLayers); } return this._timemanagerLayers; @@ -312,13 +324,13 @@ export class Config { /** * Config tooltipLayers - * @type {TooltipLayersConfig} + * @type {TooltipLayersConfig|null} */ get tooltipLayers() { - if (this._tooltipLayers != null) { - return this._tooltipLayers; - } if (this._hasTooltipLayers) { + if (this._tooltipLayers != null) { + return this._tooltipLayers; + } this._tooltipLayers = new TooltipLayersConfig(this._theConfig.tooltipLayers); } return this._tooltipLayers; @@ -334,13 +346,13 @@ export class Config { /** * Config editionLayers - * @type {EditionLayersConfig} + * @type {EditionLayersConfig|null} */ get editionLayers() { - if (this._editionLayers != null) { - return this._editionLayers; - } if (this._hasEditionLayers) { + if (this._editionLayers != null) { + return this._editionLayers; + } this._editionLayers = new EditionLayersConfig(this._theConfig.editionLayers); } return this._editionLayers; @@ -356,13 +368,13 @@ export class Config { /** * Config formFilterLayers - * @type {FormFilterConfig} + * @type {FormFilterConfig|null} */ get formFilterLayers() { - if (this._formFilterLayers != null) { - return this._formFilterLayers; - } if (this.hasFormFilterLayers) { + if (this._formFilterLayers != null) { + return this._formFilterLayers; + } this._formFilterLayers = new FormFilterConfig(this._theConfig.formFilterLayers); } return this._formFilterLayers; @@ -376,6 +388,28 @@ export class Config { return this._hasLoginFilteredLayers; } + /** + * Themes config is defined + * @type {boolean} + */ + get hasThemes() { + return this._hasThemes; + } + + /** + * Config themes + * @type {ThemesConfig|null} + */ + get themes() { + if (this.hasThemes) { + if (this._themes != null) { + return this._themes; + } + this._themes = new ThemesConfig(this._theConfig.themes); + } + return this._themes; + } + /** * Dataviz locale * @type {string} @@ -394,13 +428,13 @@ export class Config { /** * Config datavizLayers - * @type {DatavizLayersConfig} + * @type {DatavizLayersConfig|null} */ get datavizLayers() { - if (this._datavizLayers != null) { - return this._datavizLayers; - } if (this._hasDatavizConfig) { + if (this._datavizLayers != null) { + return this._datavizLayers; + } this._datavizLayers = new DatavizLayersConfig(this._theConfig.datavizLayers.layers); } return this._datavizLayers; @@ -408,13 +442,13 @@ export class Config { /** * Config datavizOptions - * @type {DatavizOptionsConfig} + * @type {DatavizOptionsConfig|null} */ get datavizOptions() { - if (this._datavizOptions != null) { - return this._datavizOptions; - } if (this._hasDatavizConfig) { + if (this._datavizOptions != null) { + return this._datavizOptions; + } this._datavizOptions = new DatavizOptionsConfig(this._theConfig.datavizLayers.dataviz); } return this._datavizOptions; diff --git a/assets/src/modules/config/Options.js b/assets/src/modules/config/Options.js index 941b25e3b4..6f942ff49f 100644 --- a/assets/src/modules/config/Options.js +++ b/assets/src/modules/config/Options.js @@ -32,6 +32,7 @@ const optionalProperties = { 'use_native_zoom_levels': {type: 'boolean', nullable: true, default: null}, 'hide_numeric_scale_value': {type: 'boolean', default: false}, 'hideGroupCheckbox': { type: 'boolean', default: false }, + 'activateFirstMapTheme': { type: 'boolean', default: false }, 'wms_single_request_for_all_layers' : { type:'boolean', default: false } }; @@ -63,6 +64,7 @@ export class OptionsConfig extends BaseObjectConfig { * @param {boolean} [cfg.use_native_zoom_levels] - does the map use native zoom levels ? * @param {boolean} [cfg.hide_numeric_scale_value] - does the scale line hide numeric scale value ? * @param {boolean} [cfg.hideGroupCheckbox] - are groups checkbox hidden ? + * @param {boolean} [cfg.activateFirstMapTheme] - is first map theme activated ? * @param {boolean} [cfg.wms_single_request_for_all_layers] - are layers loaded as single WMS image ? */ constructor(cfg) { @@ -237,6 +239,14 @@ export class OptionsConfig extends BaseObjectConfig { return this._hideGroupCheckbox; } + /** + * Activate first map theme + * @type {boolean} + */ + get activateFirstMapTheme() { + return this._activateFirstMapTheme; + } + /** * The layers are loaded as a single WMS image * @type {boolean} diff --git a/assets/src/modules/config/Theme.js b/assets/src/modules/config/Theme.js index 090fe1d89a..eb316a7164 100644 --- a/assets/src/modules/config/Theme.js +++ b/assets/src/modules/config/Theme.js @@ -61,10 +61,12 @@ export class LayerThemeConfig extends BaseObjectConfig { const themeRequiredProperties = { 'layers': {type: 'object'}, - 'expandedGroupNode': {type: 'array'}, } const themeOptionalProperties = { + 'checkedGroupNode': {type: 'array', default: []}, + 'expandedGroupNode': {type: 'array', default: []}, + 'expandedLegendNode': {type: 'array', default: []}, } /** @@ -117,6 +119,14 @@ export class ThemeConfig extends BaseObjectConfig { return [...this._layerConfigs]; } + /** + * The copy of the checked group nodes list + * @type {string[]} + */ + get checkedGroupNodes() { + return [...this._checkedGroupNode]; + } + /** * The copy of the expanded group nodes list * @type {string[]} @@ -125,6 +135,14 @@ export class ThemeConfig extends BaseObjectConfig { return [...this._expandedGroupNode]; } + /** + * The copy of the expanded legend nodes list + * @type {string[]} + */ + get expandedLegendNodes() { + return [...this._expandedLegendNode]; + } + /** * Iterate through layer ids of the theme * @generator @@ -147,6 +165,17 @@ export class ThemeConfig extends BaseObjectConfig { } } + /** + * Iterate through the checked group nodes list + * @generator + * @yields {string} The next checked group node + */ + *getCheckedGroupNodes() { + for (const node of this._checkedGroupNode) { + yield node; + } + } + /** * Iterate through the expanded group nodes list * @generator @@ -158,6 +187,17 @@ export class ThemeConfig extends BaseObjectConfig { } } + /** + * Iterate through the expanded legend nodes list + * @generator + * @yields {string} The next expanded legend node + */ + *getExpandedLegendNodes() { + for (const node of this._expandedLegendNode) { + yield node; + } + } + /** * Get a layer config of the theme by layer id * @param {string} layerId the layer id diff --git a/lizmap/modules/view/controllers/map.classic.php b/lizmap/modules/view/controllers/map.classic.php index ea8e5e7ab2..8230377d83 100644 --- a/lizmap/modules/view/controllers/map.classic.php +++ b/lizmap/modules/view/controllers/map.classic.php @@ -37,6 +37,7 @@ public function index() 'filter', 'layerStyles', 'layerOpacities', + 'mapTheme', ); // Get redirection parameters $redirectKeyParams = jEvent::notify('getRedirectKeyParams', array('repository' => $repository, 'project' => $project))->getResponse(); diff --git a/tests/end2end/playwright/theme.spec.js b/tests/end2end/playwright/theme.spec.js index 37d1a1f320..5a88ff1635 100644 --- a/tests/end2end/playwright/theme.spec.js +++ b/tests/end2end/playwright/theme.spec.js @@ -1,10 +1,11 @@ // @ts-check import { test, expect } from '@playwright/test'; +const { gotoMap } = require('./globals') test.describe('Theme', () => { test.beforeEach(async ({ page }) => { const url = '/index.php/view/map/?repository=testsrepository&project=theme'; - await page.goto(url, { waitUntil: 'networkidle' }); + await gotoMap(url, page) }); test('must display theme1 at startup', async ({ page }) => { @@ -53,17 +54,14 @@ test.describe('Theme', () => { // The url has been updated const url = new URL(page.url()); -// TODO be fixed QGIS ≥ 3.34, works with QGIS < 3.34 -// await expect(url.hash).not.toHaveLength(0); + await expect(url.hash).not.toHaveLength(0); // The decoded hash is // #3.730872,43.540386,4.017985,43.679557 // |Les%20quartiers|style2|1 // |style2 // |1 -// TODO be fixed QGIS ≥ 3.34, works with QGIS < 3.34 -// await expect(url.hash).toMatch(/#3.7308\d+,43.5403\d+,4.0179\d+,43.6795\d+\|/) -// TODO be fixed QGIS ≥ 3.34, works with QGIS < 3.34 -// await expect(url.hash).toContain('|Les%20quartiers|style2|1') + await expect(url.hash).toMatch(/#3.7308\d+,43.5403\d+,4.0179\d+,43.6795\d+\|/) + await expect(url.hash).toContain('|Les%20quartiers|style2|1') }); test('must display theme3 when selected', async ({ page }) => { @@ -98,7 +96,23 @@ test.describe('Theme', () => { await page.locator('#theme-selector > ul > li.theme').nth(3).click(); // Baselayer -// TODO be fixed QGIS ≥ 3.34, works with QGIS < 3.34 -// await expect(page.locator('lizmap-base-layers select')).toHaveValue('OpenStreetMap'); + await expect(page.locator('lizmap-base-layers select')).toHaveValue('OpenStreetMap'); + }); + + test('mapTheme parameter', async ({ page }) => { + await expect(page.locator('#theme-selector > ul > li.theme').first()).toHaveClass(/selected/); + + let url = '/index.php/view/map/?repository=testsrepository&project=theme&mapTheme=theme2'; + await gotoMap(url, page) + await expect(page.locator('#theme-selector > ul > li.theme').nth(1)).toHaveClass(/selected/); + + url = '/index.php/view/map/?repository=testsrepository&project=theme&mapTheme=theme3'; + await gotoMap(url, page) + await expect(page.locator('#theme-selector > ul > li.theme').nth(2)).toHaveClass(/selected/); + + url = '/index.php/view/map/?repository=testsrepository&project=theme&mapTheme=theme4'; + await gotoMap(url, page) + await expect(page.locator('#theme-selector > ul > li.theme').nth(3)).toHaveClass(/selected/); }); + }); diff --git a/tests/js-units/node/config.test.js b/tests/js-units/node/config.test.js index a19d5f80a2..0191580d29 100644 --- a/tests/js-units/node/config.test.js +++ b/tests/js-units/node/config.test.js @@ -12,6 +12,7 @@ import { MetadataConfig } from '../../../assets/src/modules/config/Metadata.js'; import { LocateByLayerConfig } from '../../../assets/src/modules/config/Locate.js'; import { AttributeLayersConfig } from '../../../assets/src/modules/config/AttributeTable.js'; import { TooltipLayersConfig } from '../../../assets/src/modules/config/Tooltip.js'; +import { ThemesConfig } from '../../../assets/src/modules/config/Theme.js'; import { DatavizLayersConfig, DatavizOptionsConfig } from '../../../assets/src/modules/config/Dataviz.js'; @@ -114,16 +115,18 @@ describe('Config', function () { expect(initialConfig.hasAttributeLayers).to.be.true expect(initialConfig.attributeLayers).to.be.instanceOf(AttributeLayersConfig) expect(initialConfig.hasTimemanagerLayers).to.be.false - expect(initialConfig.timemanagerLayers).to.be.undefined + expect(initialConfig.timemanagerLayers).to.be.null expect(initialConfig.hasRelations).to.be.true expect(initialConfig.hasPrintTemplates).to.be.true expect(initialConfig.hasTooltipLayers).to.be.true expect(initialConfig.tooltipLayers).to.be.instanceOf(TooltipLayersConfig) expect(initialConfig.hasEditionLayers).to.be.false - expect(initialConfig.editionLayers).to.be.undefined + expect(initialConfig.editionLayers).to.be.null expect(initialConfig.hasFormFilterLayers).to.be.false - expect(initialConfig.formFilterLayers).to.be.undefined + expect(initialConfig.formFilterLayers).to.be.null expect(initialConfig.hasLoginFilteredLayers).to.be.false + expect(initialConfig.hasThemes).to.be.true + expect(initialConfig.themes).to.be.instanceOf(ThemesConfig) expect(initialConfig.datavizLocale).to.be.eq('fr_FR') expect(initialConfig.hasDatavizConfig).to.be.true expect(initialConfig.datavizLayers).to.be.instanceOf(DatavizLayersConfig) diff --git a/tests/js-units/node/config/options.test.js b/tests/js-units/node/config/options.test.js index 604ab5460f..8db1de8feb 100644 --- a/tests/js-units/node/config/options.test.js +++ b/tests/js-units/node/config/options.test.js @@ -49,6 +49,7 @@ describe('OptionsConfig', function () { //"use_native_zoom_levels": false, //"hide_numeric_scale_value": false, //"hideGroupCheckbox": false, + //"activateFirstMapTheme": false, }) expect(opt.hideProject).to.be.eq(true) @@ -72,6 +73,7 @@ describe('OptionsConfig', function () { expect(opt.fixed_scale_overview_map).to.be.eq(true) expect(opt.hide_numeric_scale_value).to.be.eq(false) expect(opt.hideGroupCheckbox).to.be.eq(false) + expect(opt.activateFirstMapTheme).to.be.eq(false) // Default value for multiple mapScales without use_native_zoom_levels defined expect(opt.use_native_zoom_levels).to.be.eq(false) // Default value for singleWMS option is false (option wms_single_request_for_all_layers not defined) diff --git a/tests/js-units/node/config/theme.test.js b/tests/js-units/node/config/theme.test.js index d7b01ec2da..de8e1b7a6f 100644 --- a/tests/js-units/node/config/theme.test.js +++ b/tests/js-units/node/config/theme.test.js @@ -5,7 +5,7 @@ import { LayerThemeConfig, ThemeConfig, ThemesConfig } from '../../../../assets/ describe('LayerThemeConfig', function () { it('Valid', function () { - const layer1 = new LayerThemeConfig("SousQuartiers20160121124316563", {"style":"default", "expanded":"1"}) + const layer1 = new LayerThemeConfig("SousQuartiers20160121124316563", { "style": "default", "expanded": "1" }) expect(layer1.layerId).to.be.eq('SousQuartiers20160121124316563') expect(layer1.style).to.be.eq('default') expect(layer1.expanded).to.be.eq(true) @@ -31,7 +31,7 @@ describe('LayerThemeConfig', function () { it('ConversionError', function () { try { - new LayerThemeConfig("SousQuartiers20160121124316563", {"style":"default", "expanded":"trust"}) + new LayerThemeConfig("SousQuartiers20160121124316563", { "style": "default", "expanded": "trust" }) } catch (error) { expect(error.name).to.be.eq('ConversionError') expect(error.message).to.be.eq('`trust` is not an expected boolean: true, t, yes, y, 1, false, f, no, n, 0 or empty string ``!') @@ -43,13 +43,13 @@ describe('LayerThemeConfig', function () { describe('ThemeConfig', function () { it('Valid', function () { const theme = new ThemeConfig("Administrative", { - "layers":{ - "SousQuartiers20160121124316563":{"style":"default","expanded":"1"}, - "donnes_sociodemo_sous_quartiers20160121144525075":{"style":"default","expanded":"1"}, - "publicbuildings20150420100958543":{"style":"default","expanded":"1"}, - "VilleMTP_MTP_Quartiers_2011_432620130116112610876":{"style":"default","expanded":"0"} + "layers": { + "SousQuartiers20160121124316563": { "style": "default", "expanded": "1" }, + "donnes_sociodemo_sous_quartiers20160121144525075": { "style": "default", "expanded": "1" }, + "publicbuildings20150420100958543": { "style": "default", "expanded": "1" }, + "VilleMTP_MTP_Quartiers_2011_432620130116112610876": { "style": "default", "expanded": "0" } }, - "expandedGroupNode":["Edition","datalayers\/Tramway","datalayers\/Bus","datalayers\/Buildings","Overview","datalayers","Hidden"] + "expandedGroupNode": ["Edition", "datalayers\/Tramway", "datalayers\/Bus", "datalayers\/Buildings", "Overview", "datalayers", "Hidden"] }) expect(theme.name).to.be.eq('Administrative') @@ -94,38 +94,38 @@ describe('ThemeConfig', function () { describe('ThemesConfig', function () { it('Valid', function () { const themes = new ThemesConfig({ - "Administrative":{ - "layers":{ - "SousQuartiers20160121124316563":{"style":"default","expanded":"1"}, - "donnes_sociodemo_sous_quartiers20160121144525075":{"style":"default","expanded":"1"}, - "publicbuildings20150420100958543":{"style":"default","expanded":"1"}, - "VilleMTP_MTP_Quartiers_2011_432620130116112610876":{"style":"default","expanded":"0"} + "Administrative": { + "layers": { + "SousQuartiers20160121124316563": { "style": "default", "expanded": "1" }, + "donnes_sociodemo_sous_quartiers20160121144525075": { "style": "default", "expanded": "1" }, + "publicbuildings20150420100958543": { "style": "default", "expanded": "1" }, + "VilleMTP_MTP_Quartiers_2011_432620130116112610876": { "style": "default", "expanded": "0" } }, - "expandedGroupNode":["Edition","datalayers\/Tramway","datalayers\/Bus","datalayers\/Buildings","Overview","datalayers","Hidden"] + "expandedGroupNode": ["Edition", "datalayers\/Tramway", "datalayers\/Bus", "datalayers\/Buildings", "Overview", "datalayers", "Hidden"] }, - "Editable layers":{ - "layers":{ - "SousQuartiers20160121124316563":{"style":"default","expanded":"1"}, - "donnes_sociodemo_sous_quartiers20160121144525075":{"style":"default","expanded":"1"}, - "publicbuildings20150420100958543":{"style":"default","expanded":"1"}, - "edition_polygon20130409114333776":{"style":"default","expanded":"0"}, - "edition_line20130409161630329":{"style":"default","expanded":"0"}, - "edition_point20130118171631518":{"style":"default","expanded":"0"} + "Editable layers": { + "layers": { + "SousQuartiers20160121124316563": { "style": "default", "expanded": "1" }, + "donnes_sociodemo_sous_quartiers20160121144525075": { "style": "default", "expanded": "1" }, + "publicbuildings20150420100958543": { "style": "default", "expanded": "1" }, + "edition_polygon20130409114333776": { "style": "default", "expanded": "0" }, + "edition_line20130409161630329": { "style": "default", "expanded": "0" }, + "edition_point20130118171631518": { "style": "default", "expanded": "0" } }, - "expandedGroupNode":["Edition","datalayers\/Tramway","datalayers\/Bus","datalayers\/Buildings","Overview","datalayers","Hidden"] + "expandedGroupNode": ["Edition", "datalayers\/Tramway", "datalayers\/Bus", "datalayers\/Buildings", "Overview", "datalayers", "Hidden"] }, - "Transport":{ - "layers":{ - "tramway20150328114206278":{"style":"black","expanded":"1"}, - "donnes_sociodemo_sous_quartiers20160121144525075":{"style":"default","expanded":"1"}, - "tramway_ref20150612171109044":{"style":"default","expanded":"1"}, - "jointure_tram_stop20150328114216806":{"style":"default","expanded":"1"}, - "tramstop20150328114203878":{"style":"default","expanded":"1"}, - "tram_stop_work20150416102656130":{"style":"default","expanded":"1"}, - "bus_stops20121106170806413":{"style":"default","expanded":"0"}, - "bus20121102133611751":{"style":"default","expanded":"0"} + "Transport": { + "layers": { + "tramway20150328114206278": { "style": "black", "expanded": "1" }, + "donnes_sociodemo_sous_quartiers20160121144525075": { "style": "default", "expanded": "1" }, + "tramway_ref20150612171109044": { "style": "default", "expanded": "1" }, + "jointure_tram_stop20150328114216806": { "style": "default", "expanded": "1" }, + "tramstop20150328114203878": { "style": "default", "expanded": "1" }, + "tram_stop_work20150416102656130": { "style": "default", "expanded": "1" }, + "bus_stops20121106170806413": { "style": "default", "expanded": "0" }, + "bus20121102133611751": { "style": "default", "expanded": "0" } }, - "expandedGroupNode":["Edition","datalayers\/Tramway","datalayers\/Bus","datalayers\/Buildings","Overview","datalayers","Hidden"] + "expandedGroupNode": ["Edition", "datalayers\/Tramway", "datalayers\/Bus", "datalayers\/Buildings", "Overview", "datalayers", "Hidden"] } }) @@ -151,14 +151,127 @@ describe('ThemesConfig', function () { expect(theme1.getLayerConfigByLayerId('SousQuartiers20160121124316563')).to.be.eq(layer1) expect(theme1.getLayerConfigs().next().value).to.be.eq(layer1) + expect(theme1.checkedGroupNodes.length).to.be.eq(0) + expect(theme1.expandedGroupNodes.length).to.be.eq(7) expect(theme1.expandedGroupNodes[0]).to.be.eq('Edition') expect(theme1.getExpandedGroupNodes().next().value).to.be.eq('Edition') + expect(theme1.expandedLegendNodes.length).to.be.eq(0) + expect(themes.getThemeConfigByThemeName('Administrative')).to.be.eq(theme1) expect(themes.getThemeConfigs().next().value).to.be.eq(theme1) }) + it('Complexe', function () { + const themes = new ThemesConfig({ + "theme1": { + "layers": { + "quartiers_ef5b13e3_36db_4e0d_98b3_990de580367d": { + "style": "style1", + "expanded": "0" + } + }, + "checkedGroupNode": [ + "group1" + ] + }, + "theme2": { + "layers": { + "quartiers_ef5b13e3_36db_4e0d_98b3_990de580367d": { + "style": "style2", + "expanded": "1" + } + }, + "expandedGroupNode": [ + "group1" + ] + }, + "theme3": { + "layers": { + "tramway_lines_d90bd315_72dd_4dbd_b785_f835a3f61dea": { + "style": "default", + "expanded": "1" + } + }, + "checkedGroupNode": [ + "group with subgroups/sub-group-1", + "baselayers/project-background-color", + "group with subgroups/sub-group-1/sub-sub-group--1", + "baselayers", + "group with subgroups" + ], + "expandedGroupNode": [ + "group with subgroups/sub-group-1", + "group with subgroups/sub-group-1/sub-sub-group--1", + "group with subgroups" + ] + }, + "theme4": { + "layers": { + "sousquartiers_7c49d0fc_0ee0_4308_a66d_45c144e59872": { + "style": "rule-based", + "expanded": "1" + }, + "OpenStreetMap_e6aed7cf_2f70_4236_ace0_b70d2c0e7c63": { + "style": "défaut", + "expanded": "1" + } + }, + "checkedGroupNode": [ + "group1", + "baselayers" + ], + "expandedGroupNode": [ + "group with subgroups/sub-group-1", + "group1", + "group with subgroups/sub-group-1/sub-sub-group--1", + "baselayers" + ], + "expandedLegendNode": [ + "{799a3cf2-2e09-4f3d-93f5-dc2a4920971d}" + ] + } + }) + + expect(themes.themeNames.length).to.be.eq(4) + + expect(themes.themeConfigs.length).to.be.eq(4) + + const themeConfigs = themes.themeConfigs; + const theme1 = themeConfigs[0] + expect(theme1.name).to.be.eq('theme1') + expect(theme1.layerIds.length).to.be.eq(1) + expect(theme1.layerConfigs.length).to.be.eq(1) + expect(theme1.checkedGroupNodes.length).to.be.eq(1) + expect(theme1.expandedGroupNodes.length).to.be.eq(0) + expect(theme1.expandedLegendNodes.length).to.be.eq(0) + + const theme2 = themeConfigs[1] + expect(theme2.name).to.be.eq('theme2') + expect(theme2.layerIds.length).to.be.eq(1) + expect(theme2.layerConfigs.length).to.be.eq(1) + expect(theme2.checkedGroupNodes.length).to.be.eq(0) + expect(theme2.expandedGroupNodes.length).to.be.eq(1) + expect(theme2.expandedLegendNodes.length).to.be.eq(0) + + const theme3 = themeConfigs[2] + expect(theme3.name).to.be.eq('theme3') + expect(theme3.layerIds.length).to.be.eq(1) + expect(theme3.layerConfigs.length).to.be.eq(1) + expect(theme3.checkedGroupNodes.length).to.be.eq(5) + expect(theme3.expandedGroupNodes.length).to.be.eq(3) + expect(theme3.expandedLegendNodes.length).to.be.eq(0) + + const theme4 = themeConfigs[3] + expect(theme4.name).to.be.eq('theme4') + expect(theme4.layerIds.length).to.be.eq(2) + expect(theme4.layerConfigs.length).to.be.eq(2) + expect(theme4.checkedGroupNodes.length).to.be.eq(2) + expect(theme4.expandedGroupNodes.length).to.be.eq(4) + expect(theme4.expandedLegendNodes.length).to.be.eq(1) + }) + it('ValidationError', function () { try { new ThemesConfig()