From 55a9d74553763848044ed0b3a780e7654719f34b Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 17 Mar 2013 19:40:37 -0700 Subject: [PATCH] Fix up Taglist test --- test/index.html | 1 + test/index_packaged.html | 1 + test/spec/ui/inspector.js | 70 ++++-------------------------------- test/spec/ui/taglist.js | 75 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 64 deletions(-) create mode 100644 test/spec/ui/taglist.js diff --git a/test/index.html b/test/index.html index 5109d0095..03d695d79 100644 --- a/test/index.html +++ b/test/index.html @@ -220,6 +220,7 @@ + diff --git a/test/index_packaged.html b/test/index_packaged.html index 24df9f978..db71efdad 100644 --- a/test/index_packaged.html +++ b/test/index_packaged.html @@ -66,6 +66,7 @@ + diff --git a/test/spec/ui/inspector.js b/test/spec/ui/inspector.js index a43c421f0..29f072652 100644 --- a/test/spec/ui/inspector.js +++ b/test/spec/ui/inspector.js @@ -1,63 +1,22 @@ describe("iD.ui.Inspector", function () { var inspector, element, tags = {highway: 'residential'}, - entity, graph, context; - - function render() { - inspector = iD.ui.Inspector(context); - element = d3.select('body') - .append('div') - .attr('id', 'inspector-wrap') - .datum(entity) - .call(inspector); - } + entity, context; beforeEach(function () { entity = iD.Entity({type: 'node', id: "n12345", tags: tags}); context = iD(); - render(); + inspector = iD.ui.Inspector(context, entity); + element = d3.select('body') + .append('div') + .attr('id', 'inspector-wrap') + .call(inspector); }); afterEach(function () { element.remove(); }); - describe("#tags", function () { - xit("returns the current tags", function () { - expect(inspector.tags()).to.eql(tags); - }); - - xit("returns updated tags when input values have changed", function () { - element.selectAll("input.key").property('value', 'k'); - element.selectAll("input.value").property('value', 'v'); - expect(inspector.tags()).to.eql({k: 'v'}); - }); - }); - - it("creates input elements for each key-value pair", function () { - expect(element.selectAll("input[value=highway]")).not.to.be.empty; - expect(element.selectAll("input[value=residential]")).not.to.be.empty; - }); - - it("creates a pair of empty input elements if the entity has no tags", function () { - element.remove(); - entity = entity.update({tags: {}}); - render(); - expect(element.select('.tag-list').selectAll("input.value").property('value')).to.be.empty; - expect(element.select('.tag-list').selectAll("input.key").property('value')).to.be.empty; - }); - - xit("adds tags when clicking the add button", function () { - element.selectAll("button.add-tag").trigger('click'); - expect(element.select('.tag-list').selectAll("input")[0][2].value).to.be.empty; - expect(element.select('.tag-list').selectAll("input")[0][3].value).to.be.empty; - }); - - xit("removes tags when clicking the remove button", function () { - element.selectAll("button.remove").trigger('click'); - expect(inspector.tags()).to.eql({}); - }); - it("emits a close event when the apply button is clicked", function () { var spy = sinon.spy(); inspector.on('close', spy); @@ -75,21 +34,4 @@ describe("iD.ui.Inspector", function () { expect(spy).to.have.been.calledWith(entity, tags); }); - - xit("adds tags when pressing the TAB key on last input.value", function () { - expect(element.selectAll('.tag-list li')[0].length).to.eql(1); - var input = d3.select('.tag-list li:last-child input.value')[0][0]; - happen.keydown(d3.select(input).node(), {keyCode: 9}); - expect(element.selectAll('.tag-list li')[0].length).to.eql(2); - expect(element.select('.tag-list').selectAll("input")[0][2].value).to.be.empty; - expect(element.select('.tag-list').selectAll("input")[0][3].value).to.be.empty; - }); - - it("does not add a tag when pressing TAB while shift is pressed", function () { - expect(element.selectAll('.tag-list li')[0].length).to.eql(1); - var input = d3.select('.tag-list li:last-child input.value')[0][0]; - happen.keydown(d3.select(input).node(), {keyCode: 9, shiftKey: true}); - expect(element.selectAll('.tag-list li')[0].length).to.eql(1); - }); - }); diff --git a/test/spec/ui/taglist.js b/test/spec/ui/taglist.js new file mode 100644 index 000000000..de993ac07 --- /dev/null +++ b/test/spec/ui/taglist.js @@ -0,0 +1,75 @@ +describe('iD.ui.Taglist', function() { + var taglist, element, + tags = {highway: 'residential'}, + entity, context; + + function render() { + taglist = iD.ui.Taglist(context, entity); + element = d3.select('body') + .append('div') + .call(taglist); + taglist.tags(entity.tags); + } + + beforeEach(function () { + entity = iD.Entity({type: 'node', id: "n12345", tags: tags}); + context = iD(); + render(); + }); + + afterEach(function () { + element.remove(); + }); + + describe("#tags", function () { + it("returns the current tags", function () { + expect(taglist.tags()).to.eql(tags); + }); + + it("returns updated tags when input values have changed", function () { + element.selectAll("input.key").property('value', 'k'); + element.selectAll("input.value").property('value', 'v'); + expect(taglist.tags()).to.eql({k: 'v'}); + }); + }); + + it("creates input elements for each key-value pair", function () { + expect(element.selectAll("input[value=highway]")).not.to.be.empty; + expect(element.selectAll("input[value=residential]")).not.to.be.empty; + }); + + it("creates a pair of empty input elements if the entity has no tags", function () { + element.remove(); + entity = entity.update({tags: {}}); + render(); + expect(element.select('.tag-list').selectAll("input.value").property('value')).to.be.empty; + expect(element.select('.tag-list').selectAll("input.key").property('value')).to.be.empty; + }); + + it("adds tags when clicking the add button", function () { + element.selectAll("button.add-tag").trigger('click'); + expect(element.select('.tag-list').selectAll("input")[0][2].value).to.be.empty; + expect(element.select('.tag-list').selectAll("input")[0][3].value).to.be.empty; + }); + + it("removes tags when clicking the remove button", function () { + element.selectAll("button.remove").trigger('click'); + expect(taglist.tags()).to.eql({}); + }); + + it("adds tags when pressing the TAB key on last input.value", function () { + expect(element.selectAll('.tag-list li')[0].length).to.eql(1); + var input = d3.select('.tag-list li:last-child input.value')[0][0]; + happen.keydown(d3.select(input).node(), {keyCode: 9}); + expect(element.selectAll('.tag-list li')[0].length).to.eql(2); + expect(element.select('.tag-list').selectAll("input")[0][2].value).to.be.empty; + expect(element.select('.tag-list').selectAll("input")[0][3].value).to.be.empty; + }); + + it("does not add a tag when pressing TAB while shift is pressed", function () { + expect(element.selectAll('.tag-list li')[0].length).to.eql(1); + var input = d3.select('.tag-list li:last-child input.value')[0][0]; + happen.keydown(d3.select(input).node(), {keyCode: 9, shiftKey: true}); + expect(element.selectAll('.tag-list li')[0].length).to.eql(1); + }); +});