Only record query breadcrumbs when the search is submitted

Queries were previously stored whenever a result was selected, which
meant half-typed queries ended up in the history. Now a query is only
recorded when the user submits the search field, while selecting a
result only records the room.
This commit is contained in:
Stefan Ceriu
2026-09-29 14:53:02 +03:00
parent bc018251c7
commit 313365ad83
4 changed files with 22 additions and 12 deletions
@@ -127,16 +127,26 @@ struct SearchScreenViewModelTests {
@Test
func selectionRecordsBreadcrumbs() {
// Typing alone doesn't record the query, only submitting it does.
context.searchQuery = "Second"
context.send(viewAction: .selectRoom(roomID: "2"))
#expect(userSettings.searchBreadcrumbs == [.room(roomID: "2"), .query("Second")])
#expect(userSettings.searchBreadcrumbs == [.room(roomID: "2")])
context.send(viewAction: .submitQuery)
#expect(userSettings.searchBreadcrumbs == [.query("Second"), .room(roomID: "2")])
// Selecting the same room again from the empty state only bumps it back to the top.
context.searchQuery = ""
context.send(viewAction: .selectRoom(roomID: "2"))
#expect(userSettings.searchBreadcrumbs == [.room(roomID: "2"), .query("Second")])
// Submitting an empty query records nothing.
context.send(viewAction: .submitQuery)
#expect(userSettings.searchBreadcrumbs == [.room(roomID: "2"), .query("Second")])
}
@Test