Fix code tests for #8276 for real this time

Add utilFetchJson to get around some quirks of d3.json and use it for coreFileFetcher
Load real general English locale strings at the beginning of code tests
This commit is contained in:
Quincy Morgan
2021-02-23 11:50:00 -05:00
parent 997b453b98
commit 13ddeecfa7
5 changed files with 40 additions and 41 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
import { json as d3_json } from 'd3-fetch';
import { utilFetchJson } from '../util/util';
let _mainFileFetcher = coreFileFetcher(); // singleton
@@ -54,7 +54,7 @@ export function coreFileFetcher() {
let prom = _inflight[url];
if (!prom) {
_inflight[url] = prom = d3_json(url)
_inflight[url] = prom = utilFetchJson(url)
.then(result => {
delete _inflight[url];
if (!result) {
+1
View File
@@ -26,6 +26,7 @@ export { utilEntitySelector } from './util';
export { utilEntityOrMemberSelector } from './util';
export { utilEntityOrDeepMemberSelector } from './util';
export { utilFastMouse } from './util';
export { utilFetchJson } from './util';
export { utilFunctor } from './util';
export { utilGetAllNodes } from './util';
export { utilGetSetValue } from './get_set_value';
+11
View File
@@ -572,3 +572,14 @@ export function utilUnicodeCharsCount(str) {
export function utilUnicodeCharsTruncated(str, limit) {
return Array.from(str).slice(0, limit).join('');
}
// Variation of d3.json (https://github.com/d3/d3-fetch/blob/master/src/json.js)
export function utilFetchJson(resourse, init) {
return fetch(resourse, init)
.then((response) => {
// fetch in PhantomJS tests may return ok=false and status=0 even if it's okay
if ((!response.ok && response.status !== 0) || !response.json) throw new Error(response.status + ' ' + response.statusText);
if (response.status === 204 || response.status === 205) return;
return response.json();
});
}
+9 -3
View File
@@ -7,9 +7,16 @@ for (var k in iD.services) { delete iD.services[k]; }
// Run without data for speed (tests which need data can set it up themselves)
iD.fileFetcher.assetPath('../dist/');
// Initializing `coreContext` will try loading the locale data and English locale strings:
iD.fileFetcher.cache().locales = { en: { rtl: false, languageNames: {}, scriptNames: {} }};
iD.fileFetcher.cache().locale_en = { en: {} };
iD.fileFetcher.cache().locales = { en: { rtl: false, pct: 1}};
iD.fileFetcher.cache().locales_index_tagging = { en: { rtl: false, pct: 1 } };
iD.fileFetcher.cache().locale_tagging_en = { en: {} };
iD.fileFetcher.cache().locales_index_general = { en: { rtl: false, pct: 1 } };
// load the actual data for `iD.fileFetcher.cache().locale_general_en`
iD.localizer.loadLocale('en', 'general', 'locales');
// Initializing `coreContext` initializes `_background`, which tries loading:
iD.fileFetcher.cache().imagery = [];
// Initializing `coreContext` initializes `_presets`, which tries loading:
@@ -24,7 +31,6 @@ iD.fileFetcher.cache().nsi_filters = { discardNames: [] };
// Initializing `coreContext` initializes `_uploader`, which tries loading:
iD.fileFetcher.cache().discarded = {};
mocha.setup({
timeout: 5000, // 5 sec
ui: 'bdd',
+17 -36
View File
@@ -227,48 +227,29 @@ describe('iD.util', function() {
});
describe('utilDisplayName', function() {
before(function() {
iD.fileFetcher.assetPath('dist/');
});
after(function() {
iD.fileFetcher.assetPath('');
});
it('returns the name if tagged with a name', function() {
expect(iD.utilDisplayName({tags: {name: 'East Coast Greenway'}})).to.eql('East Coast Greenway');
});
it('distinguishes unnamed features by ref', function(done) {
iD.localizer.loadLocale('en', 'general', 'locales').then(function() {
expect(iD.utilDisplayName({tags: {ref: '66'}})).to.eql('66');
done();
});
it('distinguishes unnamed features by ref', function() {
expect(iD.utilDisplayName({tags: {ref: '66'}})).to.eql('66');
});
it('distinguishes unnamed features by network or cycle_network', function(done) {
iD.localizer.loadLocale('en', 'general', 'locales').then(function() {
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X'}})).to.eql('SORTA 3X');
expect(iD.utilDisplayName({tags: {network: 'ncn', cycle_network: 'US:US', ref: '76'}})).to.eql('US:US 76');
done();
});
it('distinguishes unnamed features by network or cycle_network', function() {
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X'}})).to.eql('SORTA 3X');
expect(iD.utilDisplayName({tags: {network: 'ncn', cycle_network: 'US:US', ref: '76'}})).to.eql('US:US 76');
});
it('distinguishes unnamed routes by direction', function(done) {
iD.localizer.loadLocale('en', 'general', 'locales').then(function() {
expect(iD.utilDisplayName({tags: {network: 'US:US', ref: '66', direction: 'west', route: 'road'}})).to.eql('US:US 66 west');
// Marguerite X: Counter-Clockwise
expect(iD.utilDisplayName({tags: {network: 'Marguerite', ref: 'X', direction: 'anticlockwise', route: 'bus'}})).to.eql('Marguerite X anticlockwise');
done();
});
it('distinguishes unnamed routes by direction', function() {
expect(iD.utilDisplayName({tags: {network: 'US:US', ref: '66', direction: 'west', route: 'road'}})).to.eql('US:US 66 west');
// Marguerite X: Counter-Clockwise
expect(iD.utilDisplayName({tags: {network: 'Marguerite', ref: 'X', direction: 'anticlockwise', route: 'bus'}})).to.eql('Marguerite X anticlockwise');
});
it('distinguishes unnamed routes by waypoints', function(done) {
iD.localizer.loadLocale('en', 'general', 'locales').then(function() {
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', from: 'Downtown', route: 'bus'}})).to.eql('SORTA 3X');
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', to: 'Kings Island', route: 'bus'}})).to.eql('SORTA 3X');
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', via: 'Montgomery', route: 'bus'}})).to.eql('SORTA 3X');
// Green Line: Old Ironsides => Winchester
expect(iD.utilDisplayName({tags: {network: 'VTA', ref: 'Green', from: 'Old Ironsides', to: 'Winchester', route: 'bus'}})).to.eql('VTA Green from Old Ironsides to Winchester');
// BART Yellow Line: Antioch => Pittsburg/Bay Point => SFO Airport => Millbrae
expect(iD.utilDisplayName({tags: {network: 'BART', ref: 'Yellow', from: 'Antioch', to: 'Millbrae', via: 'Pittsburg/Bay Point;San Francisco International Airport', route: 'subway'}})).to.eql('BART Yellow from Antioch to Millbrae via Pittsburg/Bay Point;San Francisco International Airport');
done();
});
it('distinguishes unnamed routes by waypoints', function() {
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', from: 'Downtown', route: 'bus'}})).to.eql('SORTA 3X');
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', to: 'Kings Island', route: 'bus'}})).to.eql('SORTA 3X');
expect(iD.utilDisplayName({tags: {network: 'SORTA', ref: '3X', via: 'Montgomery', route: 'bus'}})).to.eql('SORTA 3X');
// Green Line: Old Ironsides => Winchester
expect(iD.utilDisplayName({tags: {network: 'VTA', ref: 'Green', from: 'Old Ironsides', to: 'Winchester', route: 'bus'}})).to.eql('VTA Green from Old Ironsides to Winchester');
// BART Yellow Line: Antioch => Pittsburg/Bay Point => SFO Airport => Millbrae
expect(iD.utilDisplayName({tags: {network: 'BART', ref: 'Yellow', from: 'Antioch', to: 'Millbrae', via: 'Pittsburg/Bay Point;San Francisco International Airport', route: 'subway'}})).to.eql('BART Yellow from Antioch to Millbrae via Pittsburg/Bay Point;San Francisco International Airport');
});
});
});