Skip to content

Commit

Permalink
Fix hugging priority for searchbar (#1504)
Browse files Browse the repository at this point in the history
# Fixed
<fixed>
In landscape mode, the search bar no longer expands its height on the
screen and no longer obstructs other visual elements on the screen (for
example, the issuer list screen).
</fixed>

## Summary
- Fixes a UI issue where the SearchBar on IssuerList and other search
screens would expand its height in landscape and thus make it hard to
use the screen
- Refactored UI Tests for IssuerListComponent
  • Loading branch information
goergisn authored Jan 15, 2024
2 parents a7902c4 + ea45d7e commit b0156d8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2023 Adyen N.V.
// Copyright (c) 2024 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//
Expand Down Expand Up @@ -82,6 +82,7 @@ public class SearchViewController: UIViewController, AdyenObserver {
resultsListViewController.view.translatesAutoresizingMaskIntoConstraints = false

searchBar.setContentCompressionResistancePriority(.required, for: .vertical)
searchBar.setContentHuggingPriority(.required, for: .vertical)
view.addSubview(searchBar)

setupConstraints()
Expand Down
2 changes: 1 addition & 1 deletion Demo/Configuration.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2023 Adyen N.V.
// Copyright (c) 2024 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//
Expand Down
68 changes: 21 additions & 47 deletions UITests/Components/IssuerList/IssuerListComponentUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,80 +13,54 @@ import XCTest

final class IssuerListComponentUITests: XCTestCase {

private var context: AdyenContext!
private var paymentMethod: IssuerListPaymentMethod!
private var sut: IssuerListComponent!
private var searchViewController: SearchViewController!
private var listViewController: ListViewController!
private var context: AdyenContext { Dummy.context }
private var paymentMethod: IssuerListPaymentMethod { try! AdyenCoder.decode(issuerListDictionary) as IssuerListPaymentMethod }

override func setUpWithError() throws {
try super.setUpWithError()

initializeComponent()
}

private func initializeComponent() {
context = Dummy.context
paymentMethod = try! AdyenCoder.decode(issuerListDictionary) as IssuerListPaymentMethod
sut = IssuerListComponent(paymentMethod: paymentMethod, context: context)
searchViewController = sut.viewController as? SearchViewController
listViewController = searchViewController.resultsListViewController
}

override func tearDownWithError() throws {
context = nil
paymentMethod = nil
sut = nil
try super.tearDownWithError()
}

func testStartStopLoading() {
XCTAssertNotNil(listViewController)
func testStartStopLoading() throws {
let sut = IssuerListComponent(paymentMethod: paymentMethod, context: context)
let searchViewController = try XCTUnwrap(sut.viewController as? SearchViewController)
let listViewController = searchViewController.resultsListViewController

setupRootViewController(sut.viewController)

let items = listViewController!.sections[0].items
let item = try XCTUnwrap(listViewController.sections.first?.items.first)

let index = 0
let item = items[index]
var cell = listViewController!.tableView.visibleCells[index] as! ListCell
var cell = try XCTUnwrap(Self.getCell(for: item, tableView: listViewController.tableView))
XCTAssertFalse(cell.showsActivityIndicator)
XCTAssertTrue(listViewController.tableView.isUserInteractionEnabled)
assertViewControllerImage(matching: sut.viewController, named: "initial_state")

// start loading
item.startLoading()
cell = getCell(for: item, tableView: listViewController!.tableView)!
cell = try XCTUnwrap(Self.getCell(for: item, tableView: listViewController.tableView))
XCTAssertTrue(cell.showsActivityIndicator)
XCTAssertFalse(listViewController!.tableView.isUserInteractionEnabled)
XCTAssertFalse(listViewController.tableView.isUserInteractionEnabled)
assertViewControllerImage(matching: sut.viewController, named: "loading_first_cell")

// stop loading
sut.stopLoadingIfNeeded()
cell = getCell(for: item, tableView: listViewController!.tableView)!
cell = try XCTUnwrap(Self.getCell(for: item, tableView: listViewController.tableView))
XCTAssertFalse(cell.showsActivityIndicator)
XCTAssertTrue(listViewController!.tableView.isUserInteractionEnabled)
XCTAssertTrue(listViewController.tableView.isUserInteractionEnabled)
assertViewControllerImage(matching: sut.viewController, named: "stopped_loading")

// start loading again
item.startLoading()
cell = getCell(for: item, tableView: listViewController!.tableView)!
XCTAssertFalse(listViewController!.tableView.isUserInteractionEnabled)
cell = try XCTUnwrap(Self.getCell(for: item, tableView: listViewController.tableView))
XCTAssertFalse(listViewController.tableView.isUserInteractionEnabled)
XCTAssertTrue(cell.showsActivityIndicator)

// stop loading on item -> should stop loading on list
item.stopLoading()
cell = getCell(for: item, tableView: listViewController!.tableView)!
XCTAssertTrue(listViewController!.tableView.isUserInteractionEnabled)
cell = try XCTUnwrap(Self.getCell(for: item, tableView: listViewController.tableView))
XCTAssertTrue(listViewController.tableView.isUserInteractionEnabled)
XCTAssertFalse(cell.showsActivityIndicator)

}

private func getCell(for item: ListItem, tableView: UITableView) -> ListCell? {
for case let cell as ListCell in tableView.visibleCells where cell.item == item {
return cell
}

return nil
private static func getCell(for item: ListItem, tableView: UITableView) -> ListCell? {
tableView.visibleCells.first { cell in
(cell as? ListCell).map { $0.item == item } ?? false
} as? ListCell
}

}

0 comments on commit b0156d8

Please sign in to comment.