diff --git a/0139-better-test-dependencies-pt2/README.md b/0139-better-test-dependencies-pt2/README.md new file mode 100644 index 00000000..1bf97233 --- /dev/null +++ b/0139-better-test-dependencies-pt2/README.md @@ -0,0 +1,5 @@ +## [Point-Free](https://www.pointfree.co) + +> #### This directory contains code from Point-Free Episode: [Better Test Dependencies: Exhaustivity](https://www.pointfree.co/episodes/ep139-better-test-dependencies-failability) +> +> Exhaustively describing dependencies in your tests makes them stronger _and_ easier to understand. We improve the ergonomics of this technique by ditching the `fatalError` in unimplemented dependencies, using `XCTFail`, and we open source a library along the way. diff --git a/0139-better-test-dependencies-pt2/Todos/README.md b/0139-better-test-dependencies-pt2/Todos/README.md new file mode 100644 index 00000000..144ecba9 --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/README.md @@ -0,0 +1 @@ +# Todo Application diff --git a/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/project.pbxproj b/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/project.pbxproj new file mode 100644 index 00000000..3018e71f --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/project.pbxproj @@ -0,0 +1,501 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 52; + objects = { + +/* Begin PBXBuildFile section */ + CA93D060249BF4D000A6F65D /* Todo.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA93D05F249BF4D000A6F65D /* Todo.swift */; }; + DC67272A25FFAF6A00B47038 /* ComposableArchitecture in Frameworks */ = {isa = PBXBuildFile; productRef = DC67272925FFAF6A00B47038 /* ComposableArchitecture */; }; + DCBCB77624290F6C00DE1F59 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCBCB77524290F6C00DE1F59 /* SceneDelegate.swift */; }; + DCBCB77A24290F6D00DE1F59 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DCBCB77924290F6D00DE1F59 /* Assets.xcassets */; }; + DCBCB78B24290F6D00DE1F59 /* TodosTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCBCB78A24290F6D00DE1F59 /* TodosTests.swift */; }; + DCBCB79B24290FEB00DE1F59 /* Todos.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCBCB79A24290FEB00DE1F59 /* Todos.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + DCBCB78724290F6D00DE1F59 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = DCBCB76824290F6C00DE1F59 /* Project object */; + proxyType = 1; + remoteGlobalIDString = DCBCB76F24290F6C00DE1F59; + remoteInfo = Todos; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + DCBCB79924290FDA00DE1F59 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; + DCF6E2D124296752002F8A8F /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + CA93D05F249BF4D000A6F65D /* Todo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Todo.swift; sourceTree = ""; }; + DCBCB77024290F6C00DE1F59 /* Todos.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Todos.app; sourceTree = BUILT_PRODUCTS_DIR; }; + DCBCB77524290F6C00DE1F59 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + DCBCB77924290F6D00DE1F59 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + DCBCB78124290F6D00DE1F59 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + DCBCB78624290F6D00DE1F59 /* TodosTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TodosTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + DCBCB78A24290F6D00DE1F59 /* TodosTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodosTests.swift; sourceTree = ""; }; + DCBCB79A24290FEB00DE1F59 /* Todos.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Todos.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + DCBCB76D24290F6C00DE1F59 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + DC67272A25FFAF6A00B47038 /* ComposableArchitecture in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + DCBCB78324290F6D00DE1F59 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + DCBCB76724290F6C00DE1F59 = { + isa = PBXGroup; + children = ( + DCF6E2CE24296752002F8A8F /* Frameworks */, + DCBCB77124290F6C00DE1F59 /* Products */, + DCBCB77224290F6C00DE1F59 /* Todos */, + DCBCB78924290F6D00DE1F59 /* TodosTests */, + ); + sourceTree = ""; + }; + DCBCB77124290F6C00DE1F59 /* Products */ = { + isa = PBXGroup; + children = ( + DCBCB77024290F6C00DE1F59 /* Todos.app */, + DCBCB78624290F6D00DE1F59 /* TodosTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + DCBCB77224290F6C00DE1F59 /* Todos */ = { + isa = PBXGroup; + children = ( + DCBCB78124290F6D00DE1F59 /* Info.plist */, + DCBCB77524290F6C00DE1F59 /* SceneDelegate.swift */, + CA93D05F249BF4D000A6F65D /* Todo.swift */, + DCBCB79A24290FEB00DE1F59 /* Todos.swift */, + DCBCB77924290F6D00DE1F59 /* Assets.xcassets */, + ); + path = Todos; + sourceTree = ""; + }; + DCBCB78924290F6D00DE1F59 /* TodosTests */ = { + isa = PBXGroup; + children = ( + DCBCB78A24290F6D00DE1F59 /* TodosTests.swift */, + ); + path = TodosTests; + sourceTree = ""; + }; + DCF6E2CE24296752002F8A8F /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + DCBCB76F24290F6C00DE1F59 /* Todos */ = { + isa = PBXNativeTarget; + buildConfigurationList = DCBCB78F24290F6D00DE1F59 /* Build configuration list for PBXNativeTarget "Todos" */; + buildPhases = ( + DCBCB76C24290F6C00DE1F59 /* Sources */, + DCBCB76D24290F6C00DE1F59 /* Frameworks */, + DCBCB76E24290F6C00DE1F59 /* Resources */, + DCBCB79924290FDA00DE1F59 /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Todos; + packageProductDependencies = ( + DC67272925FFAF6A00B47038 /* ComposableArchitecture */, + ); + productName = Todos; + productReference = DCBCB77024290F6C00DE1F59 /* Todos.app */; + productType = "com.apple.product-type.application"; + }; + DCBCB78524290F6D00DE1F59 /* TodosTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = DCBCB79224290F6D00DE1F59 /* Build configuration list for PBXNativeTarget "TodosTests" */; + buildPhases = ( + DCBCB78224290F6D00DE1F59 /* Sources */, + DCBCB78324290F6D00DE1F59 /* Frameworks */, + DCBCB78424290F6D00DE1F59 /* Resources */, + DCF6E2D124296752002F8A8F /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + DCBCB78824290F6D00DE1F59 /* PBXTargetDependency */, + ); + name = TodosTests; + packageProductDependencies = ( + ); + productName = TodosTests; + productReference = DCBCB78624290F6D00DE1F59 /* TodosTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + DCBCB76824290F6C00DE1F59 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1140; + LastUpgradeCheck = 1240; + ORGANIZATIONNAME = "Point-Free"; + TargetAttributes = { + DCBCB76F24290F6C00DE1F59 = { + CreatedOnToolsVersion = 11.4; + }; + DCBCB78524290F6D00DE1F59 = { + CreatedOnToolsVersion = 11.4; + TestTargetID = DCBCB76F24290F6C00DE1F59; + }; + }; + }; + buildConfigurationList = DCBCB76B24290F6C00DE1F59 /* Build configuration list for PBXProject "Todos" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = DCBCB76724290F6C00DE1F59; + packageReferences = ( + DC67272625FFAF5600B47038 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */, + ); + productRefGroup = DCBCB77124290F6C00DE1F59 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + DCBCB76F24290F6C00DE1F59 /* Todos */, + DCBCB78524290F6D00DE1F59 /* TodosTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + DCBCB76E24290F6C00DE1F59 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DCBCB77A24290F6D00DE1F59 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + DCBCB78424290F6D00DE1F59 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + DCBCB76C24290F6C00DE1F59 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DCBCB77624290F6C00DE1F59 /* SceneDelegate.swift in Sources */, + CA93D060249BF4D000A6F65D /* Todo.swift in Sources */, + DCBCB79B24290FEB00DE1F59 /* Todos.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + DCBCB78224290F6D00DE1F59 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DCBCB78B24290F6D00DE1F59 /* TodosTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + DCBCB78824290F6D00DE1F59 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = DCBCB76F24290F6C00DE1F59 /* Todos */; + targetProxy = DCBCB78724290F6D00DE1F59 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + DCBCB78D24290F6D00DE1F59 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + DCBCB78E24290F6D00DE1F59 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + DCBCB79024290F6D00DE1F59 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + ENABLE_PREVIEWS = YES; + INFOPLIST_FILE = Todos/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.Todos; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + DCBCB79124290F6D00DE1F59 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + ENABLE_PREVIEWS = YES; + INFOPLIST_FILE = Todos/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.Todos; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + DCBCB79324290F6D00DE1F59 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.TodosTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Todos.app/Todos"; + }; + name = Debug; + }; + DCBCB79424290F6D00DE1F59 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.TodosTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Todos.app/Todos"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + DCBCB76B24290F6C00DE1F59 /* Build configuration list for PBXProject "Todos" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DCBCB78D24290F6D00DE1F59 /* Debug */, + DCBCB78E24290F6D00DE1F59 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + DCBCB78F24290F6D00DE1F59 /* Build configuration list for PBXNativeTarget "Todos" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DCBCB79024290F6D00DE1F59 /* Debug */, + DCBCB79124290F6D00DE1F59 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + DCBCB79224290F6D00DE1F59 /* Build configuration list for PBXNativeTarget "TodosTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DCBCB79324290F6D00DE1F59 /* Debug */, + DCBCB79424290F6D00DE1F59 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + DC67272625FFAF5600B47038 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/pointfreeco/swift-composable-architecture"; + requirement = { + kind = exactVersion; + version = 0.16.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + DC67272925FFAF6A00B47038 /* ComposableArchitecture */ = { + isa = XCSwiftPackageProductDependency; + package = DC67272625FFAF5600B47038 /* XCRemoteSwiftPackageReference "swift-composable-architecture" */; + productName = ComposableArchitecture; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = DCBCB76824290F6C00DE1F59 /* Project object */; +} diff --git a/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/xcshareddata/xcschemes/Todos.xcscheme b/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/xcshareddata/xcschemes/Todos.xcscheme new file mode 100644 index 00000000..795eb3fe --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/Todos.xcodeproj/xcshareddata/xcschemes/Todos.xcscheme @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/0139-better-test-dependencies-pt2/Todos/Todos/Assets.xcassets/AppIcon.appiconset/AppIcon.png b/0139-better-test-dependencies-pt2/Todos/Todos/Assets.xcassets/AppIcon.appiconset/AppIcon.png new file mode 100644 index 00000000..186b90e3 Binary files /dev/null and b/0139-better-test-dependencies-pt2/Todos/Todos/Assets.xcassets/AppIcon.appiconset/AppIcon.png differ diff --git a/0139-better-test-dependencies-pt2/Todos/Todos/Assets.xcassets/AppIcon.appiconset/Contents.json b/0139-better-test-dependencies-pt2/Todos/Todos/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..e4b96da0 --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/Todos/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,99 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "filename" : "AppIcon.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/0139-better-test-dependencies-pt2/Todos/Todos/Assets.xcassets/Contents.json b/0139-better-test-dependencies-pt2/Todos/Todos/Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/Todos/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/0139-better-test-dependencies-pt2/Todos/Todos/Info.plist b/0139-better-test-dependencies-pt2/Todos/Todos/Info.plist new file mode 100644 index 00000000..9742bf0f --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/Todos/Info.plist @@ -0,0 +1,60 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + + + + + UILaunchStoryboardName + LaunchScreen + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/0139-better-test-dependencies-pt2/Todos/Todos/SceneDelegate.swift b/0139-better-test-dependencies-pt2/Todos/Todos/SceneDelegate.swift new file mode 100644 index 00000000..8dc79320 --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/Todos/SceneDelegate.swift @@ -0,0 +1,40 @@ +import ComposableArchitecture +import SwiftUI +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + var window: UIWindow? + + func scene( + _ scene: UIScene, + willConnectTo session: UISceneSession, + options connectionOptions: UIScene.ConnectionOptions + ) { + self.window = (scene as? UIWindowScene).map(UIWindow.init(windowScene:)) + + let rootView = AppView( + store: Store( + initialState: AppState(), + reducer: appReducer, + environment: AppEnvironment( + analytics: .live, + mainQueue: DispatchQueue.main.eraseToAnyScheduler(), + uuid: UUID.init + ) + ) + ) + + self.window?.rootViewController = UIHostingController(rootView: rootView) + self.window?.makeKeyAndVisible() + } +} + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + true + } +} diff --git a/0139-better-test-dependencies-pt2/Todos/Todos/Todo.swift b/0139-better-test-dependencies-pt2/Todos/Todos/Todo.swift new file mode 100644 index 00000000..59079953 --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/Todos/Todo.swift @@ -0,0 +1,49 @@ +import ComposableArchitecture +import Foundation +import SwiftUI + +struct Todo: Equatable, Identifiable { + var description = "" + let id: UUID + var isComplete = false +} + +enum TodoAction: Equatable { + case checkBoxToggled + case textFieldChanged(String) +} + +struct TodoEnvironment {} + +let todoReducer = Reducer { todo, action, _ in + switch action { + case .checkBoxToggled: + todo.isComplete.toggle() + return .none + + case let .textFieldChanged(description): + todo.description = description + return .none + } +} + +struct TodoView: View { + let store: Store + + var body: some View { + WithViewStore(self.store) { viewStore in + HStack { + Button(action: { viewStore.send(.checkBoxToggled) }) { + Image(systemName: viewStore.isComplete ? "checkmark.square" : "square") + } + .buttonStyle(PlainButtonStyle()) + + TextField( + "Untitled Todo", + text: viewStore.binding(get: { $0.description }, send: TodoAction.textFieldChanged) + ) + } + .foregroundColor(viewStore.isComplete ? .gray : nil) + } + } +} diff --git a/0139-better-test-dependencies-pt2/Todos/Todos/Todos.swift b/0139-better-test-dependencies-pt2/Todos/Todos/Todos.swift new file mode 100644 index 00000000..0d7a8ef0 --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/Todos/Todos.swift @@ -0,0 +1,341 @@ +import ComposableArchitecture +import SwiftUI + +enum Filter: LocalizedStringKey, CaseIterable, Hashable { + case all = "All" + case active = "Active" + case completed = "Completed" +} + +struct AppState: Equatable { + var editMode: EditMode = .inactive + var filter: Filter = .all + var todos: IdentifiedArrayOf = [] + + var filteredTodos: IdentifiedArrayOf { + switch filter { + case .active: return self.todos.filter { !$0.isComplete } + case .all: return self.todos + case .completed: return self.todos.filter { $0.isComplete } + } + } +} + +enum AppAction: Equatable { + case addTodoButtonTapped + case clearCompletedButtonTapped + case delete(IndexSet) + case editModeChanged(EditMode) + case filterPicked(Filter) + case move(IndexSet, Int) + case sortCompletedTodos + case todo(id: UUID, action: TodoAction) +} + +struct AppEnvironment { + var analytics: AnalyticsClient + var mainQueue: AnySchedulerOf + var uuid: () -> UUID +} + +let appReducer = Reducer.combine( + todoReducer.forEach( + state: \.todos, + action: /AppAction.todo(id:action:), + environment: { _ in TodoEnvironment() } + ), + Reducer { state, action, environment in + switch action { + case .addTodoButtonTapped: + state.todos.insert(Todo(id: environment.uuid()), at: 0) + return .none + + case .clearCompletedButtonTapped: + state.todos.removeAll(where: { $0.isComplete }) + return environment.analytics.track(.init(name: "Cleared Completed Todos")) + .fireAndForget() + + case let .delete(indexSet): +// _ = environment.uuid() + state.todos.remove(atOffsets: indexSet) + return environment.analytics.track( + .init( + name: "Todo Deleted", + properties: ["editMode": "\(state.editMode)"] + ) + ) + .fireAndForget() + + case let .editModeChanged(editMode): + state.editMode = editMode + return .none + + case let .filterPicked(filter): + state.filter = filter + return environment.analytics.track( + .init( + name: "Filter Changed", + properties: ["filter": "\(filter)"] + ) + ) + .fireAndForget() + + case let .move(source, destination): + state.todos.move(fromOffsets: source, toOffset: destination) + return Effect(value: .sortCompletedTodos) + .delay(for: .milliseconds(100), scheduler: environment.mainQueue) + .eraseToEffect() + + case .sortCompletedTodos: + state.todos.sortCompleted() + return .none + + case .todo(id: _, action: .checkBoxToggled): + struct TodoCompletionId: Hashable {} + return Effect(value: .sortCompletedTodos) + .debounce(id: TodoCompletionId(), for: 1, scheduler: environment.mainQueue.animation()) + + case .todo: + return .none + } + } +) + +struct AppView: View { + struct ViewState: Equatable { + var editMode: EditMode + var isClearCompletedButtonDisabled: Bool + } + + let store: Store + + var body: some View { + WithViewStore(self.store.scope(state: { $0.view })) { viewStore in + NavigationView { + VStack(alignment: .leading) { + WithViewStore(self.store.scope(state: { $0.filter }, action: AppAction.filterPicked)) { + filterViewStore in + Picker( + "Filter", selection: filterViewStore.binding(send: { $0 }).animation() + ) { + ForEach(Filter.allCases, id: \.self) { filter in + Text(filter.rawValue).tag(filter) + } + } + .pickerStyle(SegmentedPickerStyle()) + } + .padding([.leading, .trailing]) + + List { + ForEachStore( + self.store.scope(state: { $0.filteredTodos }, action: AppAction.todo(id:action:)), + content: TodoView.init(store:) + ) + .onDelete { viewStore.send(.delete($0)) } + .onMove { viewStore.send(.move($0, $1)) } + } + } + .navigationBarTitle("Todos") + .navigationBarItems( + trailing: HStack(spacing: 20) { + EditButton() + Button("Clear Completed") { + viewStore.send(.clearCompletedButtonTapped, animation: .default) + } + .disabled(viewStore.isClearCompletedButtonDisabled) + Button("Add Todo") { viewStore.send(.addTodoButtonTapped, animation: .default) } + } + ) + .environment( + \.editMode, + viewStore.binding(get: { $0.editMode }, send: AppAction.editModeChanged) + ) + } + .navigationViewStyle(StackNavigationViewStyle()) + } + } +} + +extension AppState { + var view: AppView.ViewState { + .init( + editMode: self.editMode, + isClearCompletedButtonDisabled: !self.todos.contains(where: { $0.isComplete }) + ) + } +} + +extension IdentifiedArray where ID == UUID, Element == Todo { + fileprivate mutating func sortCompleted() { + // Simulate stable sort + self = IdentifiedArray( + self.enumerated() + .sorted(by: { lhs, rhs in + (rhs.element.isComplete && !lhs.element.isComplete) || lhs.offset < rhs.offset + }) + .map { $0.element } + ) + } +} + +extension IdentifiedArray where ID == UUID, Element == Todo { + static let mock: Self = [ + Todo( + description: "Check Mail", + id: UUID(uuidString: "DEADBEEF-DEAD-BEEF-DEAD-BEEDDEADBEEF")!, + isComplete: false + ), + Todo( + description: "Buy Milk", + id: UUID(uuidString: "CAFEBEEF-CAFE-BEEF-CAFE-BEEFCAFEBEEF")!, + isComplete: false + ), + Todo( + description: "Call Mom", + id: UUID(uuidString: "D00DCAFE-D00D-CAFE-D00D-CAFED00DCAFE")!, + isComplete: true + ), + ] +} + +struct AppView_Previews: PreviewProvider { + static var previews: some View { + AppView( + store: Store( + initialState: AppState(todos: .mock), + reducer: appReducer, + environment: AppEnvironment( + analytics: .live, + mainQueue: DispatchQueue.main.eraseToAnyScheduler(), + uuid: UUID.init + ) + ) + ) + } +} + +struct AnalyticsClient { + let track: (Event) -> Effect + + struct Event: Equatable { + var name: String + var properties: [String: String] = [:] + } +} + +extension AnalyticsClient { + static let live = Self( + track: { event in + .fireAndForget { + print("Track name: \(event.name), properties: \(event.properties)") + // TODO: send the event data to the analytics server +// URLSession.shared.dataTask(with: URL(string: "https://www.my-company.com/analytics")!) +// .resume() + } + } + ) +} + + +#if canImport(XCTest) +import XCTest + +extension UUID { + // A deterministic, auto-incrementing "UUID" generator for testing. + static var incrementing: () -> UUID { + var uuid = 0 + return { + defer { uuid += 1 } + return UUID(uuidString: "00000000-0000-0000-0000-\(String(format: "%012x", uuid))")! + } + } + + static let unimplemented: () -> UUID = { fatalError() } + +// static func failing(file: StaticString = #file, line: UInt = #line) -> () -> UUID { +// { +// XCTFail("UUID initializer is unimplemented.", file: file, line: line) +// return UUID() +// } +// } + + static let failing: () -> UUID = { + XCTFail("UUID initializer is unimplemented.") + return UUID() +// return UUID.init(uuidString: "deadbeef-dead-beef-dead-beefdeadbeef")! + } +} + +import Combine + +extension Scheduler { + static var unimplemented: AnySchedulerOf { + AnyScheduler( + minimumTolerance: { fatalError() }, + now: { fatalError() }, + scheduleImmediately: { _, _ in fatalError() }, + delayed: { _, _, _, _ in fatalError() }, + interval: { _, _, _, _, _ in fatalError() } + ) + } + + static func failing(now: SchedulerTimeType) -> AnySchedulerOf { + AnyScheduler( + minimumTolerance: { + XCTFail("Scheduler.minimumTolerance is unimplemented") + return .zero + }, + now: { + XCTFail("Scheduler.now is unimplemented") + return now + }, + scheduleImmediately: { _, _ in XCTFail("Scheduler.scheduleImmediately is unimplemented") }, + delayed: { _, _, _, _ in XCTFail("Scheduler.delayed is unimplemented") }, + interval: { _, _, _, _, _ in + XCTFail("Scheduler.interval is unimplemented") + return AnyCancellable {} + } + ) + } +} + +extension Scheduler +where + SchedulerTimeType == DispatchQueue.SchedulerTimeType, + SchedulerOptions == DispatchQueue.SchedulerOptions +{ + static var failing: AnySchedulerOf { + .failing(now: .init(.init(uptimeNanoseconds: 0))) + } +} + +extension Effect { + static func failing(_ title: String) -> Self { + .fireAndForget { + XCTFail("\(title): Effect is unimplemented") + } + } +} + +extension AnalyticsClient { + static let unimplemented = Self( + track: { _ in fatalError() } + ) + + static let failing = Self( + track: { event in + .failing("AnalyticsClient.track") + } + ) + + static func test(onEvent: @escaping (Event) -> Void) -> Self { + Self( + track: { event in + .fireAndForget { + onEvent(event) + } + } + ) + } +} +#endif diff --git a/0139-better-test-dependencies-pt2/Todos/TodosTests/TodosTests.swift b/0139-better-test-dependencies-pt2/Todos/TodosTests/TodosTests.swift new file mode 100644 index 00000000..42dc658e --- /dev/null +++ b/0139-better-test-dependencies-pt2/Todos/TodosTests/TodosTests.swift @@ -0,0 +1,333 @@ +import ComposableArchitecture +import XCTest + +@testable import Todos + +class TodosTests: XCTestCase { + var events: [AnalyticsClient.Event] = [] + let scheduler = DispatchQueue.testScheduler + + func testAddTodo() { + let store = TestStore( + initialState: AppState(), + reducer: appReducer, + environment: AppEnvironment( + analytics: .failing, + mainQueue: .failing, + uuid: UUID.incrementing + ) + ) + + store.assert( + .send(.addTodoButtonTapped) { + $0.todos.insert( + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!, + isComplete: false + ), + at: 0 + ) + }, + .send(.addTodoButtonTapped) { + $0.todos.insert( + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!, + isComplete: false + ), + at: 0 + ) + } + ) + } + + func testEditTodo() { + let state = AppState( + todos: [ + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!, + isComplete: false + ) + ] + ) + let store = TestStore( + initialState: state, + reducer: appReducer, + environment: AppEnvironment( + analytics: .failing, + mainQueue: .failing, + uuid: UUID.failing + ) + ) + + store.assert( + .send( + .todo(id: state.todos[0].id, action: .textFieldChanged("Learn Composable Architecture")) + ) { + $0.todos[0].description = "Learn Composable Architecture" + } + ) + } + + func testCompleteTodo() { + let state = AppState( + todos: [ + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!, + isComplete: false + ), + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!, + isComplete: false + ), + ] + ) + let store = TestStore( + initialState: state, + reducer: appReducer, + environment: AppEnvironment( + analytics: .failing, + mainQueue: self.scheduler.eraseToAnyScheduler(), + uuid: UUID.failing + ) + ) + + store.send(.todo(id: state.todos[0].id, action: .checkBoxToggled)) { + $0.todos[0].isComplete = true + } + + self.scheduler.advance(by: 1) + store.receive(.sortCompletedTodos) { + $0.todos = [ + $0.todos[1], + $0.todos[0], + ] + } + } + + func testCompleteTodoDebounces() { + let state = AppState( + todos: [ + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!, + isComplete: false + ), + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!, + isComplete: false + ), + ] + ) + let store = TestStore( + initialState: state, + reducer: appReducer, + environment: AppEnvironment( + analytics: .failing, + mainQueue: self.scheduler.eraseToAnyScheduler(), + uuid: UUID.incrementing + ) + ) + + store.assert( + .send(.todo(id: state.todos[0].id, action: .checkBoxToggled)) { + $0.todos[0].isComplete = true + }, + .do { self.scheduler.advance(by: 0.5) }, + .send(.todo(id: state.todos[0].id, action: .checkBoxToggled)) { + $0.todos[0].isComplete = false + }, + .do { self.scheduler.advance(by: 1) }, + .receive(.sortCompletedTodos) + ) + } + + func testClearCompleted() { + let state = AppState( + todos: [ + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!, + isComplete: false + ), + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!, + isComplete: true + ), + ] + ) + let store = TestStore( + initialState: state, + reducer: appReducer, + environment: AppEnvironment( + analytics: .test(onEvent: { event in self.events.append(event) }), + mainQueue: self.scheduler.eraseToAnyScheduler(), + uuid: UUID.incrementing + ) + ) + + store.assert( + .send(.clearCompletedButtonTapped) { + $0.todos = [ + $0.todos[0] + ] + } + ) + XCTAssertEqual(events, [.init(name: "Cleared Completed Todos")]) + } + + func testDelete() { + let state = AppState( + todos: [ + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!, + isComplete: false + ), + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!, + isComplete: false + ), + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000002")!, + isComplete: false + ), + ] + ) + let store = TestStore( + initialState: state, + reducer: appReducer, + environment: AppEnvironment( + analytics: .test { self.events.append($0) }, + mainQueue: .failing, + uuid: UUID.failing + ) + ) + + store.send(.delete([1])) { + $0.todos = [ + $0.todos[0], + $0.todos[2], + ] + } + + XCTAssertEqual( + self.events, + [ + .init(name: "Todo Deleted", properties: ["editMode": "inactive"]), + ] + ) + + store.send(.editModeChanged(.active)) { + $0.editMode = .active + } + store.send(.delete([0])) { + $0.todos = [ + $0.todos[1] + ] + } + + XCTAssertEqual( + events, + [ + .init(name: "Todo Deleted", properties: ["editMode": "inactive"]), + .init(name: "Todo Deleted", properties: ["editMode": "active"]), + ] + ) + } + + func testEditModeMoving() { + let state = AppState( + todos: [ + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!, + isComplete: false + ), + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!, + isComplete: false + ), + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000002")!, + isComplete: false + ), + ] + ) + let store = TestStore( + initialState: state, + reducer: appReducer, + environment: AppEnvironment( + analytics: .failing, + mainQueue: self.scheduler.eraseToAnyScheduler(), + uuid: UUID.incrementing + ) + ) + + store.assert( + .send(.editModeChanged(.active)) { + $0.editMode = .active + }, + .send(.move([0], 2)) { + $0.todos = [ + $0.todos[1], + $0.todos[0], + $0.todos[2], + ] + }, + .do { self.scheduler.advance(by: .milliseconds(100)) }, + .receive(.sortCompletedTodos) + ) + } + + func testFilteredEdit() { + let state = AppState( + todos: [ + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!, + isComplete: false + ), + Todo( + description: "", + id: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!, + isComplete: true + ), + ] + ) + let store = TestStore( + initialState: state, + reducer: appReducer, + environment: AppEnvironment( + analytics: .test(onEvent: { self.events.append($0) }), + mainQueue: self.scheduler.eraseToAnyScheduler(), + uuid: UUID.incrementing + ) + ) + + store.assert( + .send(.filterPicked(.completed)) { + $0.filter = .completed + }, + .do { + XCTAssertEqual( + self.events, + [.init(name: "Filter Changed", properties: ["filter": "completed"])] + ) + }, + .send(.todo(id: state.todos[1].id, action: .textFieldChanged("Did this already"))) { + $0.todos[1].description = "Did this already" + } + ) + } +} diff --git a/README.md b/README.md index e21b7452..2defc5eb 100644 --- a/README.md +++ b/README.md @@ -140,3 +140,4 @@ This repository is the home of code written on episodes of [Point-Free](https:// 1. [SwiftUI Animation: Composable Architecture](0136-swiftui-animation-pt2) 1. [SwiftUI Animation: The Point](0137-swiftui-animation-pt3) 1. [Better Test Dependencies: Exhaustivity](0138-better-test-dependencies-pt1) +1. [Better Test Dependencies: Failability](0139-better-test-dependencies-pt2)