Skip to content

Commit

Permalink
Add FXIOS-3736 test cases for search view model (#20676)
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharC95 authored Jun 14, 2024
1 parent 18eb1c8 commit adb9f2d
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,62 @@ final class SearchViewModelTests: XCTestCase {
XCTAssertEqual(mockDelegate.didReloadTableViewCount, 1)
}

func testFirefoxSuggestionReturnsSponsored() async {
FxNimbus.shared.features.firefoxSuggestFeature.with(initializer: { _, _ in
FirefoxSuggestFeature(availableSuggestionsTypes:
[.amp: false, .ampMobile: true, .wikipedia: true])
})

engines.shouldShowFirefoxSuggestions = false
engines.shouldShowSponsoredSuggestions = true
let subject = createSubject()
await subject.loadFirefoxSuggestions()?.value

XCTAssertEqual(subject.firefoxSuggestions[0].title, "Mozilla")
XCTAssertEqual(subject.firefoxSuggestions.count, 1)
}

func testFirefoxSuggestionReturnsNonSponsored() async {
FxNimbus.shared.features.firefoxSuggestFeature.with(initializer: { _, _ in
FirefoxSuggestFeature(availableSuggestionsTypes:
[.amp: false, .ampMobile: true, .wikipedia: true])
})

engines.shouldShowFirefoxSuggestions = true
engines.shouldShowSponsoredSuggestions = false
let subject = createSubject()
await subject.loadFirefoxSuggestions()?.value

XCTAssertEqual(subject.firefoxSuggestions[0].title, "California")
XCTAssertEqual(subject.firefoxSuggestions.count, 1)
}

func testQuickSearchEnginesWithSearchSuggestionsEnabled() {
let subject = createSubject()
subject.searchEngines = engines
let quickSearchEngines = subject.quickSearchEngines

let expectedEngineNames = ["BTester", "CTester", "DTester", "ETester", "FTester"]

XCTAssertEqual(subject.searchEngines?.defaultEngine?.shortName, "ATester")
XCTAssertEqual(quickSearchEngines.map { $0.shortName }, expectedEngineNames)
XCTAssertEqual(quickSearchEngines.count, 5)
}

func testQuickSearchEnginesWithSearchSuggestionsDisabled() {
engines.shouldShowSearchSuggestions = false
let subject = createSubject()
subject.searchEngines = engines
let quickSearchEngines = subject.quickSearchEngines

let expectedEngineNames = ["ATester", "BTester", "CTester", "DTester", "ETester", "FTester"]

XCTAssertEqual(quickSearchEngines.first?.shortName, "ATester")
XCTAssertEqual(subject.searchEngines?.defaultEngine?.shortName, "ATester")
XCTAssertEqual(quickSearchEngines.map { $0.shortName }, expectedEngineNames)
XCTAssertEqual(quickSearchEngines.count, 6)
}

private func createSubject(
isPrivate: Bool = false,
isBottomSearchBar: Bool = false,
Expand Down

0 comments on commit adb9f2d

Please sign in to comment.