From b38e145e38d056629f719b7762eb1ce0023945ad Mon Sep 17 00:00:00 2001 From: Valentina Socolov Date: Sun, 31 Jul 2022 16:40:01 +0100 Subject: [PATCH 1/2] add tests for ToDoList --- Classes/BaseViewController.swift | 75 ++++---- Classes/Tasks/TasksViewController.swift | 4 +- ToDoList.xcodeproj/project.pbxproj | 161 +++++++++++++++++- .../xcshareddata/xcschemes/ToDoList.xcscheme | 10 ++ ToDoListUITests/Base/ToDoListUITests.swift | 31 ++++ .../Elements/ScreensElements.swift | 64 +++++++ ToDoListUITests/Steps/ToDoListSteps.swift | 44 +++++ ToDoListUITests/Tests/ToDoListTests.swift | 19 +++ 8 files changed, 368 insertions(+), 40 deletions(-) create mode 100644 ToDoListUITests/Base/ToDoListUITests.swift create mode 100644 ToDoListUITests/Elements/ScreensElements.swift create mode 100644 ToDoListUITests/Steps/ToDoListSteps.swift create mode 100644 ToDoListUITests/Tests/ToDoListTests.swift diff --git a/Classes/BaseViewController.swift b/Classes/BaseViewController.swift index 29249d2..87e3435 100644 --- a/Classes/BaseViewController.swift +++ b/Classes/BaseViewController.swift @@ -9,41 +9,42 @@ import UIKit class BaseViewController: UIViewController { - - override func viewDidLoad() { - super.viewDidLoad() - - self.setupUI() - self.setupBindings() - } - - @objc func setupUI() { - DispatchQueue.main.async { - self.setupNavigationBar() - } - } - - func setupBindings() { - NotificationCenter.default.addObserver(self, selector: #selector(self.setupUI), name: Config.Notifications.themeUpdated, object: nil) - } - - func setupNavigationBar() { - self.navigationController?.navigationBar.barStyle = .black; -// self.navigationController?.navigationBar.barTintColor = Utils().getCurrentThemeColor() -// self.navigationController?.view.backgroundColor = Utils().getCurrentThemeColor() - - let appearance = UINavigationBarAppearance() - appearance.configureWithOpaqueBackground() - appearance.backgroundColor = Utils().getCurrentThemeColor() - self.navigationController?.navigationBar.standardAppearance = appearance; - self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance - - - self.navigationController?.navigationBar.tintColor = UIColor.white - self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] - self.navigationController?.navigationBar.isTranslucent = false - self.navigationController?.navigationBar.setValue(true, forKey: "hidesShadow") - - UISearchBar.appearance().backgroundColor = Utils().getCurrentThemeColor() - } + + override func viewDidLoad() { + super.viewDidLoad() + + self.setupUI() + self.setupBindings() + } + + @objc func setupUI() { + DispatchQueue.main.async { + self.setupNavigationBar() + } + } + + func setupBindings() { + NotificationCenter.default.addObserver(self, selector: #selector(self.setupUI), name: Config.Notifications.themeUpdated, object: nil) + } + + func setupNavigationBar() { + self.navigationController?.navigationBar.barStyle = .black; + // self.navigationController?.navigationBar.barTintColor = Utils().getCurrentThemeColor() + // self.navigationController?.view.backgroundColor = Utils().getCurrentThemeColor() + if #available(iOS 13.0, *) { + let appearance = UINavigationBarAppearance() + appearance.configureWithOpaqueBackground() + appearance.backgroundColor = Utils().getCurrentThemeColor() + self.navigationController?.navigationBar.standardAppearance = appearance; + self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance + + + self.navigationController?.navigationBar.tintColor = UIColor.white + self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] + self.navigationController?.navigationBar.isTranslucent = false + self.navigationController?.navigationBar.setValue(true, forKey: "hidesShadow") + + UISearchBar.appearance().backgroundColor = Utils().getCurrentThemeColor() + } + } } diff --git a/Classes/Tasks/TasksViewController.swift b/Classes/Tasks/TasksViewController.swift index 345524d..5abda57 100644 --- a/Classes/Tasks/TasksViewController.swift +++ b/Classes/Tasks/TasksViewController.swift @@ -69,7 +69,7 @@ class TasksViewController: BaseViewController { self.searchController.searchBar.tintColor = UIColor.white // self.searchController.searchBar.barTintColor = Utils().getCurrentThemeColor() // self.navigationController?.view.backgroundColor = Utils().getCurrentThemeColor() - + if #available(iOS 13.0, *) { let appearance = UINavigationBarAppearance() appearance.configureWithOpaqueBackground() appearance.backgroundColor = Utils().getCurrentThemeColor() @@ -84,7 +84,7 @@ class TasksViewController: BaseViewController { self.tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.size.width, height: 1)) } - + } override func setupBindings() { super.setupBindings() diff --git a/ToDoList.xcodeproj/project.pbxproj b/ToDoList.xcodeproj/project.pbxproj index 87cc16c..0dddca0 100644 --- a/ToDoList.xcodeproj/project.pbxproj +++ b/ToDoList.xcodeproj/project.pbxproj @@ -7,6 +7,10 @@ objects = { /* Begin PBXBuildFile section */ + 016C77EA2896D8B400FD4F5B /* ToDoListUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016C77E92896D8B400FD4F5B /* ToDoListUITests.swift */; }; + 016C77F72896D91F00FD4F5B /* ScreensElements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016C77F62896D91F00FD4F5B /* ScreensElements.swift */; }; + 016C77F92896D94000FD4F5B /* ToDoListSteps.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016C77F82896D94000FD4F5B /* ToDoListSteps.swift */; }; + 016C77FB2896D96500FD4F5B /* ToDoListTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016C77FA2896D96500FD4F5B /* ToDoListTests.swift */; }; 170DEDFE2672916600024B70 /* IceCream in Frameworks */ = {isa = PBXBuildFile; productRef = 170DEDFD2672916600024B70 /* IceCream */; }; 1710DD2923CF5C46000E64F4 /* Main-iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1710DD2823CF5C46000E64F4 /* Main-iPad.storyboard */; }; 1718BE4523CCBB19009D591A /* NotificationCenter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1718BE4423CCBB19009D591A /* NotificationCenter.framework */; }; @@ -123,6 +127,13 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 016C77ED2896D8B400FD4F5B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 17D18D33221D56C4005C647B /* Project object */; + proxyType = 1; + remoteGlobalIDString = 17D18D3A221D56C4005C647B; + remoteInfo = ToDoList; + }; 1718BE4D23CCBB19009D591A /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 17D18D33221D56C4005C647B /* Project object */; @@ -183,6 +194,11 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 016C77E72896D8B400FD4F5B /* ToDoListUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ToDoListUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 016C77E92896D8B400FD4F5B /* ToDoListUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToDoListUITests.swift; sourceTree = ""; }; + 016C77F62896D91F00FD4F5B /* ScreensElements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreensElements.swift; sourceTree = ""; }; + 016C77F82896D94000FD4F5B /* ToDoListSteps.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToDoListSteps.swift; sourceTree = ""; }; + 016C77FA2896D96500FD4F5B /* ToDoListTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToDoListTests.swift; sourceTree = ""; }; 170DEDFC267290D000024B70 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 1710DD2823CF5C46000E64F4 /* Main-iPad.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Main-iPad.storyboard"; sourceTree = ""; }; 1718BE4323CCBB19009D591A /* ToDoListWidget.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = ToDoListWidget.appex; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -277,6 +293,13 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 016C77E42896D8B400FD4F5B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 1718BE4023CCBB19009D591A /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -333,6 +356,49 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 016C77E82896D8B400FD4F5B /* ToDoListUITests */ = { + isa = PBXGroup; + children = ( + 016C77F52896D8E600FD4F5B /* Tests */, + 016C77F42896D8E000FD4F5B /* Steps */, + 016C77F32896D8D400FD4F5B /* Elements */, + 016C77F22896D8C800FD4F5B /* Base */, + ); + path = ToDoListUITests; + sourceTree = ""; + }; + 016C77F22896D8C800FD4F5B /* Base */ = { + isa = PBXGroup; + children = ( + 016C77E92896D8B400FD4F5B /* ToDoListUITests.swift */, + ); + path = Base; + sourceTree = ""; + }; + 016C77F32896D8D400FD4F5B /* Elements */ = { + isa = PBXGroup; + children = ( + 016C77F62896D91F00FD4F5B /* ScreensElements.swift */, + ); + path = Elements; + sourceTree = ""; + }; + 016C77F42896D8E000FD4F5B /* Steps */ = { + isa = PBXGroup; + children = ( + 016C77F82896D94000FD4F5B /* ToDoListSteps.swift */, + ); + path = Steps; + sourceTree = ""; + }; + 016C77F52896D8E600FD4F5B /* Tests */ = { + isa = PBXGroup; + children = ( + 016C77FA2896D96500FD4F5B /* ToDoListTests.swift */, + ); + path = Tests; + sourceTree = ""; + }; 1718BE4623CCBB19009D591A /* Widget */ = { isa = PBXGroup; children = ( @@ -427,6 +493,7 @@ 1718BE4623CCBB19009D591A /* Widget */, 17278CC523CE05880014B8B2 /* WatchApp */, 17278CD423CE05890014B8B2 /* WatchApp Extension */, + 016C77E82896D8B400FD4F5B /* ToDoListUITests */, 17D18D3C221D56C4005C647B /* Products */, 174F9ED1221D8E7F00D9C139 /* Frameworks */, ); @@ -439,6 +506,7 @@ 1718BE4323CCBB19009D591A /* ToDoListWidget.appex */, 17278CC423CE05880014B8B2 /* WatchApp.app */, 17278CD023CE05890014B8B2 /* WatchApp Extension.appex */, + 016C77E72896D8B400FD4F5B /* ToDoListUITests.xctest */, ); name = Products; sourceTree = ""; @@ -526,6 +594,24 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 016C77E62896D8B400FD4F5B /* ToDoListUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 016C77F12896D8B400FD4F5B /* Build configuration list for PBXNativeTarget "ToDoListUITests" */; + buildPhases = ( + 016C77E32896D8B400FD4F5B /* Sources */, + 016C77E42896D8B400FD4F5B /* Frameworks */, + 016C77E52896D8B400FD4F5B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 016C77EE2896D8B400FD4F5B /* PBXTargetDependency */, + ); + name = ToDoListUITests; + productName = ToDoListUITests; + productReference = 016C77E72896D8B400FD4F5B /* ToDoListUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; 1718BE4223CCBB19009D591A /* ToDoListWidget */ = { isa = PBXNativeTarget; buildConfigurationList = 1718BE5323CCBB19009D591A /* Build configuration list for PBXNativeTarget "ToDoListWidget" */; @@ -638,10 +724,14 @@ 17D18D33221D56C4005C647B /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 1130; + LastSwiftUpdateCheck = 1330; LastUpgradeCheck = 1200; ORGANIZATIONNAME = "Radu Ursache - RanduSoft"; TargetAttributes = { + 016C77E62896D8B400FD4F5B = { + CreatedOnToolsVersion = 13.3.1; + TestTargetID = 17D18D3A221D56C4005C647B; + }; 1718BE4223CCBB19009D591A = { CreatedOnToolsVersion = 11.3; }; @@ -701,11 +791,19 @@ 1718BE4223CCBB19009D591A /* ToDoListWidget */, 17278CC323CE05880014B8B2 /* WatchApp */, 17278CCF23CE05890014B8B2 /* WatchApp Extension */, + 016C77E62896D8B400FD4F5B /* ToDoListUITests */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 016C77E52896D8B400FD4F5B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 1718BE4123CCBB19009D591A /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -769,6 +867,17 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 016C77E32896D8B400FD4F5B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 016C77F72896D91F00FD4F5B /* ScreensElements.swift in Sources */, + 016C77EA2896D8B400FD4F5B /* ToDoListUITests.swift in Sources */, + 016C77F92896D94000FD4F5B /* ToDoListSteps.swift in Sources */, + 016C77FB2896D96500FD4F5B /* ToDoListTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 1718BE3F23CCBB19009D591A /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -846,6 +955,11 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 016C77EE2896D8B400FD4F5B /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 17D18D3A221D56C4005C647B /* ToDoList */; + targetProxy = 016C77ED2896D8B400FD4F5B /* PBXContainerItemProxy */; + }; 1718BE4E23CCBB19009D591A /* PBXTargetDependency */ = { isa = PBXTargetDependency; platformFilter = ios; @@ -936,6 +1050,42 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 016C77EF2896D8B400FD4F5B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.4; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.vale.ToDoListUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = ToDoList; + }; + name = Debug; + }; + 016C77F02896D8B400FD4F5B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.4; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.vale.ToDoListUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = ToDoList; + }; + name = Release; + }; 1718BE5123CCBB19009D591A /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -1264,6 +1414,15 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 016C77F12896D8B400FD4F5B /* Build configuration list for PBXNativeTarget "ToDoListUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 016C77EF2896D8B400FD4F5B /* Debug */, + 016C77F02896D8B400FD4F5B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 1718BE5323CCBB19009D591A /* Build configuration list for PBXNativeTarget "ToDoListWidget" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/ToDoList.xcodeproj/xcshareddata/xcschemes/ToDoList.xcscheme b/ToDoList.xcodeproj/xcshareddata/xcschemes/ToDoList.xcscheme index ee71efc..367ad31 100644 --- a/ToDoList.xcodeproj/xcshareddata/xcschemes/ToDoList.xcscheme +++ b/ToDoList.xcodeproj/xcshareddata/xcschemes/ToDoList.xcscheme @@ -37,6 +37,16 @@ + + + + Date: Mon, 1 Aug 2022 00:11:53 +0100 Subject: [PATCH 2/2] add comments to tests --- .../Elements/ScreensElements.swift | 6 +++-- ToDoListUITests/Steps/ToDoListSteps.swift | 24 ++++++++++++++----- ToDoListUITests/Tests/ToDoListTests.swift | 6 +++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/ToDoListUITests/Elements/ScreensElements.swift b/ToDoListUITests/Elements/ScreensElements.swift index cc46d8e..225a177 100644 --- a/ToDoListUITests/Elements/ScreensElements.swift +++ b/ToDoListUITests/Elements/ScreensElements.swift @@ -8,7 +8,7 @@ import XCTest class ToDoListElements { - + // Group screen element and attached relevant element type thus in case of any changed/issues it is easier and faster to detect and update label enum ScreensElements: String { case welcom = "Welcome to ToDoList" case continueButton = "Continue" @@ -33,6 +33,7 @@ class ToDoListElements { } } } + enum taskName:String { case addTask = "To write a test" case editTask = " and to run a test" @@ -44,7 +45,6 @@ class ToDoListElements { XCUIApplication().textViews.element.typeText(taskName.rawValue) ToDoListElements.ScreensElements.saveButton.element.tap() case .editTask: - //as a improvements for this step is to add identofier in the code and use string interpolation to make identifier unique for each cell XCUIApplication().cells.element(boundBy: 0).tap() XCUIApplication().cells.element(boundBy: 0).tap() ToDoListElements.ScreensElements.editButton.element.tap() @@ -55,6 +55,8 @@ class ToDoListElements { func enterTaskName(_ name: ToDoListElements.taskName) { enter(taskName: name) } + + // Confirm if task was created by matching All Tasks with updated value 1 func createdTask() { XCUIApplication().cells .descendants(matching: .staticText).matching(NSPredicate(format: "label = '1'", "All Tasks")) diff --git a/ToDoListUITests/Steps/ToDoListSteps.swift b/ToDoListUITests/Steps/ToDoListSteps.swift index 9d7ba65..c97fab5 100644 --- a/ToDoListUITests/Steps/ToDoListSteps.swift +++ b/ToDoListUITests/Steps/ToDoListSteps.swift @@ -11,32 +11,44 @@ import XCTest class ToDoListSteps: ToDoListUITests { private let screenElements = ToDoListElements() - //MARK: Tests steps - + //MARK: User pass onBoarding + // Given: User Launch app for the fisr time + // When: User pass onBoarding + // Then: User Land on ToDoList Main Page func userPassOnBoarding() { - XCTContext.runActivity(named: "Given: User pass onBoarding") { _ in + XCTContext.runActivity(named: "Given: User launch app for the first time") { _ in waitForElement(ToDoListElements.ScreensElements.welcom.element) + } + XCTContext.runActivity(named: "When user pass onBoarding") { _ in ToDoListElements.ScreensElements.continueButton.element.tap() waitForElement(ToDoListElements.ScreensElements.pushNotification.element) ToDoListElements.ScreensElements.notNowButton.element.tap() waitForElement(ToDoListElements.ScreensElements.onBoardingDone.element) ToDoListElements.ScreensElements.getStartedButton.element.tap() + } + XCTContext.runActivity(named: "Then user see ToDOList Main Page") { _ in waitForElement(ToDoListElements.ScreensElements.toDoListHome.element) } } + + //MARK: User add,edit and mark as done first task +//Given: User passed onBoarding +//When: user add first task +//And: task can be editable +//Then: task marked as complete func userAddTask() { - XCTContext.runActivity(named: "When: user add task") { _ in + XCTContext.runActivity(named: "When: user add first task") { _ in screenElements.enterTaskName(.addTask) screenElements.createdTask() } } func userEditTask() { - XCTContext.runActivity(named: "Then: User can edit task") { _ in + XCTContext.runActivity(named: "And: task can be editable") { _ in screenElements.enterTaskName(.editTask) } } func usedDeleteTask() { - XCTContext.runActivity(named: "And: User can delete task") { _ in + XCTContext.runActivity(named: "Then: task can be deleted") { _ in ToDoListElements.ScreensElements.completeTaskButton.element.tap() waitForElement(ToDoListElements.ScreensElements.noTasks.element) } diff --git a/ToDoListUITests/Tests/ToDoListTests.swift b/ToDoListUITests/Tests/ToDoListTests.swift index 2e7e078..e9363a6 100644 --- a/ToDoListUITests/Tests/ToDoListTests.swift +++ b/ToDoListUITests/Tests/ToDoListTests.swift @@ -9,8 +9,10 @@ import XCTest class ToDoListTests: ToDoListSteps { - - func test_userAddTask() { + + //MARK: Main tests to run + + func test_userAddEditCompleteTask() { userPassOnBoarding() userAddTask() userEditTask()