From 6732ca6edacb68290fc881a43fb1d7b90a6451f4 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 11 Dec 2018 00:42:06 -0500 Subject: [PATCH] Comboboxes no longer show on focus.. update tests --- modules/ui/combobox.js | 7 ++++--- test/spec/ui/combobox.js | 40 ++++++++++++++++------------------------ 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/modules/ui/combobox.js b/modules/ui/combobox.js index 030600733..8173021bc 100644 --- a/modules/ui/combobox.js +++ b/modules/ui/combobox.js @@ -83,7 +83,7 @@ export function uiCombobox(context) { function focus() { - fetch('', render); + fetch(''); // prefetch values (may warm taginfo cache) } @@ -242,7 +242,6 @@ export function uiCombobox(context) { if (comboRect.bottom > containerRect.bottom) { var node = attachTo ? attachTo.node() : input.node(); - var rect = node.getBoundingClientRect(); node.scrollIntoView({ behavior: 'instant', block: 'center' }); render(); } @@ -271,7 +270,9 @@ export function uiCombobox(context) { function fetch(v, cb) { _fetcher.call(input, v, function(results) { _suggestions = results; - cb(); + if (cb) { + cb(); + } }); } diff --git a/test/spec/ui/combobox.js b/test/spec/ui/combobox.js index d443ede49..48953282a 100644 --- a/test/spec/ui/combobox.js +++ b/test/spec/ui/combobox.js @@ -37,6 +37,7 @@ describe('uiCombobox', function() { case '↑': case '↓': case '↩': + case '⎋': break; case '⌫': @@ -89,40 +90,20 @@ describe('uiCombobox', function() { it('adds combobox under container', function() { input.call(combobox.data(data)); - focusTypeahead(input); - expect(d3.select('body > div.combobox').nodes().length).to.equal(0); + body.selectAll('.combobox-caret').dispatch('mousedown'); expect(d3.select('.id-container > div.combobox').nodes().length).to.equal(1); }); - it('shows a menu of entries on focus', function() { + it('filters entries to those matching the value', function() { input.call(combobox.data(data)); focusTypeahead(input); - expect(body.selectAll('.combobox-option').nodes().length).to.equal(5); - expect(body.selectAll('.combobox-option').text()).to.equal('foobar'); - }); - - it('filters entries to those matching the value', function() { - input.property('value', 'b').call(combobox.data(data)); - focusTypeahead(input); + simulateKeypress('b'); expect(body.selectAll('.combobox-option').size()).to.equal(3); expect(body.selectAll('.combobox-option').nodes()[0].text).to.equal('foobar'); expect(body.selectAll('.combobox-option').nodes()[1].text).to.equal('bar'); expect(body.selectAll('.combobox-option').nodes()[2].text).to.equal('Baz'); }); - it('shows no menu on focus if it would contain only one item', function() { - input.property('value', 't').call(combobox.data(data)); - focusTypeahead(input); - expect(body.selectAll('.combobox-option').size()).to.equal(0); - }); - - it('shows menu on focus if it would contain at least minItems items', function() { - combobox.minItems(1); - input.property('value', 't').call(combobox.data(data)); - focusTypeahead(input); - expect(body.selectAll('.combobox-option').size()).to.equal(1); - }); - it('shows all entries when clicking on the caret', function() { input.property('value', 'foobar').call(combobox.data(data)); body.selectAll('.combobox-caret').dispatch('mousedown'); @@ -132,7 +113,7 @@ describe('uiCombobox', function() { it('is initially shown with no selection', function() { input.call(combobox.data(data)); - focusTypeahead(input); + body.selectAll('.combobox-caret').dispatch('mousedown'); expect(body.selectAll('.combobox-option.selected').size()).to.equal(0); }); @@ -280,6 +261,17 @@ describe('uiCombobox', function() { simulateKeypress('↩'); }); + it('emits cancel event with selected datum on ⎋', function(done) { + combobox.on('cancel', function(d) { + expect(d).to.eql({title: 'bar', value: 'bar'}); + done(); + }); + input.call(combobox.data(data)); + focusTypeahead(input); + simulateKeypress('b'); + simulateKeypress('⎋'); + }); + it('hides on ↩', function() { input.call(combobox.data(data)); input.node().focus();