Skip to content

Commit

Permalink
chore: ios: Add unit tests for network selection settings and details…
Browse files Browse the repository at this point in the history
… action modal
  • Loading branch information
krodak committed Jan 11, 2024
1 parent 8b6bc94 commit 3935a75
Show file tree
Hide file tree
Showing 11 changed files with 428 additions and 40 deletions.
18 changes: 17 additions & 1 deletion ios/PolkadotVault.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@
6D8045D928D0761E00237F8C /* QRCodeAddressFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D8045D828D0761E00237F8C /* QRCodeAddressFooterView.swift */; };
6D8045DC28D0840F00237F8C /* MKeyDetails+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D8045DB28D0840F00237F8C /* MKeyDetails+Helpers.swift */; };
6D8045DE28D087D400237F8C /* QRCodeRootFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D8045DD28D087D400237F8C /* QRCodeRootFooterView.swift */; };
6D80EB4B2B4E7034009C544B /* NetworkSettingDetailsActionModalViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D80EB4A2B4E7034009C544B /* NetworkSettingDetailsActionModalViewModelTests.swift */; };
6D80EB522B4EB0B8009C544B /* MSufficientCryptoReady+Generate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D80EB512B4EB0B8009C544B /* MSufficientCryptoReady+Generate.swift */; };
6D80EB542B4EB0C8009C544B /* MAddressCard+Generate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D80EB532B4EB0C8009C544B /* MAddressCard+Generate.swift */; };
6D80EB492B4CF582009C544B /* BananaSplitService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D80EB482B4CF582009C544B /* BananaSplitService.swift */; };
6D84442428D3424F0072FBAC /* HiddenScrollContainerModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D84442328D3424F0072FBAC /* HiddenScrollContainerModifier.swift */; };
6D850BDE292F7B4D00BA9017 /* EnterPasswordModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D850BDD292F7B4D00BA9017 /* EnterPasswordModal.swift */; };
Expand Down Expand Up @@ -225,6 +228,7 @@
6DAFCB042B0AEF6800DDD165 /* PasswordProtectionStatePublisherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DAFCB032B0AEF6800DDD165 /* PasswordProtectionStatePublisherTests.swift */; };
6DB2E7C12B4BBAF7002387DE /* SettingsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB2E7C02B4BBAF7002387DE /* SettingsViewModelTests.swift */; };
6DB2E7C52B4BBC24002387DE /* BackupSelectKeyViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB2E7C42B4BBC24002387DE /* BackupSelectKeyViewModelTests.swift */; };
6DB2E7C82B4BBEB0002387DE /* NetworkSelectionSettingsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB2E7C72B4BBEB0002387DE /* NetworkSelectionSettingsViewModelTests.swift */; };
6DB2E7CA2B4BBF6E002387DE /* MmNetwork+Generate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB2E7C92B4BBF6E002387DE /* MmNetwork+Generate.swift */; };
6DB2E7CC2B4BBF78002387DE /* MNetworkDetails+Generate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB2E7CB2B4BBF78002387DE /* MNetworkDetails+Generate.swift */; };
6DB39AA42A4579E0004B8FAA /* AddDerivedKeysView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB39AA32A4579E0004B8FAA /* AddDerivedKeysView.swift */; };
Expand Down Expand Up @@ -553,6 +557,9 @@
6D8045D828D0761E00237F8C /* QRCodeAddressFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeAddressFooterView.swift; sourceTree = "<group>"; };
6D8045DB28D0840F00237F8C /* MKeyDetails+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MKeyDetails+Helpers.swift"; sourceTree = "<group>"; };
6D8045DD28D087D400237F8C /* QRCodeRootFooterView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QRCodeRootFooterView.swift; sourceTree = "<group>"; };
6D80EB4A2B4E7034009C544B /* NetworkSettingDetailsActionModalViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkSettingDetailsActionModalViewModelTests.swift; sourceTree = "<group>"; };
6D80EB512B4EB0B8009C544B /* MSufficientCryptoReady+Generate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MSufficientCryptoReady+Generate.swift"; sourceTree = "<group>"; };
6D80EB532B4EB0C8009C544B /* MAddressCard+Generate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MAddressCard+Generate.swift"; sourceTree = "<group>"; };
6D80EB482B4CF582009C544B /* BananaSplitService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BananaSplitService.swift; sourceTree = "<group>"; };
6D84442328D3424F0072FBAC /* HiddenScrollContainerModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HiddenScrollContainerModifier.swift; sourceTree = "<group>"; };
6D850BDD292F7B4D00BA9017 /* EnterPasswordModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnterPasswordModal.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -608,6 +615,7 @@
6DAFCB032B0AEF6800DDD165 /* PasswordProtectionStatePublisherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordProtectionStatePublisherTests.swift; sourceTree = "<group>"; };
6DB2E7C02B4BBAF7002387DE /* SettingsViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewModelTests.swift; sourceTree = "<group>"; };
6DB2E7C42B4BBC24002387DE /* BackupSelectKeyViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackupSelectKeyViewModelTests.swift; sourceTree = "<group>"; };
6DB2E7C72B4BBEB0002387DE /* NetworkSelectionSettingsViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkSelectionSettingsViewModelTests.swift; sourceTree = "<group>"; };
6DB2E7C92B4BBF6E002387DE /* MmNetwork+Generate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MmNetwork+Generate.swift"; sourceTree = "<group>"; };
6DB2E7CB2B4BBF78002387DE /* MNetworkDetails+Generate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MNetworkDetails+Generate.swift"; sourceTree = "<group>"; };
6DB39AA32A4579E0004B8FAA /* AddDerivedKeysView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddDerivedKeysView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1569,6 +1577,8 @@
6D57DC51289D68B800005C63 /* ActionResult+Generate.swift */,
6DB2E7C92B4BBF6E002387DE /* MmNetwork+Generate.swift */,
6DB2E7CB2B4BBF78002387DE /* MNetworkDetails+Generate.swift */,
6D80EB512B4EB0B8009C544B /* MSufficientCryptoReady+Generate.swift */,
6D80EB532B4EB0C8009C544B /* MAddressCard+Generate.swift */,
);
path = "Models+Generate";
sourceTree = "<group>";
Expand Down Expand Up @@ -1728,6 +1738,8 @@
6DB2E7C62B4BBEA0002387DE /* NetworkSelectionSettings */ = {
isa = PBXGroup;
children = (
6DB2E7C72B4BBEB0002387DE /* NetworkSelectionSettingsViewModelTests.swift */,
6D80EB4A2B4E7034009C544B /* NetworkSettingDetailsActionModalViewModelTests.swift */,
);
path = NetworkSelectionSettings;
sourceTree = "<group>";
Expand Down Expand Up @@ -2151,7 +2163,7 @@
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1250;
LastUpgradeCheck = 1500;
LastUpgradeCheck = 1510;
TargetAttributes = {
2DE72BBD26A588C7002BB752 = {
CreatedOnToolsVersion = 12.5.1;
Expand Down Expand Up @@ -2639,13 +2651,15 @@
6DE48E8E2B1F0B96003094D5 /* AutoMockable+B.generated.swift in Sources */,
6DE48E992B1F14A0003094D5 /* QRCodeAddressFooterViewModel+Generate.swift in Sources */,
6DE48E832B1F0B96003094D5 /* AutoMockable+C.generated.swift in Sources */,
6D80EB542B4EB0C8009C544B /* MAddressCard+Generate.swift in Sources */,
6D8AF88228BCC4D100CF0AB2 /* AccessControlProvidingAssemblerTests.swift in Sources */,
6DE48E8D2B1F0B96003094D5 /* AutoMockable+S.generated.swift in Sources */,
6DE48E872B1F0B96003094D5 /* AutoMockable+E.generated.swift in Sources */,
6DE48E8B2B1F0B96003094D5 /* AutoMockable+I.generated.swift in Sources */,
6DE48E8A2B1F0B96003094D5 /* AutoMockable+V.generated.swift in Sources */,
6DB2E7CA2B4BBF6E002387DE /* MmNetwork+Generate.swift in Sources */,
6D686B9C2B45B36A007B7642 /* DevicePasscodeAuthenticatorTests.swift in Sources */,
6D80EB4B2B4E7034009C544B /* NetworkSettingDetailsActionModalViewModelTests.swift in Sources */,
6D57DC54289D6CE900005C63 /* NavigationTests.swift in Sources */,
6DE48E8F2B1F0B96003094D5 /* AutoMockable+Y.generated.swift in Sources */,
6DAFCB022B0AEE4900DDD165 /* ApplicationStatePublisherTests.swift in Sources */,
Expand All @@ -2662,6 +2676,7 @@
6DE48E812B1F0B96003094D5 /* AutoMockable+G.generated.swift in Sources */,
6D57DC52289D68B800005C63 /* ActionResult+Generate.swift in Sources */,
6DAFCAFD2B0AE87300DDD165 /* RuntimePropertiesProviderTests.swift in Sources */,
6DB2E7C82B4BBEB0002387DE /* NetworkSelectionSettingsViewModelTests.swift in Sources */,
6DBD2202289A8E1F005D539B /* ErrorMock.swift in Sources */,
6DC2EDF92B11961800298F00 /* DateFormatterTests.swift in Sources */,
6DDD38B72B1346C8000D2B62 /* KeyDetailsPublicKeyViewModelTests.swift in Sources */,
Expand All @@ -2673,6 +2688,7 @@
6DAFCAF82B0A360600DDD165 /* CameraPermissionHandlerTests.swift in Sources */,
6DE48E952B1F0B96003094D5 /* AutoMockable+Q.generated.swift in Sources */,
6DE48E802B1F0B96003094D5 /* AutoMockable+P.generated.swift in Sources */,
6D80EB522B4EB0B8009C544B /* MSufficientCryptoReady+Generate.swift in Sources */,
6DE48E8C2B1F0B96003094D5 /* AutoMockable+R.generated.swift in Sources */,
6D5801E5289937BA006C41D8 /* ConnectivityMonitoringAssemblerTests.swift in Sources */,
6DE07B102B450EB7001AF54C /* OnboardingMediatorTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,21 @@ struct NetworkSelectionSettings: View {
extension NetworkSelectionSettings {
final class ViewModel: ObservableObject {
private let cancelBag = CancelBag()
private let service: GetManagedNetworksService
private let networkDetailsService: ManageNetworkDetailsService
private let service: GetManagedNetworksServicing
private let networkDetailsService: ManageNetworkDetailsServicing
@Published var networks: [MmNetwork] = []
@Published var selectedDetails: MNetworkDetails!
@Published var selectedDetailsKey: String!
@Published var isPresentingDetails = false
@Published var isShowingQRScanner: Bool = false
var snackbarViewModel: SnackbarViewModel = .init(title: "")
@Published var snackbarViewModel: SnackbarViewModel = .init(title: "")
@Published var isSnackbarPresented: Bool = false
@Published var isPresentingError: Bool = false
@Published var presentableError: ErrorBottomModalViewModel = .alertError(message: "")

init(
service: GetManagedNetworksService = GetManagedNetworksService(),
networkDetailsService: ManageNetworkDetailsService = ManageNetworkDetailsService()
service: GetManagedNetworksServicing = GetManagedNetworksService(),
networkDetailsService: ManageNetworkDetailsServicing = ManageNetworkDetailsService()
) {
self.service = service
self.networkDetailsService = networkDetailsService
Expand Down Expand Up @@ -172,10 +172,12 @@ extension NetworkSelectionSettings {

private extension NetworkSelectionSettings.ViewModel {
func onDetailsDismiss() {
$isPresentingDetails.sink { [weak self] isPresented in
guard let self, !isPresented else { return }
updateNetworks()
}.store(in: cancelBag)
$isPresentingDetails
.dropFirst()
.sink { [weak self] isPresented in
guard let self, !isPresented else { return }
updateNetworks()
}.store(in: cancelBag)
}

func updateNetworks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ struct NetworkSettingsDetails: View {
}
) {
NetworkSettingsDetailsActionModal(
isShowingActionSheet: $viewModel.isShowingActionSheet,
shouldPresentRemoveNetworkConfirmation: $viewModel.shouldPresentRemoveNetworkConfirmation,
shouldSignSpecs: $viewModel.shouldSignSpecs
viewModel: .init(
isPresented: $viewModel.isShowingActionSheet,
shouldPresentRemoveNetworkConfirmation: $viewModel.shouldPresentRemoveNetworkConfirmation,
shouldSignSpecs: $viewModel.shouldSignSpecs
)
)
.clearModalBackground()
}
Expand Down Expand Up @@ -328,7 +330,7 @@ extension NetworkSettingsDetails {

final class ViewModel: ObservableObject {
private let cancelBag = CancelBag()
private let networkDetailsService: ManageNetworkDetailsService
private let networkDetailsService: ManageNetworkDetailsServicing
private var metadataToDelete: MMetadataRecord?
var dismissViewRequest: AnyPublisher<Void, Never> { dismissRequest.eraseToAnyPublisher() }
private let dismissRequest = PassthroughSubject<Void, Never>()
Expand All @@ -345,15 +347,15 @@ extension NetworkSettingsDetails {
@Published var specSignType: SpecSignType!
@Published var isPresentingSignSpecList: Bool = false
@Published var isShowingQRScanner: Bool = false
var snackbarViewModel: SnackbarViewModel = .init(title: "")
@Published var snackbarViewModel: SnackbarViewModel = .init(title: "")
@Published var isSnackbarPresented: Bool = false
@Published var isPresentingError: Bool = false
@Published var presentableError: ErrorBottomModalViewModel = .alertError(message: "")

init(
networkKey: String,
networkDetails: MNetworkDetails,
networkDetailsService: ManageNetworkDetailsService = ManageNetworkDetailsService(),
networkDetailsService: ManageNetworkDetailsServicing = ManageNetworkDetailsService(),
onCompletion: @escaping (OnCompletionAction) -> Void
) {
self.networkKey = networkKey
Expand Down Expand Up @@ -467,10 +469,12 @@ private extension NetworkSettingsDetails.ViewModel {

func listenToNavigationUpdates() {
guard cancelBag.subscriptions.isEmpty else { return }
$isPresentingSignSpecList.sink { [weak self] isPresentingSignSpecList in
guard let self, !isPresentingSignSpecList else { return }
updateView()
}.store(in: cancelBag)
$isPresentingSignSpecList
.dropFirst()
.sink { [weak self] isPresentingSignSpecList in
guard let self, !isPresentingSignSpecList else { return }
updateView()
}.store(in: cancelBag)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,29 @@
import SwiftUI

struct NetworkSettingsDetailsActionModal: View {
@State private var animateBackground: Bool = false
@Binding var isShowingActionSheet: Bool
@Binding var shouldPresentRemoveNetworkConfirmation: Bool
@Binding var shouldSignSpecs: Bool
@StateObject var viewModel: ViewModel

var body: some View {
FullScreenRoundedModal(
backgroundTapAction: { animateDismissal() },
animateBackground: $animateBackground,
backgroundTapAction: { viewModel.dismissActionSheet() },
animateBackground: $viewModel.animateBackground,
content: {
VStack(alignment: .leading, spacing: 0) {
// Sign Specs
ActionSheetButton(
action: { animateDismissal { shouldSignSpecs = true } },
action: { viewModel.toggleSignSpecs() },
icon: Image(.signSpecs),
text: Localizable.Settings.NetworkDetails.More.Action.sign.key
)
// Remove Network
ActionSheetButton(
action: { animateDismissal { shouldPresentRemoveNetworkConfirmation = true } },
action: { viewModel.toggleRemoveNetworkConfirmation() },
icon: Image(.delete),
text: Localizable.Settings.NetworkDetails.More.Action.delete.key,
style: .destructive
)
ActionButton(
action: { animateDismissal() },
action: { viewModel.dismissActionSheet() },
text: Localizable.LogsList.More.Action.cancel.key,
style: .emptySecondary()
)
Expand All @@ -44,14 +41,63 @@ struct NetworkSettingsDetailsActionModal: View {
}
)
}
}

private func animateDismissal(_ completion: @escaping () -> Void = {}) {
Animations.chainAnimation(
animateBackground.toggle(),
delayedAnimationClosure: {
isShowingActionSheet = false
completion()
}()
)
extension NetworkSettingsDetailsActionModal {
final class ViewModel: ObservableObject {
@Published var animateBackground: Bool = false
@Binding var isPresented: Bool
@Binding var shouldPresentRemoveNetworkConfirmation: Bool
@Binding var shouldSignSpecs: Bool

init(
isPresented: Binding<Bool>,
shouldPresentRemoveNetworkConfirmation: Binding<Bool>,
shouldSignSpecs: Binding<Bool>
) {
_isPresented = isPresented
_shouldPresentRemoveNetworkConfirmation = shouldPresentRemoveNetworkConfirmation
_shouldSignSpecs = shouldSignSpecs
}

func toggleSignSpecs() {
shouldSignSpecs = true
animateDismissal()
}

func toggleRemoveNetworkConfirmation() {
shouldPresentRemoveNetworkConfirmation = true
animateDismissal()
}

func dismissActionSheet() {
animateDismissal()
}

func animateDismissal() {
Animations.chainAnimation(
animateBackground.toggle(),
// swiftformat:disable all
delayedAnimationClosure: self.hide()
)
}

private func hide() {
isPresented = false
}
}
}

#if DEBUG
struct NetworkSettingsDetailsActionModal_Previews: PreviewProvider {
static var previews: some View {
NetworkSettingsDetailsActionModal(
viewModel: .init(
isPresented: .constant(true),
shouldPresentRemoveNetworkConfirmation: .constant(false),
shouldSignSpecs: .constant(false)
)
)
}
}
#endif
Loading

0 comments on commit 3935a75

Please sign in to comment.