From ff97d44395127234e8a6fcbbefe2f9aef874bd12 Mon Sep 17 00:00:00 2001 From: Aaron Lidman Date: Fri, 1 Nov 2013 16:57:33 -0700 Subject: [PATCH] Add tests for suggestNames --- test/index.html | 2 ++ test/index_packaged.html | 1 + test/spec/ui/preset/localized.js | 2 +- test/spec/util/suggest_names.js | 36 ++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/spec/util/suggest_names.js diff --git a/test/index.html b/test/index.html index 14fb4087e..0ea970316 100644 --- a/test/index.html +++ b/test/index.html @@ -192,6 +192,7 @@ + @@ -273,6 +274,7 @@ + diff --git a/test/index_packaged.html b/test/index_packaged.html index 356e4b687..55c067b52 100644 --- a/test/index_packaged.html +++ b/test/index_packaged.html @@ -91,6 +91,7 @@ + diff --git a/test/spec/ui/preset/localized.js b/test/spec/ui/preset/localized.js index 040adc414..d02a0dc1a 100644 --- a/test/spec/ui/preset/localized.js +++ b/test/spec/ui/preset/localized.js @@ -3,7 +3,7 @@ describe('iD.ui.preset.localized', function() { beforeEach(function() { selection = d3.select(document.createElement('div')); - field = iD().presets().field('name'); + field = iD.presets.Field('test', {key: 'name'}); }); it("adds a blank set of fields when the + button is clicked", function() { diff --git a/test/spec/util/suggest_names.js b/test/spec/util/suggest_names.js new file mode 100644 index 000000000..a26934c51 --- /dev/null +++ b/test/spec/util/suggest_names.js @@ -0,0 +1,36 @@ +describe("iD.util.SuggestNames", function() { + var suggestions = { + 'key': { + 'value': { + 'abcdef': {}, + 'ghijkl': {} + } + } + }; + + var preset = { + 'id': 'key/value' + }; + + var a = iD.util.SuggestNames(preset, suggestions); + + it('provides suggestions for an entered value', function(done) { + a('abcd', function(result) { + expect(result).to.eql([ + { + title: 'abcdef', + value: 'abcdef', + dist: 0 + } + ]); + done(); + }); + }); + + it('provides no suggestions for short values', function(done){ + a('ab', function(result) { + expect(result).to.eql([]); + done(); + }); + }); +});