Skip to content

Commit cbbac9e

Browse files
committed
added cypress e2e test, updated translation strings
1 parent d6cde2f commit cbbac9e

File tree

9 files changed

+66
-3
lines changed

9 files changed

+66
-3
lines changed

cypress/e2e/local-file.cy.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { MaputnikDriver } from "./maputnik-driver";
2+
3+
describe("local file", () => {
4+
const { when, get } = new MaputnikDriver();
5+
6+
beforeEach(() => {
7+
when.setStyle("");
8+
});
9+
10+
describe("PMTiles", () => {
11+
it("valid file loads without error", () => {
12+
const fileName = "polygon-z0.pmtiles"; // a small polygon located at Null Island
13+
14+
const stub = cy.stub();
15+
cy.on('window:alert', stub);
16+
17+
get
18+
.bySelector("file", "type")
19+
.selectFile(`cypress/fixtures/${fileName}`, { force: true });
20+
when.wait(200);
21+
cy.then(() => {
22+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
23+
expect(stub).to.not.have.been.called;
24+
});
25+
});
26+
27+
it("invalid file results in error", () => {
28+
const fileName = "example-style.json";
29+
30+
const stub = cy.stub();
31+
cy.on('window:alert', stub);
32+
33+
get
34+
.bySelector("file", "type")
35+
.selectFile(`cypress/fixtures/${fileName}`, { force: true });
36+
when.wait(200);
37+
cy.then(() => {
38+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
39+
expect(stub).to.be.called;
40+
expect(stub.getCall(0).args[0]).to.contain('File type is not supported');
41+
});
42+
})
43+
});
44+
});
468 Bytes
Binary file not shown.

src/components/AppToolbar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
147147
return e.errors.map(f => f.message).join("\n")
148148
}).join("\n");
149149
console.error("Dropzone file rejected:", errorMessageLine);
150-
alert(errorMessageLine);
150+
151+
const alertMessage = this.props.t("File type is not supported");
152+
alert(alertMessage);
151153
}
152154

153155
render() {

src/components/MapMaplibreGl.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ type MapMaplibreGlState = {
7878
pmtilesProtocol: Protocol | null;
7979
};
8080

81+
interface Metadata {
82+
name?: string;
83+
type?: string;
84+
tilestats?: unknown;
85+
vector_layers: LayerSpecification[];
86+
}
87+
8188
class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps, MapMaplibreGlState> {
8289
static defaultProps = {
8390
onMapLoaded: () => {},
@@ -143,13 +150,13 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
143150
this.state.pmtilesProtocol!.add(file); // this is necessary for non-HTTP sources
144151

145152
if (map) {
146-
file.getMetadata().then((metadata: any) => {
153+
(file.getMetadata() as Promise<Metadata>).then(metadata => {
147154
const layerNames = metadata.vector_layers.map((e: LayerSpecification) => e.id);
148155

149156
// used by maplibre-gl-inspect to pick up inspectable layers
150157
map.style.sourceCaches["source"]._source.vectorLayerIds = layerNames;
151158
}).catch( e => {
152-
console.error(`Error in reading local PMTiles file: ${e}`);
159+
console.error(`${this.props.t('Error in reading local PMTiles file')}: ${e}`);
153160
});
154161
}
155162
}

src/locales/de/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"Convert property to data function": "Eigenschaft in eine Datenfunktion umwandeln",
1919
"Layer <1>{formatLayerId(layerId)}</1>: {parsed.data.message}": "Ebene <1>{formatLayerId(layerId)}</1>: {parsed.data.message}",
2020
"switch to layer": "zur Ebene wechseln",
21+
"File type is not supported": "__STRING_NOT_TRANSLATED__",
2122
"Map": "Karte",
2223
"Inspect": "Untersuchen",
2324
"Deuteranopia filter": "Deuteranopie-Filter",
@@ -73,6 +74,7 @@
7374
"Collapse": "Einklappen",
7475
"Expand": "Ausklappen",
7576
"Add Layer": "Ebene hinzufügen",
77+
"Error in reading local PMTiles file": "__STRING_NOT_TRANSLATED__",
7678
"Search": "Suche",
7779
"Zoom:": "Zoom:",
7880
"Close popup": "Popup schließen",

src/locales/fr/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"Convert property to data function": "Convertir la propriété en fonction de données",
1919
"Layer <1>{formatLayerId(layerId)}</1>: {parsed.data.message}": "Calque <1>{formatLayerId(layerId)}</1> : {parsed.data.message}",
2020
"switch to layer": "changer de calque",
21+
"File type is not supported": "__STRING_NOT_TRANSLATED__",
2122
"Map": "Carte",
2223
"Inspect": "Inspecter",
2324
"Deuteranopia filter": "Filtre Deutéranopie",
@@ -73,6 +74,7 @@
7374
"Collapse": "Réduire",
7475
"Expand": "Développer",
7576
"Add Layer": "Ajouter un calque",
77+
"Error in reading local PMTiles file": "__STRING_NOT_TRANSLATED__",
7678
"Search": "Recherche",
7779
"Zoom:": "Zoom :",
7880
"Close popup": "Fermer la fenêtre",

src/locales/he/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"Convert property to data function": "המרה לפונקציית מידע",
1919
"Layer <1>{formatLayerId(layerId)}</1>: {parsed.data.message}": "שכבה <1>{formatLayerId(layerId)}</1>: {parsed.data.message}",
2020
"switch to layer": "שינוי לשכבה",
21+
"File type is not supported": "__STRING_NOT_TRANSLATED__",
2122
"Map": "מפה",
2223
"Inspect": "בדיקה",
2324
"Deuteranopia filter": "Deuteranopia filter",
@@ -73,6 +74,7 @@
7374
"Collapse": "הקטנה",
7475
"Expand": "הגדלה",
7576
"Add Layer": "הוספת שכבה",
77+
"Error in reading local PMTiles file": "__STRING_NOT_TRANSLATED__",
7678
"Search": "חיפוש",
7779
"Zoom:": "זום:",
7880
"Close popup": "סגירת החלון",

src/locales/ja/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"Convert property to data function": "プロパティをデータ関数に変換する",
1919
"Layer <1>{formatLayerId(layerId)}</1>: {parsed.data.message}": "レイヤ<1>{formatLayerId(layerId)}</1>: {parsed.data.message}",
2020
"switch to layer": "レイヤへ切替",
21+
"File type is not supported": "__STRING_NOT_TRANSLATED__",
2122
"Map": "地図",
2223
"Inspect": "検査",
2324
"Deuteranopia filter": "緑色盲フィルタ",
@@ -73,6 +74,7 @@
7374
"Collapse": "畳む",
7475
"Expand": "展開",
7576
"Add Layer": "レイヤー追加",
77+
"Error in reading local PMTiles file": "__STRING_NOT_TRANSLATED__",
7678
"Search": "検索",
7779
"Zoom:": "ズーム:",
7880
"Close popup": "ポップアップを閉じる",

src/locales/zh/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"Convert property to data function": "将属性转换为数据函数",
1919
"Layer <1>{formatLayerId(layerId)}</1>: {parsed.data.message}": "图层<1>{formatLayerId(layerId)}</1>: {parsed.data.message}",
2020
"switch to layer": "切换到图层",
21+
"File type is not supported": "__STRING_NOT_TRANSLATED__",
2122
"Map": "地图",
2223
"Inspect": "检查",
2324
"Deuteranopia filter": "绿色盲滤镜",
@@ -73,6 +74,7 @@
7374
"Collapse": "折叠",
7475
"Expand": "展开",
7576
"Add Layer": "添加图层",
77+
"Error in reading local PMTiles file": "__STRING_NOT_TRANSLATED__",
7678
"Search": "搜索",
7779
"Zoom:": "缩放:",
7880
"Close popup": "关闭弹出窗口",

0 commit comments

Comments
 (0)