mirror of
https://github.com/yattee/yattee.git
synced 2026-10-23 21:22:53 +00:00
Standing the feed error down under the context banner was aimed at one sentence and hit every one. The fallback to local reads asks for a Yattee Server nobody configured, and that question the banner already answers — but a local refresh that failed on the way out answers nothing, and it was being swallowed too. With the banner up, an offline refresh left the last feed on screen with no explanation and no retry: the state said error, the view said nothing. The decision now names the errors the banner covers. `yatteeServerRequired` and `notAuthenticated` are the account the banner is already talking about and stand down; a `networkError` is news the banner does not carry and keeps its own message and its retry button. It lives on `FeedLoadState` as `displayedError(contextBannerVisible:)` so the rule is one function rather than a guard in a view property, and so it can be tested.
74 lines
2.2 KiB
Swift
74 lines
2.2 KiB
Swift
//
|
|
// SubscriptionFeedErrorTests.swift
|
|
// YatteeTests
|
|
//
|
|
// Tests for which feed errors the context banner speaks for.
|
|
//
|
|
|
|
import Testing
|
|
import Foundation
|
|
@testable import Yattee
|
|
|
|
@Suite("Subscription Feed Error Display")
|
|
struct SubscriptionFeedErrorTests {
|
|
|
|
// MARK: - Without a banner
|
|
|
|
@Test("Every feed error shows when no banner is up")
|
|
func everyErrorShowsWithoutBanner() {
|
|
let errors: [FeedLoadState.FeedLoadError] = [
|
|
.yatteeServerRequired,
|
|
.notAuthenticated,
|
|
.networkError("The Internet connection appears to be offline.")
|
|
]
|
|
|
|
for error in errors {
|
|
#expect(FeedLoadState.error(error).displayedError(contextBannerVisible: false) == error)
|
|
}
|
|
}
|
|
|
|
// MARK: - Under the banner
|
|
|
|
@Test("The Yattee Server the fallback asks for stands down under the banner")
|
|
func yatteeServerRequiredStandsDownUnderBanner() {
|
|
let state = FeedLoadState.error(.yatteeServerRequired)
|
|
|
|
#expect(state.displayedError(contextBannerVisible: true) == nil)
|
|
}
|
|
|
|
@Test("An account error stands down under the banner")
|
|
func notAuthenticatedStandsDownUnderBanner() {
|
|
let state = FeedLoadState.error(.notAuthenticated)
|
|
|
|
#expect(state.displayedError(contextBannerVisible: true) == nil)
|
|
}
|
|
|
|
@Test("A failed refresh keeps its error under the banner")
|
|
func networkErrorSurvivesTheBanner() {
|
|
let state = FeedLoadState.error(.networkError("The Internet connection appears to be offline."))
|
|
|
|
#expect(
|
|
state.displayedError(contextBannerVisible: true)
|
|
== .networkError("The Internet connection appears to be offline.")
|
|
)
|
|
}
|
|
|
|
// MARK: - Other states
|
|
|
|
@Test("States that are not errors have nothing to show")
|
|
func nonErrorStatesShowNothing() {
|
|
let states: [FeedLoadState] = [
|
|
.idle,
|
|
.loading,
|
|
.loadingMore,
|
|
.ready,
|
|
.partiallyLoaded(readyCount: 1, pendingCount: 2, errorCount: 0)
|
|
]
|
|
|
|
for state in states {
|
|
#expect(state.displayedError(contextBannerVisible: false) == nil)
|
|
#expect(state.displayedError(contextBannerVisible: true) == nil)
|
|
}
|
|
}
|
|
}
|