From 4159e58f7fa0547b463390c1de028cc3f2ae9d57 Mon Sep 17 00:00:00 2001 From: Radoslav Vitanov Date: Thu, 18 Aug 2016 09:05:12 +0300 Subject: [PATCH] Start suggestions after first character not second fixes #3235 --- js/components/urlBarSuggestions.js | 5 ++++ test/components/navigationBarTest.js | 36 ++++++++++++++++++------ test/components/urlBarSuggestionsTest.js | 10 +++++++ 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/js/components/urlBarSuggestions.js b/js/components/urlBarSuggestions.js index add1be5e6b5..94912f8e92a 100644 --- a/js/components/urlBarSuggestions.js +++ b/js/components/urlBarSuggestions.js @@ -164,6 +164,11 @@ class UrlBarSuggestions extends ImmutableComponent { this.updateSuggestions(parseInt(e.target.dataset.index, 10)) } + componentDidMount () { + this.suggestionList = this.getNewSuggestionList() + this.searchXHR() + } + componentWillUpdate (prevProps) { if (this.selectedElement) { this.selectedElement.scrollIntoView() diff --git a/test/components/navigationBarTest.js b/test/components/navigationBarTest.js index 5bcd1f17847..00e5694f0c4 100644 --- a/test/components/navigationBarTest.js +++ b/test/components/navigationBarTest.js @@ -72,6 +72,7 @@ describe('navigationBar', function () { it('updates the location in the navbar when changed by the opener', function * () { yield this.app.client .windowByUrl(Brave.browserWindowUrl) + .ipcSend('shortcut-focus-url') .waitUntil(function () { return this.getValue(urlInput).then((val) => val === 'data:text/html;,%3Ctitle%3ETabnapping%20Target%3C/title%3E') }) @@ -412,18 +413,27 @@ describe('navigationBar', function () { yield this.app.client.waitUntil(function () { return this.getValue(urlInput).then((val) => val === '') }) + + yield this.app.client + .addSite({ location: 'https://brave.com', title: 'Brave' }) + // now type something - yield this.app.client.keys('a') + yield this.app.client + .setValue(urlInput, 'b') + .waitForExist(urlBarSuggestions + ' li') }) - it('sets the value to "a"', function * () { + it('sets the value to "b"', function * () { yield this.app.client.waitUntil(function () { - return this.getValue(urlInput).then((val) => val === 'a') + return this.getValue(urlInput).then((val) => val === 'brave.com') }) }) it('clears the selected text', function * () { - yield selectsText(this.app.client, '') + // Since now the first letter will trigger the autocomplete + // expect the selected text to be part of the first suggestion + // in the list + yield selectsText(this.app.client, 'rave.com') }) describe('shortcut-focus-url', function () { @@ -437,7 +447,9 @@ describe('navigationBar', function () { }) it('selects the text', function * () { - yield selectsText(this.app.client, 'a') + // Since now the first letter will trigger the autocomplete + // expect the selected text to be the first suggestion in the list + yield selectsText(this.app.client, 'brave.com') }) it('has the file icon', function * () { @@ -625,7 +637,9 @@ describe('navigationBar', function () { .waitUntil(function () { return this.getValue(urlInput).then((val) => val === 'a') }) - yield selectsText(this.app.client, '') + .waitUntil(function () { + return this.getSelectedText().then(function (value) { return value === '' }) + }) }) }) @@ -654,10 +668,14 @@ describe('navigationBar', function () { yield this.app.client.waitUntil(function () { return this.getValue(urlInput).then((val) => val === '') }) + + yield this.app.client + .addSite({ location: 'https://brave.com', title: 'Brave' }) + // now type something - yield this.app.client.keys('a') + yield this.app.client.keys('b') yield this.app.client.waitUntil(function () { - return this.getValue(urlInput).then((val) => val === 'a') + return this.getValue(urlInput).then((val) => val === 'b') }) yield blur(this.app.client) yield this.app.client @@ -670,7 +688,7 @@ describe('navigationBar', function () { }) it('selects the text', function * () { - yield selectsText(this.app.client, 'a') + yield selectsText(this.app.client, 'brave.com') }) }) diff --git a/test/components/urlBarSuggestionsTest.js b/test/components/urlBarSuggestionsTest.js index b14dda91953..106505d42be 100644 --- a/test/components/urlBarSuggestionsTest.js +++ b/test/components/urlBarSuggestionsTest.js @@ -37,6 +37,16 @@ describe('urlbarSuggestions', function () { }) }) + it('show suggestion when single letter is typed in', function * () { + yield this.app.client.ipcSend('shortcut-focus-url') + .waitForElementFocus(urlInput) + .setValue(urlInput, 'a') + .waitUntil(function () { + return this.getValue(urlInput).then((val) => val === 'a') + }) + .waitForExist(urlBarSuggestions) + }) + it('deactivates suggestions on escape', function * () { yield this.app.client .setValue(urlInput, 'Page 1')