From 677966a31696d003fd8c4c40a3b4f309cfd54f59 Mon Sep 17 00:00:00 2001 From: Theodore Date: Fri, 8 Mar 2024 00:09:23 -0800 Subject: [PATCH] More swiftlint fixes --- Stronger.xcodeproj/project.pbxproj | 4 +++ Stronger/Exercise/WorkoutSelection.swift | 12 +++++--- StrongerUITests/MissedWorkoutTest.swift | 39 ++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 StrongerUITests/MissedWorkoutTest.swift diff --git a/Stronger.xcodeproj/project.pbxproj b/Stronger.xcodeproj/project.pbxproj index 70aa2e7..625e3c6 100644 --- a/Stronger.xcodeproj/project.pbxproj +++ b/Stronger.xcodeproj/project.pbxproj @@ -84,6 +84,7 @@ 38756AB22B946D0E00FDF599 /* ExerciseInfo.json in Resources */ = {isa = PBXBuildFile; fileRef = 38756AB12B946D0E00FDF599 /* ExerciseInfo.json */; }; 38C4563E2B96CF3B009D69AA /* WorkoutHomeButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38C4563D2B96CF3B009D69AA /* WorkoutHomeButton.swift */; }; 38FE1D022B716A42008F8BE0 /* WorkoutVideoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38FE1D012B7169DF008F8BE0 /* WorkoutVideoView.swift */; }; + 4002F0AC2B9AFC4D00AD3D47 /* MissedWorkoutTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4002F0AB2B9AFC4D00AD3D47 /* MissedWorkoutTest.swift */; }; 4011141A2B7EE59A000083A2 /* ProgressCircle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 401114192B7EE59A000083A2 /* ProgressCircle.swift */; }; 4011141D2B83FCD1000083A2 /* SummaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4011141C2B83FCD1000083A2 /* SummaryView.swift */; }; 401114232B8489D1000083A2 /* GoalResist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 401114222B8489D1000083A2 /* GoalResist.swift */; }; @@ -218,6 +219,7 @@ 38756AB12B946D0E00FDF599 /* ExerciseInfo.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ExerciseInfo.json; sourceTree = ""; }; 38C4563D2B96CF3B009D69AA /* WorkoutHomeButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WorkoutHomeButton.swift; sourceTree = ""; }; 38FE1D012B7169DF008F8BE0 /* WorkoutVideoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkoutVideoView.swift; sourceTree = ""; }; + 4002F0AB2B9AFC4D00AD3D47 /* MissedWorkoutTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MissedWorkoutTest.swift; sourceTree = ""; }; 401114192B7EE59A000083A2 /* ProgressCircle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressCircle.swift; sourceTree = ""; }; 4011141C2B83FCD1000083A2 /* SummaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SummaryView.swift; sourceTree = ""; }; 401114222B8489D1000083A2 /* GoalResist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoalResist.swift; sourceTree = ""; }; @@ -566,6 +568,7 @@ 40D4E47E2B97CB9900261632 /* HomeTest.swift */, 40D4E4812B97CBB800261632 /* TapSwitchTest.swift */, 40D4E4832B97CD0A00261632 /* WorkoutTest.swift */, + 4002F0AB2B9AFC4D00AD3D47 /* MissedWorkoutTest.swift */, ); path = StrongerUITests; sourceTree = ""; @@ -920,6 +923,7 @@ 40D4E47F2B97CB9900261632 /* HomeTest.swift in Sources */, 2F4E237E2989A2FE0013F3D9 /* LaunchTests.swift in Sources */, 40D4E4822B97CBB800261632 /* TapSwitchTest.swift in Sources */, + 4002F0AC2B9AFC4D00AD3D47 /* MissedWorkoutTest.swift in Sources */, 40D4E4842B97CD0A00261632 /* WorkoutTest.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Stronger/Exercise/WorkoutSelection.swift b/Stronger/Exercise/WorkoutSelection.swift index ea80eb0..d333b1f 100644 --- a/Stronger/Exercise/WorkoutSelection.swift +++ b/Stronger/Exercise/WorkoutSelection.swift @@ -241,7 +241,7 @@ struct WorkoutSelection: View { } } - private func populateUniqueValuesSet(from documents: [QueryDocumentSnapshot]) -> Set { + private func populateUniqueValuesSet(from documents: [QueryDocumentSnapshot] = []) -> Set { var uniqueValuesSet = Set() // Iterate over documents to populate the set @@ -271,8 +271,12 @@ struct WorkoutSelection: View { if let error = error { print("Error fetching documents: \(error)") } else { + guard let querySnapshot = querySnapshot else { + print("querySnapshot is nil") + return + } // Get the count of documents - let documentCount = querySnapshot?.documents.count ?? 0 + let documentCount = querySnapshot.documents.count print("Number of documents returned: \(documentCount)") @@ -282,14 +286,14 @@ struct WorkoutSelection: View { self.selectedDay = 1 } else { // Check if there are documents with selectedDay equal to 1 - let selectedDay2Count = populateUniqueValuesSet(from: querySnapshot!.documents.filter { $0["exerciseDay"] as? Int == 2 }).count + let selectedDay2Count = populateUniqueValuesSet(from: querySnapshot.documents.filter { $0["exerciseDay"] as? Int == 2 }).count if selectedDay2Count > 3 { print("Documents found with selectedDay equal to 2. Setting selectedDay to 3.") self.selectedDay = 3 } else { // Check if there are documents with selectedDay equal to 2 let selectedDay1Count = populateUniqueValuesSet( - from: querySnapshot!.documents.filter { $0["exerciseDay"] as? Int == 1 } + from: querySnapshot.documents.filter { $0["exerciseDay"] as? Int == 1 } ).count if selectedDay1Count > 3 { print("Documents found with selectedDay equal to 1. Setting selectedDay to 2.") diff --git a/StrongerUITests/MissedWorkoutTest.swift b/StrongerUITests/MissedWorkoutTest.swift new file mode 100644 index 0000000..7cf7dcf --- /dev/null +++ b/StrongerUITests/MissedWorkoutTest.swift @@ -0,0 +1,39 @@ +//// +//// This source file is part of the Stronger based on the Stanford Spezi Template Application project +//// +//// SPDX-FileCopyrightText: 2023 Stanford University +//// +//// SPDX-License-Identifier: MIT +//// +// +//import XCTest +// +// +//class MissedWorkoutTests: XCTestCase { +// override func setUpWithError() throws { +// try super.setUpWithError() +// +// continueAfterFailure = false +// +// let app = XCUIApplication() +// app.launchArguments = ["--skipOnboarding"] +// app.launch() +// } +// +// +// func testApplicationMissedWorkouts() throws { +// let app = XCUIApplication() +// XCTAssertEqual(app.state, .runningForeground) +// +// XCTAssertTrue(app.tabBars["Tab Bar"].buttons["Workout"].waitForExistence(timeout: 2)) +// app.tabBars["Tab Bar"].buttons["Workout"].tap() +// +// XCTAssertTrue(app.buttons["Enter Missed Workout"].waitForExistence(timeout: 2)) +// app.buttons["Enter Missed Workout"].tap() +// +// +// XCTAssertTrue(app.buttons["Week 1"].waitForExistence(timeout: 2)) +// app.buttons["Week1 1"].tap() +// XCTAssertTrue(app.buttons["Week 1"].waitForExistence(timeout: 2)) +// } +//}