From 27d86011bc02ca7e7183c8dd32da6f3e20206d07 Mon Sep 17 00:00:00 2001 From: prusswan Date: Tue, 28 Jan 2025 23:33:36 +0800 Subject: [PATCH] added cypress e2e test, updated translation strings --- cypress/e2e/local-file.cy.ts | 44 ++++++++++++++++++++++++++++ cypress/fixtures/polygon-z0.pmtiles | Bin 0 -> 468 bytes src/components/AppToolbar.tsx | 4 ++- src/components/MapMaplibreGl.tsx | 11 +++++-- src/locales/de/translation.json | 2 ++ src/locales/fr/translation.json | 2 ++ src/locales/he/translation.json | 2 ++ src/locales/ja/translation.json | 2 ++ src/locales/zh/translation.json | 2 ++ 9 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 cypress/e2e/local-file.cy.ts create mode 100644 cypress/fixtures/polygon-z0.pmtiles diff --git a/cypress/e2e/local-file.cy.ts b/cypress/e2e/local-file.cy.ts new file mode 100644 index 000000000..369596742 --- /dev/null +++ b/cypress/e2e/local-file.cy.ts @@ -0,0 +1,44 @@ +import { MaputnikDriver } from "./maputnik-driver"; + +describe("local file", () => { + const { when, get } = new MaputnikDriver(); + + beforeEach(() => { + when.setStyle(""); + }); + + describe("PMTiles", () => { + it("valid file loads without error", () => { + const fileName = "polygon-z0.pmtiles"; // a small polygon located at Null Island + + const stub = cy.stub(); + cy.on('window:alert', stub); + + get + .bySelector("file", "type") + .selectFile(`cypress/fixtures/${fileName}`, { force: true }); + when.wait(200); + cy.then(() => { + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + expect(stub).to.not.have.been.called; + }); + }); + + it("invalid file results in error", () => { + const fileName = "example-style.json"; + + const stub = cy.stub(); + cy.on('window:alert', stub); + + get + .bySelector("file", "type") + .selectFile(`cypress/fixtures/${fileName}`, { force: true }); + when.wait(200); + cy.then(() => { + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + expect(stub).to.be.called; + expect(stub.getCall(0).args[0]).to.contain('File type is not supported'); + }); + }) + }); +}); diff --git a/cypress/fixtures/polygon-z0.pmtiles b/cypress/fixtures/polygon-z0.pmtiles new file mode 100644 index 0000000000000000000000000000000000000000..c86db1f27bba6d3818bb5da5ac6b78e8f6e3303a GIT binary patch literal 468 zcmWIW4av+&EoQD~fB;D-Jp)RAhtlX&KO;oM6)FMcGN988OiVB#pvwAbGZ-3x7!KsS zIlyct;pCKrl2jH3ANx)QR-h0r{uR(?Y;E0N${r@wV$Rqz?{?h$%CZ~pR-fD;chPxcGvD5#swCfUJ3q9X zyYJfGQaN*z>CwX)(_MHoE_$j>pZmpR;iPE+bNH@ihyD-PGDW#IC`?~Ew^Gu@^U;5~ zMLN|*T=}&jpE@sYjM(y1WHrOxzp@|qI{uNHt+DuR>j{?#b(QndSF&YxKiSJB=o0K; zmUMDvv&>(=%}+VLv)Zh>lkdN)q3RE>2ir|u&wq}OjgFMDdZaDyH+~%MwD)0=m+&ls zb+dE0Za)PE6vEq+FRf2_B&6%9tJmp&dX0vru2-+Q&I#R { return e.errors.map(f => f.message).join("\n") }).join("\n"); console.error("Dropzone file rejected:", errorMessageLine); - alert(errorMessageLine); + + const alertMessage = this.props.t("File type is not supported"); + alert(alertMessage); } render() { diff --git a/src/components/MapMaplibreGl.tsx b/src/components/MapMaplibreGl.tsx index f466cfc0e..52eb5d31a 100644 --- a/src/components/MapMaplibreGl.tsx +++ b/src/components/MapMaplibreGl.tsx @@ -78,6 +78,13 @@ type MapMaplibreGlState = { pmtilesProtocol: Protocol | null; }; +interface Metadata { + name?: string; + type?: string; + tilestats?: unknown; + vector_layers: LayerSpecification[]; +} + class MapMaplibreGlInternal extends React.Component { static defaultProps = { onMapLoaded: () => {}, @@ -143,13 +150,13 @@ class MapMaplibreGlInternal extends React.Component { + (file.getMetadata() as Promise).then(metadata => { const layerNames = metadata.vector_layers.map((e: LayerSpecification) => e.id); // used by maplibre-gl-inspect to pick up inspectable layers map.style.sourceCaches["source"]._source.vectorLayerIds = layerNames; }).catch( e => { - console.error(`Error in reading local PMTiles file: ${e}`); + console.error(`${t('Error in reading local PMTiles file')}: ${e}`); }); } } diff --git a/src/locales/de/translation.json b/src/locales/de/translation.json index a65af8bd0..1ca24baa8 100644 --- a/src/locales/de/translation.json +++ b/src/locales/de/translation.json @@ -18,6 +18,7 @@ "Convert property to data function": "Eigenschaft in eine Datenfunktion umwandeln", "Layer <1>{formatLayerId(layerId)}: {parsed.data.message}": "Ebene <1>{formatLayerId(layerId)}: {parsed.data.message}", "switch to layer": "zur Ebene wechseln", + "File type is not supported": "__STRING_NOT_TRANSLATED__", "Map": "Karte", "Inspect": "Untersuchen", "Deuteranopia filter": "Deuteranopie-Filter", @@ -73,6 +74,7 @@ "Collapse": "Einklappen", "Expand": "Ausklappen", "Add Layer": "Ebene hinzufügen", + "Error in reading local PMTiles file": "__STRING_NOT_TRANSLATED__", "Search": "Suche", "Zoom:": "Zoom:", "Close popup": "Popup schließen", diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.json index 90e709401..8d0d4db8c 100644 --- a/src/locales/fr/translation.json +++ b/src/locales/fr/translation.json @@ -18,6 +18,7 @@ "Convert property to data function": "Convertir la propriété en fonction de données", "Layer <1>{formatLayerId(layerId)}: {parsed.data.message}": "Calque <1>{formatLayerId(layerId)} : {parsed.data.message}", "switch to layer": "changer de calque", + "File type is not supported": "__STRING_NOT_TRANSLATED__", "Map": "Carte", "Inspect": "Inspecter", "Deuteranopia filter": "Filtre Deutéranopie", @@ -73,6 +74,7 @@ "Collapse": "Réduire", "Expand": "Développer", "Add Layer": "Ajouter un calque", + "Error in reading local PMTiles file": "__STRING_NOT_TRANSLATED__", "Search": "Recherche", "Zoom:": "Zoom :", "Close popup": "Fermer la fenêtre", diff --git a/src/locales/he/translation.json b/src/locales/he/translation.json index 03fa8010e..b97e022bf 100644 --- a/src/locales/he/translation.json +++ b/src/locales/he/translation.json @@ -18,6 +18,7 @@ "Convert property to data function": "המרה לפונקציית מידע", "Layer <1>{formatLayerId(layerId)}: {parsed.data.message}": "שכבה <1>{formatLayerId(layerId)}: {parsed.data.message}", "switch to layer": "שינוי לשכבה", + "File type is not supported": "__STRING_NOT_TRANSLATED__", "Map": "מפה", "Inspect": "בדיקה", "Deuteranopia filter": "Deuteranopia filter", @@ -73,6 +74,7 @@ "Collapse": "הקטנה", "Expand": "הגדלה", "Add Layer": "הוספת שכבה", + "Error in reading local PMTiles file": "__STRING_NOT_TRANSLATED__", "Search": "חיפוש", "Zoom:": "זום:", "Close popup": "סגירת החלון", diff --git a/src/locales/ja/translation.json b/src/locales/ja/translation.json index 67e46448b..c4f3f01cb 100644 --- a/src/locales/ja/translation.json +++ b/src/locales/ja/translation.json @@ -18,6 +18,7 @@ "Convert property to data function": "プロパティをデータ関数に変換する", "Layer <1>{formatLayerId(layerId)}: {parsed.data.message}": "レイヤ<1>{formatLayerId(layerId)}: {parsed.data.message}", "switch to layer": "レイヤへ切替", + "File type is not supported": "__STRING_NOT_TRANSLATED__", "Map": "地図", "Inspect": "検査", "Deuteranopia filter": "緑色盲フィルタ", @@ -73,6 +74,7 @@ "Collapse": "畳む", "Expand": "展開", "Add Layer": "レイヤー追加", + "Error in reading local PMTiles file": "__STRING_NOT_TRANSLATED__", "Search": "検索", "Zoom:": "ズーム:", "Close popup": "ポップアップを閉じる", diff --git a/src/locales/zh/translation.json b/src/locales/zh/translation.json index 0e28345ae..959ae16e9 100644 --- a/src/locales/zh/translation.json +++ b/src/locales/zh/translation.json @@ -18,6 +18,7 @@ "Convert property to data function": "将属性转换为数据函数", "Layer <1>{formatLayerId(layerId)}: {parsed.data.message}": "图层<1>{formatLayerId(layerId)}: {parsed.data.message}", "switch to layer": "切换到图层", + "File type is not supported": "__STRING_NOT_TRANSLATED__", "Map": "地图", "Inspect": "检查", "Deuteranopia filter": "绿色盲滤镜", @@ -73,6 +74,7 @@ "Collapse": "折叠", "Expand": "展开", "Add Layer": "添加图层", + "Error in reading local PMTiles file": "__STRING_NOT_TRANSLATED__", "Search": "搜索", "Zoom:": "缩放:", "Close popup": "关闭弹出窗口",