Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Start suggestions after first character not second fixes #3235
Browse files Browse the repository at this point in the history
  • Loading branch information
Radoslav Vitanov committed Aug 29, 2016
1 parent ce762e6 commit 4159e58
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
5 changes: 5 additions & 0 deletions js/components/urlBarSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
36 changes: 27 additions & 9 deletions test/components/navigationBarTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down Expand Up @@ -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 () {
Expand All @@ -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 * () {
Expand Down Expand Up @@ -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 === '' })
})
})
})

Expand Down Expand Up @@ -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
Expand All @@ -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')
})
})

Expand Down
10 changes: 10 additions & 0 deletions test/components/urlBarSuggestionsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 4159e58

Please sign in to comment.