Skip to content
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
2 changes: 1 addition & 1 deletion EssentialApp/EssentialAppTests/FeedAcceptanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FeedAcceptanceTests: XCTestCase {
store: InMemoryFeedStore = .empty
) -> ListViewController {
let sut = SceneDelegate(httpClient: httpClient, store: store)
sut.window = UIWindow()
sut.window = UIWindow(frame: CGRect(x: 0, y: 0, width: 390, height: 1))
sut.configureWindow()

let nav = sut.window?.rootViewController as? UINavigationController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ extension FeedImageCellController: UITableViewDataSource, UITableViewDelegate, U

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell = tableView.dequeueReusableCell()
cell?.onReuse = { [weak self] in
self?.releaseCellForReuse()
}
cell?.locationContainer.isHidden = !viewModel.hasLocation
cell?.locationLabel.text = viewModel.location
cell?.descriptionLabel.text = viewModel.description
cell?.feedImageView.image = nil
cell?.onRetry = { [weak self] in
self?.delegate.didRequestImage()
}
cell?.onReuse = { [weak self] in
self?.releaseCellForReuse()
}
delegate.didRequestImage()
return cell!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public final class ListViewController: UITableViewController, UITableViewDataSou
super.viewDidLoad()

configureTableView()
configureTraitCollectionObservers()

// Note: Using `onViewIsAppearing` to defer `beginRefreshing()` until the view is fully visible.
// This ensures the spinner appears correctly, addressing a change in behavior introduced in iOS 17.
Expand All @@ -44,9 +45,11 @@ public final class ListViewController: UITableViewController, UITableViewDataSou
}
}

public override func traitCollectionDidChange(_ previous: UITraitCollection?) {
if previous?.preferredContentSizeCategory != traitCollection.preferredContentSizeCategory {
tableView.reloadData()
private func configureTraitCollectionObservers() {
registerForTraitChanges(
[UITraitPreferredContentSizeCategory.self]
) { (self: Self, previous: UITraitCollection) in
self.tableView.reloadData()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public final class ErrorView: UIButton {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.center

var attributes = AttributeContainer()
attributes.paragraphStyle = paragraphStyle
attributes.font = UIFont.preferredFont(forTextStyle: .body)
return attributes
return AttributeContainer([
.paragraphStyle: paragraphStyle,
.font: UIFont.preferredFont(forTextStyle: .body)
])
}

private func configure() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ class FeedSnapshotTests: XCTestCase {

sut.display(feedWithContent())

assert(snapshot: sut.snapshot(for: .iPhone8(style: .light)), named: "FEED_WITH_CONTENT_light")
assert(snapshot: sut.snapshot(for: .iPhone8(style: .dark)), named: "FEED_WITH_CONTENT_dark")
assert(snapshot: sut.snapshot(for: .iPhone8(style: .light, contentSize: .extraExtraExtraLarge)), named: "FEED_WITH_CONTENT_light_extraExtraExtraLarge")
assert(snapshot: sut.snapshot(for: .iPhone(style: .light)), named: "FEED_WITH_CONTENT_light")
assert(snapshot: sut.snapshot(for: .iPhone(style: .dark)), named: "FEED_WITH_CONTENT_dark")
assert(snapshot: sut.snapshot(for: .iPhone(style: .light, contentSize: .extraExtraExtraLarge)), named: "FEED_WITH_CONTENT_light_extraExtraExtraLarge")
}

func test_feedWithFailedImageLoading() {
let sut = makeSUT()

sut.display(feedWithFailedImageLoading())

assert(snapshot: sut.snapshot(for: .iPhone8(style: .light)), named: "FEED_WITH_FAILED_IMAGE_LOADING_light")
assert(snapshot: sut.snapshot(for: .iPhone8(style: .dark)), named: "FEED_WITH_FAILED_IMAGE_LOADING_dark")
assert(snapshot: sut.snapshot(for: .iPhone(style: .light)), named: "FEED_WITH_FAILED_IMAGE_LOADING_light")
assert(snapshot: sut.snapshot(for: .iPhone(style: .dark)), named: "FEED_WITH_FAILED_IMAGE_LOADING_dark")
}

// MARK: - Helpers
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,29 @@ struct SnapshotConfiguration {
let layoutMargins: UIEdgeInsets
let traitCollection: UITraitCollection

static func iPhone8(style: UIUserInterfaceStyle, contentSize: UIContentSizeCategory = .medium) -> SnapshotConfiguration {
static func iPhone(style: UIUserInterfaceStyle, contentSize: UIContentSizeCategory = .medium) -> SnapshotConfiguration {
return SnapshotConfiguration(
size: CGSize(width: 375, height: 667),
safeAreaInsets: UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0),
layoutMargins: UIEdgeInsets(top: 20, left: 16, bottom: 0, right: 16),
traitCollection: UITraitCollection {
$0.forceTouchCapability = .available
$0.layoutDirection = .leftToRight
$0.preferredContentSizeCategory = contentSize
$0.userInterfaceIdiom = .phone
$0.horizontalSizeClass = .compact
$0.verticalSizeClass = .regular
$0.displayScale = 2
$0.displayGamut = .P3
$0.userInterfaceStyle = style
}
size: CGSize(width: 390, height: 844),
safeAreaInsets: UIEdgeInsets(top: 47, left: 0, bottom: 34, right: 0),
layoutMargins: UIEdgeInsets(top: 55, left: 8, bottom: 42, right: 8),
traitCollection: UITraitCollection(mutations: { traits in
traits.forceTouchCapability = .unavailable
traits.layoutDirection = .leftToRight
traits.preferredContentSizeCategory = contentSize
traits.userInterfaceIdiom = .phone
traits.horizontalSizeClass = .compact
traits.verticalSizeClass = .regular
traits.displayScale = 3
traits.accessibilityContrast = .normal
traits.displayGamut = .P3
traits.userInterfaceStyle = style
})
)
}
}

private final class SnapshotWindow: UIWindow {
private var configuration: SnapshotConfiguration = .iPhone8(style: .light)
private var configuration: SnapshotConfiguration = .iPhone(style: .light)

convenience init(configuration: SnapshotConfiguration, root: UIViewController) {
self.init(frame: CGRect(origin: .zero, size: configuration.size))
Expand All @@ -50,21 +51,11 @@ private final class SnapshotWindow: UIWindow {
}

override var safeAreaInsets: UIEdgeInsets {
return configuration.safeAreaInsets
configuration.safeAreaInsets
}

override var traitCollection: UITraitCollection {
return super.traitCollection.modifyingTraits { traits in
traits.forceTouchCapability = configuration.traitCollection.forceTouchCapability
traits.layoutDirection = configuration.traitCollection.layoutDirection
traits.preferredContentSizeCategory = configuration.traitCollection.preferredContentSizeCategory
traits.userInterfaceIdiom = configuration.traitCollection.userInterfaceIdiom
traits.horizontalSizeClass = configuration.traitCollection.horizontalSizeClass
traits.verticalSizeClass = configuration.traitCollection.verticalSizeClass
traits.displayScale = configuration.traitCollection.displayScale
traits.displayGamut = configuration.traitCollection.displayGamut
traits.userInterfaceStyle = configuration.traitCollection.userInterfaceStyle
}
configuration.traitCollection
}

func snapshot() -> UIImage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class ImageCommentsSnapshotTests: XCTestCase {

sut.display(comments())

assert(snapshot: sut.snapshot(for: .iPhone8(style: .light)), named: "IMAGE_COMMENTS_light")
assert(snapshot: sut.snapshot(for: .iPhone8(style: .dark)), named: "IMAGE_COMMENTS_dark")
assert(snapshot: sut.snapshot(for: .iPhone8(style: .light, contentSize: .extraExtraExtraLarge)), named: "IMAGE_COMMENTS_light_extraExtraExtraLarge")
assert(snapshot: sut.snapshot(for: .iPhone(style: .light)), named: "IMAGE_COMMENTS_light")
assert(snapshot: sut.snapshot(for: .iPhone(style: .dark)), named: "IMAGE_COMMENTS_dark")
assert(snapshot: sut.snapshot(for: .iPhone(style: .light, contentSize: .extraExtraExtraLarge)), named: "IMAGE_COMMENTS_light_extraExtraExtraLarge")
}

// MARK: - Helpers
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ class ListSnapshotTests: XCTestCase {

sut.display(emptyList())

assert(snapshot: sut.snapshot(for: .iPhone8(style: .light)), named: "EMPTY_LIST_light")
assert(snapshot: sut.snapshot(for: .iPhone8(style: .dark)), named: "EMPTY_LIST_dark")
assert(snapshot: sut.snapshot(for: .iPhone(style: .light)), named: "EMPTY_LIST_light")
assert(snapshot: sut.snapshot(for: .iPhone(style: .dark)), named: "EMPTY_LIST_dark")
}

func test_listWithErrorMessage() {
let sut = makeSUT()

sut.display(.error(message: "This is a\nmulti-line\nerror message"))

assert(snapshot: sut.snapshot(for: .iPhone8(style: .light)), named: "LIST_WITH_ERROR_MESSAGE_light")
assert(snapshot: sut.snapshot(for: .iPhone8(style: .dark)), named: "LIST_WITH_ERROR_MESSAGE_dark")
assert(snapshot: sut.snapshot(for: .iPhone8(style: .light, contentSize: .extraExtraExtraLarge)), named: "LIST_WITH_ERROR_MESSAGE_light_extraExtraExtraLarge")
assert(snapshot: sut.snapshot(for: .iPhone(style: .light)), named: "LIST_WITH_ERROR_MESSAGE_light")
assert(snapshot: sut.snapshot(for: .iPhone(style: .dark)), named: "LIST_WITH_ERROR_MESSAGE_dark")
assert(snapshot: sut.snapshot(for: .iPhone(style: .light, contentSize: .extraExtraExtraLarge)), named: "LIST_WITH_ERROR_MESSAGE_light_extraExtraExtraLarge")
}

// MARK: - Helpers
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.