From bd736ef3e4a2554147cc49a55537052489ed7bfe Mon Sep 17 00:00:00 2001 From: marc tobias Date: Tue, 15 Nov 2022 23:28:37 +0100 Subject: [PATCH] formatLabel: dont print -Yes- as label --- src/lib/helpers.js | 4 ++-- test/unit/helpers.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 test/unit/helpers.js diff --git a/src/lib/helpers.js b/src/lib/helpers.js index a2e5d82..de1cfd4 100644 --- a/src/lib/helpers.js +++ b/src/lib/helpers.js @@ -41,8 +41,8 @@ function formatLabel(aPlace) { return s && s[0].toUpperCase() + s.slice(1); } - if (aPlace.type && aPlace.type === 'yes' && aPlace.class) { - return capitalize(aPlace.class.replace(/_/g, ' ')); + if (aPlace.type && aPlace.type === 'yes' && aPlace.category) { + return capitalize(aPlace.category.replace(/_/g, ' ')); } if (aPlace.type) { return capitalize(aPlace.type.replace(/_/g, ' ')); diff --git a/test/unit/helpers.js b/test/unit/helpers.js new file mode 100644 index 0000000..9570059 --- /dev/null +++ b/test/unit/helpers.js @@ -0,0 +1,37 @@ +const assert = require('assert'); +const helpers = require('../../src/lib/helpers'); + +describe('Helpers', function () { + + it('.formatLabel', function () { + // not enough data + assert.equal(helpers.formatLabel({}), ''); + + // if label set, that becomes the label + assert.equal(helpers.formatLabel({ label: 'A Label' }), 'A Label'); + + // type, but nicely formatted + assert.equal(helpers.formatLabel({ category: 'highway', type: 'bus_stop' }), 'Bus stop'); + + // type=yes, so we use the category + assert.equal(helpers.formatLabel({ category: 'building', type: 'yes' }), 'Building'); + }); + + it('.wikipediaLink', function () { + assert.equal( + helpers.wikipediaLink({}), + '' + ); + + assert.equal( + helpers.wikipediaLink({ calculated_wikipedia: 'de:Brandenburg Gate' }), + 'de:Brandenburg Gate' + ); + + // title includes HTML + assert.equal( + helpers.wikipediaLink({ calculated_wikipedia: 'en:Slug & Lattuce' }), + 'en:Slug & Lattuce' + ); + }); +}); -- 2.45.1