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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct OnboardingScreenshot: View {
let content: Content
let accessibilityLabel: String

@Environment(\.colorScheme) private var colorScheme
@Environment(\.locale) private var locale
@State private var screenshot: UIImage?

Expand Down Expand Up @@ -47,7 +48,8 @@ struct OnboardingScreenshot: View {
screenshot = nil
let loadedScreenshot = await Self.image(
content: content,
language: language
language: language,
appearance: appearance
)
guard !Task.isCancelled else { return }
screenshot = loadedScreenshot
Expand All @@ -58,16 +60,29 @@ struct OnboardingScreenshot: View {
OnboardingScreenshotLanguage.resolve(locale: locale)
}

private var appearance: OnboardingScreenshotAppearance {
OnboardingScreenshotAppearance.resolve(colorScheme: colorScheme)
}

private var resourceName: String {
Self.resourceName(content: content, language: language)
Self.resourceName(
content: content,
language: language,
appearance: appearance
)
}

@MainActor
static func image(
content: Content,
language: OnboardingScreenshotLanguage
language: OnboardingScreenshotLanguage,
appearance: OnboardingScreenshotAppearance
) async -> UIImage {
let resourceName = resourceName(content: content, language: language)
let resourceName = resourceName(
content: content,
language: language,
appearance: appearance
)
let cacheKey = resourceName as NSString
if let cachedImage = screenshotCache.object(forKey: cacheKey) {
return cachedImage
Expand Down Expand Up @@ -103,14 +118,23 @@ struct OnboardingScreenshot: View {
@MainActor private static let screenshotCache: NSCache<NSString, UIImage> = {
let cache = NSCache<NSString, UIImage>()
cache.countLimit = Content.allCases.count
* OnboardingScreenshotLanguage.allCases.count
* OnboardingScreenshotAppearance.allCases.count
return cache
}()

private static func resourceName(
content: Content,
language: OnboardingScreenshotLanguage
language: OnboardingScreenshotLanguage,
appearance: OnboardingScreenshotAppearance
) -> String {
"Onboarding-\(content.rawValue)-\(language.rawValue)"
let baseName = "Onboarding-\(content.rawValue)-\(language.rawValue)"
switch appearance {
case .light:
return baseName
case .dark:
return "\(baseName)-dark"
}
}
}

Expand All @@ -135,4 +159,13 @@ enum OnboardingScreenshotLanguage: String, CaseIterable, Equatable, Sendable {
: .english
}
}

enum OnboardingScreenshotAppearance: String, CaseIterable, Equatable, Sendable {
case light
case dark

static func resolve(colorScheme: ColorScheme) -> Self {
colorScheme == .dark ? .dark : .light
}
}
#endif
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.
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
@@ -1,6 +1,7 @@
#if os(iOS)
@testable import CmuxMobileShellUI
import Foundation
import SwiftUI
import Testing
import UIKit

Expand Down Expand Up @@ -91,16 +92,24 @@ import UIKit
@Test @MainActor func everyLocalizedOnboardingScreenshotLoads() async {
for content in OnboardingScreenshot.Content.allCases {
for language in OnboardingScreenshotLanguage.allCases {
let image = await OnboardingScreenshot.image(
content: content,
language: language
)
#expect(image.size.width > 0)
#expect(image.size.height > 0)
for appearance in OnboardingScreenshotAppearance.allCases {
let image = await OnboardingScreenshot.image(
content: content,
language: language,
appearance: appearance
)
#expect(image.size.width > 0)
#expect(image.size.height > 0)
}
}
}
}

@Test func screenshotAppearanceMatchesTheSystemColorScheme() {
#expect(OnboardingScreenshotAppearance.resolve(colorScheme: .light) == .light)
#expect(OnboardingScreenshotAppearance.resolve(colorScheme: .dark) == .dark)
}

@Test @MainActor func onboardingCopyUsesNativeLineBalancing() {
let label = OnboardingBalancedText.makeLabel()
label.font = .preferredFont(forTextStyle: .body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ import Testing
let pendingSwitchTask = view.handleMacTitlePickerSelection(.machine("mac-b"))
await waitForSwitchStart()

#expect(view.macTitlePickerSelection.wrappedValue == .machine("mac-b"))
view.macTitlePickerSelection.wrappedValue = .all
#expect(view.currentMacTitlePickerSelection == .machine("mac-b"))
view.handleMacTitlePickerSelection(.all)
await waitForCancelStart()

#expect(requestedSwitches == ["mac-b"])
Expand Down