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
27 changes: 27 additions & 0 deletions App Store Tests/ValidationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@ import XCTest
@testable import Shipyard

final class ValidationTests: XCTestCase {
func testAppInfoLocaleSelectionChoosesValidLocaleAfterDeletion() {
XCTAssertEqual(
ShipyardAppInfoView.localeAfterDeleting(
"ca",
availableLocales: ["ca", "en-US"],
primaryLocale: "en-US"),
"en-US")
XCTAssertEqual(
ShipyardAppInfoView.localeAfterDeleting(
"ca",
availableLocales: ["ca", "de-DE", "fr-FR"],
primaryLocale: "en-US"),
"de-DE")
XCTAssertEqual(
ShipyardAppInfoView.localeAfterDeleting(
"ca",
availableLocales: ["ca"],
primaryLocale: "en-US"),
"en-US")
XCTAssertEqual(
ShipyardAppInfoView.localeAfterDeleting(
"ca",
availableLocales: ["ca"],
primaryLocale: nil),
BetaLocalizationLocales.defaultLocale)
}

@MainActor
func testBuildsQueryLoadsTenBuildsForSelectedVersion() {
let query = DetailViewModel.buildsQueryParams(
Expand Down
4 changes: 2 additions & 2 deletions App Store.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"App Store/Preview Content\"";
DEVELOPMENT_TEAM = SQ2XJ67YNR;
Expand Down Expand Up @@ -1064,7 +1064,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"App Store/Preview Content\"";
DEVELOPMENT_TEAM = SQ2XJ67YNR;
Expand Down
33 changes: 28 additions & 5 deletions Shipyard/ShipyardAppInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -889,15 +889,38 @@ struct ShipyardAppInfoView: View {

private func removeLocale() async {
guard let record = versionLocalization else { return }
if let message = await detailVM.deleteVersionLocalization(id: record.id, locale: locale) {
let removedLocale = locale
if let message = await detailVM.deleteVersionLocalization(id: record.id, locale: removedLocale) {
saveError = message
toastCenter.show("Couldn't remove localization", detail: message, variant: .error)
return
}
toastCenter.show("Localization removed", detail: BetaLocalizationLocales.displayName(for: locale), variant: .success)
for field in Field.allCases { drafts.removeValue(forKey: field.rawValue) }
draftSignature = ""
syncDrafts()
if locale == removedLocale {
switchToLocale(Self.localeAfterDeleting(
removedLocale,
availableLocales: locales,
primaryLocale: app.primaryLocale))
}
toastCenter.show(
"Localization removed",
detail: BetaLocalizationLocales.displayName(for: removedLocale),
variant: .success)
}

/// Keeps the picker on a real record after deleting its current locale.
/// Prefer Apple's primary locale, then the first remaining locale. When
/// the version has no localizations left, keep the primary/default code
/// selected so the empty editor still has a useful locale context.
static func localeAfterDeleting(
_ removedLocale: String,
availableLocales: [String],
primaryLocale: String?
) -> String {
let remaining = availableLocales.filter { $0 != removedLocale }
if let primaryLocale, remaining.contains(primaryLocale) {
return primaryLocale
}
return remaining.first ?? primaryLocale ?? BetaLocalizationLocales.defaultLocale
}

private func save() async {
Expand Down
Loading