From cc1864ab1d3c8757edf89bc012fc1cac6fd4dc15 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Fri, 30 Sep 2022 02:53:44 +0200 Subject: [PATCH] Add ContactLookupFeature library --- .../xcschemes/ContactLookupFeature.xcscheme | 78 +++++++++++++++++++ Examples/xx-messenger/Package.swift | 19 +++++ .../xcschemes/XXMessenger.xcscheme | 10 +++ .../ContactLookupFeature.swift | 46 +++++++++++ .../ContactLookupView.swift | 69 ++++++++++++++++ .../ContactLookupFeatureTests.swift | 31 ++++++++ 6 files changed, 253 insertions(+) create mode 100644 Examples/xx-messenger/.swiftpm/xcode/xcshareddata/xcschemes/ContactLookupFeature.xcscheme create mode 100644 Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupFeature.swift create mode 100644 Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupView.swift create mode 100644 Examples/xx-messenger/Tests/ContactLookupFeatureTests/ContactLookupFeatureTests.swift diff --git a/Examples/xx-messenger/.swiftpm/xcode/xcshareddata/xcschemes/ContactLookupFeature.xcscheme b/Examples/xx-messenger/.swiftpm/xcode/xcshareddata/xcschemes/ContactLookupFeature.xcscheme new file mode 100644 index 00000000..e0070c64 --- /dev/null +++ b/Examples/xx-messenger/.swiftpm/xcode/xcshareddata/xcschemes/ContactLookupFeature.xcscheme @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Scheme + LastUpgradeVersion = "1400" + version = "1.3"> + <BuildAction + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + <BuildActionEntries> + <BuildActionEntry + buildForTesting = "YES" + buildForRunning = "YES" + buildForProfiling = "YES" + buildForArchiving = "YES" + buildForAnalyzing = "YES"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "ContactLookupFeature" + BuildableName = "ContactLookupFeature" + BlueprintName = "ContactLookupFeature" + ReferencedContainer = "container:"> + </BuildableReference> + </BuildActionEntry> + </BuildActionEntries> + </BuildAction> + <TestAction + buildConfiguration = "Debug" + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> + <Testables> + <TestableReference + skipped = "NO"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "ContactLookupFeatureTests" + BuildableName = "ContactLookupFeatureTests" + BlueprintName = "ContactLookupFeatureTests" + ReferencedContainer = "container:"> + </BuildableReference> + </TestableReference> + </Testables> + </TestAction> + <LaunchAction + buildConfiguration = "Debug" + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + launchStyle = "0" + useCustomWorkingDirectory = "NO" + ignoresPersistentStateOnLaunch = "NO" + debugDocumentVersioning = "YES" + debugServiceExtension = "internal" + allowLocationSimulation = "YES"> + </LaunchAction> + <ProfileAction + buildConfiguration = "Release" + shouldUseLaunchSchemeArgsEnv = "YES" + savedToolIdentifier = "" + useCustomWorkingDirectory = "NO" + debugDocumentVersioning = "YES"> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "ContactLookupFeature" + BuildableName = "ContactLookupFeature" + BlueprintName = "ContactLookupFeature" + ReferencedContainer = "container:"> + </BuildableReference> + </MacroExpansion> + </ProfileAction> + <AnalyzeAction + buildConfiguration = "Debug"> + </AnalyzeAction> + <ArchiveAction + buildConfiguration = "Release" + revealArchiveInOrganizer = "YES"> + </ArchiveAction> +</Scheme> diff --git a/Examples/xx-messenger/Package.swift b/Examples/xx-messenger/Package.swift index 4668d629..1cab487e 100644 --- a/Examples/xx-messenger/Package.swift +++ b/Examples/xx-messenger/Package.swift @@ -20,6 +20,7 @@ let package = Package( .library(name: "CheckContactAuthFeature", targets: ["CheckContactAuthFeature"]), .library(name: "ConfirmRequestFeature", targets: ["ConfirmRequestFeature"]), .library(name: "ContactFeature", targets: ["ContactFeature"]), + .library(name: "ContactLookupFeature", targets: ["ContactLookupFeature"]), .library(name: "ContactsFeature", targets: ["ContactsFeature"]), .library(name: "HomeFeature", targets: ["HomeFeature"]), .library(name: "MyContactFeature", targets: ["MyContactFeature"]), @@ -208,6 +209,24 @@ let package = Package( ], swiftSettings: swiftSettings ), + .target( + name: "ContactLookupFeature", + dependencies: [ + .target(name: "AppCore"), + .product(name: "ComposableArchitecture", package: "swift-composable-architecture"), + .product(name: "XXMessengerClient", package: "elixxir-dapps-sdk-swift"), + .product(name: "XXModels", package: "client-ios-db"), + ], + swiftSettings: swiftSettings + ), + .testTarget( + name: "ContactLookupFeatureTests", + dependencies: [ + .target(name: "ContactLookupFeature"), + .product(name: "CustomDump", package: "swift-custom-dump"), + ], + swiftSettings: swiftSettings + ), .target( name: "ContactsFeature", dependencies: [ diff --git a/Examples/xx-messenger/Project/XXMessenger.xcodeproj/xcshareddata/xcschemes/XXMessenger.xcscheme b/Examples/xx-messenger/Project/XXMessenger.xcodeproj/xcshareddata/xcschemes/XXMessenger.xcscheme index b50f1c10..42a3cede 100644 --- a/Examples/xx-messenger/Project/XXMessenger.xcodeproj/xcshareddata/xcschemes/XXMessenger.xcscheme +++ b/Examples/xx-messenger/Project/XXMessenger.xcodeproj/xcshareddata/xcschemes/XXMessenger.xcscheme @@ -99,6 +99,16 @@ ReferencedContainer = "container:.."> </BuildableReference> </TestableReference> + <TestableReference + skipped = "NO"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "ContactLookupFeatureTests" + BuildableName = "ContactLookupFeatureTests" + BlueprintName = "ContactLookupFeatureTests" + ReferencedContainer = "container:.."> + </BuildableReference> + </TestableReference> <TestableReference skipped = "NO"> <BuildableReference diff --git a/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupFeature.swift b/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupFeature.swift new file mode 100644 index 00000000..7fd2fc8e --- /dev/null +++ b/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupFeature.swift @@ -0,0 +1,46 @@ +import ComposableArchitecture +import Foundation +import XCTestDynamicOverlay + +public struct ContactLookupState: Equatable { + public init( + id: Data, + isLookingUp: Bool = false + ) { + self.id = id + self.isLookingUp = isLookingUp + } + + public var id: Data + public var isLookingUp: Bool +} + +public enum ContactLookupAction: Equatable { + case task + case cancelTask + case lookupTapped +} + +public struct ContactLookupEnvironment { + public init() {} +} + +#if DEBUG +extension ContactLookupEnvironment { + public static let unimplemented = ContactLookupEnvironment() +} +#endif + +public let contactLookupReducer = Reducer<ContactLookupState, ContactLookupAction, ContactLookupEnvironment> +{ state, action, env in + switch action { + case .task: + return .none + + case .cancelTask: + return .none + + case .lookupTapped: + return .none + } +} diff --git a/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupView.swift b/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupView.swift new file mode 100644 index 00000000..1d1e0208 --- /dev/null +++ b/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupView.swift @@ -0,0 +1,69 @@ +import AppCore +import ComposableArchitecture +import SwiftUI + +public struct ContactLookupView: View { + public init(store: Store<ContactLookupState, ContactLookupAction>) { + self.store = store + } + + let store: Store<ContactLookupState, ContactLookupAction> + + struct ViewState: Equatable { + init(state: ContactLookupState) { + id = state.id + isLookingUp = state.isLookingUp + } + + var id: Data + var isLookingUp: Bool + } + + public var body: some View { + WithViewStore(store, observe: ViewState.init) { viewStore in + Form { + Section { + Label(viewStore.id.hexString, systemImage: "number") + .font(.footnote.monospaced()) + + Button { + viewStore.send(.lookupTapped) + } label: { + HStack { + Text("Lookup") + Spacer() + if viewStore.isLookingUp { + ProgressView() + } else { + Image(systemName: "magnifyingglass") + } + } + } + .disabled(viewStore.isLookingUp) + } header: { + Text("Contact ID") + } + } + .navigationTitle("Lookup") + .task { + await viewStore.send(.task).finish() + } + } + } +} + +#if DEBUG +public struct ContactLookupView_Previews: PreviewProvider { + public static var previews: some View { + NavigationView { + ContactLookupView(store: Store( + initialState: ContactLookupState( + id: "1234".data(using: .utf8)! + ), + reducer: .empty, + environment: () + )) + } + } +} +#endif diff --git a/Examples/xx-messenger/Tests/ContactLookupFeatureTests/ContactLookupFeatureTests.swift b/Examples/xx-messenger/Tests/ContactLookupFeatureTests/ContactLookupFeatureTests.swift new file mode 100644 index 00000000..70847105 --- /dev/null +++ b/Examples/xx-messenger/Tests/ContactLookupFeatureTests/ContactLookupFeatureTests.swift @@ -0,0 +1,31 @@ +import ComposableArchitecture +import XCTest +@testable import ContactLookupFeature + +final class ContactLookupFeatureTests: XCTestCase { + func testTask() { + let store = TestStore( + initialState: ContactLookupState( + id: "1234".data(using: .utf8)! + ), + reducer: contactLookupReducer, + environment: .unimplemented + ) + + store.send(.task) + + store.send(.cancelTask) + } + + func testLookup() { + let store = TestStore( + initialState: ContactLookupState( + id: "1234".data(using: .utf8)! + ), + reducer: contactLookupReducer, + environment: .unimplemented + ) + + store.send(.lookupTapped) + } +} -- GitLab