Skip to content

Do not allow to push it.only() tests #579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
},
root: true,
ignorePatterns: ['node_modules', '.github', 'dist'],
plugins: ['simple-import-sort'],
plugins: ['simple-import-sort', 'mocha'],
extends: [
'eslint:recommended',
'plugin:vue/vue3-recommended',
Expand All @@ -28,6 +28,7 @@ module.exports = {
],
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'mocha/no-exclusive-tests': 'error', // Do not allow it.only() tests
},
globals: {
VITE_ENVIRONMENT: true,
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14
v18
50 changes: 50 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"eslint": "^8.55.0",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-markdownlint": "^0.5.0",
"eslint-plugin-mocha": "^10.2.0",
"eslint-plugin-prettier-vue": "^5.0.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-vue": "^9.19.2",
Expand Down
16 changes: 7 additions & 9 deletions src/api/layers/WMSCapabilitiesParser.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class WMSCapabilitiesParser {
throw new Error(`Failed to parse WMTS Capabilities: invalid content: ${error}`)
}

this.originUrl = new URL(originUrl)
this.originUrl = originUrl
}

/**
Expand Down Expand Up @@ -65,7 +65,7 @@ export default class WMSCapabilitiesParser {
getExternalLayerObject(layerId, projection, opacity = 1, visible = true, ignoreError = true) {
const { layer, parents } = this.findLayer(layerId)
if (!layer) {
const msg = `No WMS layer ${layerId} found in Capabilities ${this.originUrl.toString()}`
const msg = `No WMS layer ${layerId} found in Capabilities ${this.originUrl}`
log.error(msg)
if (ignoreError) {
return null
Expand Down Expand Up @@ -164,7 +164,7 @@ export default class WMSCapabilitiesParser {
}
if (!layerId) {
// Without layerID we cannot use the layer in our viewer
const msg = `No layerId found in WMS capabilities for layer in ${this.originUrl.toString()}`
const msg = `No layerId found in WMS capabilities for layer in ${this.originUrl}`
log.error(msg, layer)
if (ignoreError) {
return {}
Expand All @@ -175,9 +175,9 @@ export default class WMSCapabilitiesParser {
if (!this.version || !WMS_SUPPORTED_VERSIONS.includes(this.version)) {
let msg = ''
if (!this.version) {
msg = `No WMS version found in Capabilities of ${this.originUrl.toString()}`
msg = `No WMS version found in Capabilities of ${this.originUrl}`
} else {
msg = `WMS version ${this.version} of ${this.originUrl.toString()} not supported`
msg = `WMS version ${this.version} of ${this.originUrl} not supported`
}
log.error(msg, layer)
if (ignoreError) {
Expand All @@ -189,9 +189,7 @@ export default class WMSCapabilitiesParser {
return {
layerId: layerId,
title: layer.Title,
url:
this.Capability?.Request?.GetMap?.DCPType[0]?.HTTP?.Get?.OnlineResource ||
this.originUrl.toString(),
url: this.originUrl,
version: this.version,
abstract: layer.Abstract,
attributions: this._getLayerAttribution(layerId, layer, ignoreError),
Expand Down Expand Up @@ -248,7 +246,7 @@ export default class WMSCapabilitiesParser {
}

if (!layerExtent) {
const msg = `No layer extent found for ${layerId} in ${this.originUrl.toString()}`
const msg = `No layer extent found for ${layerId} in ${this.originUrl}`
log.error(msg, layer, parents)
if (!ignoreError) {
throw Error(msg)
Expand Down
17 changes: 6 additions & 11 deletions src/api/layers/WMTSCapabilitiesParser.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class WMTSCapabilitiesParser {
throw new Error(`Failed to parse WMTS Capabilities: invalid content`)
}
Object.assign(this, capabilities)
this.originUrl = new URL(originUrl)
this.originUrl = originUrl
}

/**
Expand All @@ -64,7 +64,7 @@ export default class WMTSCapabilitiesParser {
getExternalLayerObject(layerId, projection, opacity = 1, visible = true, ignoreError = true) {
const layer = this.findLayer(layerId)
if (!layer) {
const msg = `No WMTS layer ${layerId} found in Capabilities ${this.originUrl.toString()}`
const msg = `No WMTS layer ${layerId} found in Capabilities ${this.originUrl}`
log.error(msg)
if (!ignoreError) {
throw new Error(msg)
Expand Down Expand Up @@ -117,23 +117,18 @@ export default class WMTSCapabilitiesParser {
layerId = layer.Title
}
if (!layerId) {
const msg = `No layer identifier found in Capabilities ${this.originUrl.toString()}`
const msg = `No layer identifier found in Capabilities ${this.originUrl}`
log.error(msg, layer)
if (ignoreError) {
return {}
}
throw new Error(msg)
}
const title = layer.Title || layerId

const getCapUrl =
this.OperationsMetadata?.GetCapabilities?.DCP?.HTTP?.Get[0]?.href ||
this.originUrl.toString()

return {
layerId: layerId,
title: title,
url: getCapUrl,
title: layer.Title || layerId,
url: this.originUrl,
version: this.version,
abstract: layer.Abstract,
attributions: this._getLayerAttribution(layerId),
Expand Down Expand Up @@ -235,7 +230,7 @@ export default class WMTSCapabilitiesParser {
if (!title) {
const msg = `No attribution title for layer ${layerId}`
log.error(msg)
title = this.originUrl.hostname
title = new URL(this.originUrl).hostname
}
return [new LayerAttribution(title, url)]
}
Expand Down
11 changes: 5 additions & 6 deletions src/api/layers/__tests__/WMSCapabitliesParser.class.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,22 @@ describe('WMSCapabilitiesParser of wms-geoadmin-sample.xml', () => {
expect(capabilities.version).toBe('1.3.0')
expect(capabilities.Capability).toBeTypeOf('object')
expect(capabilities.Service).toBeTypeOf('object')
expect(capabilities.originUrl).toBeInstanceOf(URL)
expect(capabilities.originUrl.toString()).toBe('https://wms.geo.admin.ch/')
expect(capabilities.originUrl).toBe('https://wms.geo.admin.ch')
})
it('Parse layer attributes', () => {
// General layer
let layer = capabilities.getExternalLayerObject('ch.swisstopo-vd.official-survey', WGS84)
expect(layer.externalLayerId).toBe('ch.swisstopo-vd.official-survey')
expect(layer.name).toBe('OpenData-AV')
expect(layer.abstract).toBe('The official survey (AV).')
expect(layer.baseURL).toBe('https://wms.geo.admin.ch/?')
expect(layer.baseURL).toBe('https://wms.geo.admin.ch')

// Layer without .Name
layer = capabilities.getExternalLayerObject('Periodic-Tracking', WGS84)
expect(layer.externalLayerId).toBe('Periodic-Tracking')
expect(layer.name).toBe('Periodic-Tracking')
expect(layer.abstract).toBe('Layer without Name element should use the Title')
expect(layer.baseURL).toBe('https://wms.geo.admin.ch/?')
expect(layer.baseURL).toBe('https://wms.geo.admin.ch')
})
it('Parse layer attribution', () => {
// Attribution in root layer
Expand Down Expand Up @@ -109,7 +108,7 @@ describe('WMSCapabilitiesParser - layer attributes', () => {
`
let capabilities = new WMSCapabilitiesParser(content, 'https://wms.geo.admin.ch')
let layer = capabilities.getExternalLayerObject('ch.swisstopo-vd.official-survey', WGS84)
expect(layer.baseURL).toBe('https://wms.geo.admin.ch/')
expect(layer.baseURL).toBe('https://wms.geo.admin.ch')

// URL from Capability
content = `<?xml version='1.0' encoding="UTF-8" standalone="no"?>
Expand Down Expand Up @@ -140,7 +139,7 @@ describe('WMSCapabilitiesParser - layer attributes', () => {
`
capabilities = new WMSCapabilitiesParser(content, 'https://wms.geo.admin.ch')
layer = capabilities.getExternalLayerObject('ch.swisstopo-vd.official-survey', WGS84)
expect(layer.baseURL).toBe('https://wms.geo.admin.ch/map?')
expect(layer.baseURL).toBe('https://wms.geo.admin.ch')
})
})

Expand Down
7 changes: 3 additions & 4 deletions src/api/layers/__tests__/WMTSCapabitliesParser.class.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,22 @@ describe('WMTSCapabilitiesParser of wmts-ogc-sample.xml', () => {
expect(capabilities.OperationsMetadata).toBeTypeOf('object')
expect(capabilities.ServiceIdentification).toBeTypeOf('object')
expect(capabilities.ServiceProvider).toBeTypeOf('object')
expect(capabilities.originUrl).toBeInstanceOf(URL)
expect(capabilities.originUrl.toString()).toBe('https://example.com/')
expect(capabilities.originUrl).toBe('https://example.com')
})
it('Parse layer attributes', () => {
// General layer
let layer = capabilities.getExternalLayerObject('BlueMarbleSecondGenerationAG', WGS84)
expect(layer.externalLayerId).toBe('BlueMarbleSecondGenerationAG')
expect(layer.name).toBe('Blue Marble Second Generation - AG')
expect(layer.abstract).toBe('Blue Marble Second Generation Canton Aargau Product')
expect(layer.baseURL).toBe('http://maps.example.com/cgi-bin/map.cgi?')
expect(layer.baseURL).toBe('https://example.com')

// Layer without .Identifier
layer = capabilities.getExternalLayerObject('BlueMarbleThirdGenerationZH', WGS84)
expect(layer.externalLayerId).toBe('BlueMarbleThirdGenerationZH')
expect(layer.name).toBe('BlueMarbleThirdGenerationZH')
expect(layer.abstract).toBe('Blue Marble Third Generation Canton Zürich Product')
expect(layer.baseURL).toBe('http://maps.example.com/cgi-bin/map.cgi?')
expect(layer.baseURL).toBe('https://example.com')
})
it('Parse layer attribution', () => {
// General layer
Expand Down
9 changes: 8 additions & 1 deletion src/store/modules/layers.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,14 @@ const mutations = {
state.activeLayers.push(layer)
},
updateLayer(state, layer) {
Object.assign(getActiveLayerById(state, layer.getID()), layer)
const layer2Update = getActiveLayerById(state, layer.getID())
if (layer2Update) {
Object.assign(layer2Update, layer)
} else {
throw new Error(
`Failed to update layer ${layer.getID()}: layer not found in active layers`
)
}
},
removeLayerWithId(state, layerId) {
state.activeLayers = removeActiveLayerById(state, layerId)
Expand Down
2 changes: 1 addition & 1 deletion src/store/plugins/external-layers.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function updateExternalLayer(store, externalLayer, projection) {
updatedExternalLayer.isLoading = false
store.dispatch('updateLayer', updatedExternalLayer)
} catch (error) {
log.error(`Failed to update external layer: ${error}`)
log.error(`Failed to update external layer: `, error)
}
}

Expand Down
Loading