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

Start suggestions after first character not second fixes #3235 #3238

Merged
merged 4 commits into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions js/components/urlBarSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ class UrlBarSuggestions extends ImmutableComponent {
this.updateSuggestions(parseInt(e.target.dataset.index, 10))
}

componentDidMount () {
this.suggestionList = this.getNewSuggestionList()
this.searchXHR()
}

componentWillUpdate (nextProps) {
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 @@ -74,6 +74,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 @@ -713,18 +714,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 @@ -738,7 +748,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 @@ -932,7 +944,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 @@ -974,10 +988,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 @@ -990,7 +1008,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 @@ -35,6 +35,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