Skip to content

Commit

Permalink
Update Android Components and fix breaking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalmeida committed Aug 7, 2020
1 parent bee2ae6 commit 9568bda
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ class ToolbarView(
/* Only set the search terms if pasted text is null so that the search term doesn't
overwrite pastedText when view enters `editMode` */
if (searchState.pastedText.isNullOrEmpty()) {
view.setSearchTerms(searchState.searchTerms)
// If we're in edit mode, setting the search term will update the toolbar,
// so we make sure we have the correct term/query to show.
val termOrQuery = if (searchState.searchTerms.isNotEmpty()) {
searchState.searchTerms
} else {
searchState.query
}
view.setSearchTerms(termOrQuery)
}

// We must trigger an onTextChanged so when search terms are set when transitioning to `editMode`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,26 @@ class ToolbarViewTest {
view.update(defaultState)
view.update(defaultState)

verify(exactly = 1) { toolbar.url = any() }
verify(exactly = 1) { toolbar.setSearchTerms(any()) }
verify(exactly = 1) { interactor.onTextChanged(any()) }
// editMode gets called when the view is initialized. So it is called twice in this test
verify(exactly = 2) { toolbar.editMode() }

assertTrue(view.isInitialized)
}

@Test
fun `search term updates the url`() {
val view = buildToolbarView(false)

view.update(defaultState)
view.update(defaultState)
view.update(defaultState)

// editMode gets called when the view is initialized.
verify(exactly = 2) { toolbar.editMode() }
// search term changes update the url and invoke the interactor.
verify(exactly = 2) { toolbar.url = any() }
verify(exactly = 2) { interactor.onTextChanged(any()) }
}

@Test
fun `URL gets set to the states query`() {
val toolbarView = buildToolbarView(false)
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/AndroidComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

object AndroidComponents {
const val VERSION = "54.0.20200806130142"
const val VERSION = "54.0.20200807130552"
}

0 comments on commit 9568bda

Please sign in to comment.