From 998732b070831f6188fc40fd0b4f6e9a06bf6026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Fri, 22 Mar 2024 17:05:40 +0100 Subject: [PATCH] chore: move URLs tests to mocha cli --- umap/static/umap/js/modules/urls.js | 19 +++++++++++++++++-- umap/static/umap/{test => unittests}/URLs.js | 5 +++++ 2 files changed, 22 insertions(+), 2 deletions(-) rename umap/static/umap/{test => unittests}/URLs.js (95%) diff --git a/umap/static/umap/js/modules/urls.js b/umap/static/umap/js/modules/urls.js index fd3d4b5f..bdf54363 100644 --- a/umap/static/umap/js/modules/urls.js +++ b/umap/static/umap/js/modules/urls.js @@ -1,4 +1,19 @@ -import { Util } from '../../vendors/leaflet/leaflet-src.esm.js' +// Vendorized from leaflet.utils +// https://github.com/Leaflet/Leaflet/blob/108c6717b70f57c63645498f9bd66b6677758786/src/core/Util.js#L132-L151 +var templateRe = /\{ *([\w_ -]+) *\}/g + +function template(str, data) { + return str.replace(templateRe, function (str, key) { + var value = data[key] + + if (value === undefined) { + throw new Error('No value provided for variable ' + str) + } else if (typeof value === 'function') { + value = value(data) + } + return value + }) +} export default class URLs { constructor(serverUrls) { @@ -9,7 +24,7 @@ export default class URLs { if (typeof this[urlName] === 'function') return this[urlName](params) if (this.urls.hasOwnProperty(urlName)) { - return Util.template(this.urls[urlName], params) + return template(this.urls[urlName], params) } else { throw `Unable to find a URL for route ${urlName}` } diff --git a/umap/static/umap/test/URLs.js b/umap/static/umap/unittests/URLs.js similarity index 95% rename from umap/static/umap/test/URLs.js rename to umap/static/umap/unittests/URLs.js index ccd8a91b..5ad50115 100644 --- a/umap/static/umap/test/URLs.js +++ b/umap/static/umap/unittests/URLs.js @@ -1,3 +1,8 @@ +import { describe, it } from 'mocha' + +import pkg from 'chai' +const { expect, assert } = pkg + import URLs from '../js/modules/urls.js' describe('URLs', () => {