generated from StanfordSpezi/SpeziTemplateApplication
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assessments tests and minor fixes (#56)
# Assessments tests and minor fixes ## ♻️ Current situation & Problem Currently, we only implement the assessments tab for #44 but we did not write any tests to test it. Therefore, this PR aims to add the UI and uni tests for the assessments tab, including each of the tasks and the visualization of results. Currently, we only test creating the task for trail making and reaction time task as described below, but we reach the desired test coverage and 539 out of 589 lines (~91.5%) in the assessment folder are covered. This PR also includes some small fixes described below. ## ⚙️ Release Notes - tests the assessment tasks. Currently, we run through the Stroop task during the UI task and only test creating tasks for (1) trail-making task as we are unable to click the buttons to make trails as they are not shown in the app but grouped into an Other element `Tappable Buttons` and (2) reaction time as currently there is no supports for the shake motion in testing. This should be acceptable as the process of the two tasks is also solely handled by the ResaerchKit, and we only wrote functions to create and parse the results. - Add the additional unit task to the function parsing the trail-making task to ensure that no error is returned - We are missing tests for parsing the reaction time result as the simulator does not support result files, which is required when parsing the reaction time result. Other fixes - Fix some colors for the dark mode for HealthKit visualizations. - Fix the issue that the running task occurs on both the main screen and the sheet. Change the toggle showingTestSheet to directly setting to true to avoid the sheet not re-rendering (always showing trail-making task) issue. - Do not show chart legend for score/error count if those data are not collected. <img width="200" alt="image" src="https://github.com/CS342/2024-PICS/assets/32094663/bd943430-d570-4dfa-952a-9cc0f5b2430c"> ## 📚 Documentation Related commends are added to the codes. ## ✅ Testing The PR adds tests to our codes. ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
Showing
9 changed files
with
235 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// This source file is part of the PICS based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
@testable import PICS | ||
import ResearchKit | ||
import XCTest | ||
|
||
|
||
class AssessmentsUnitTests: XCTestCase { | ||
// Test tha the trail making test result could be parsed correctly without error. | ||
func testParseTMResult() throws { | ||
// Create the task result object with trail making results. | ||
let taskResult = ORKTaskResult(taskIdentifier: "TestTMTaskResult", taskRun: UUID(), outputDirectory: nil) | ||
|
||
let tmResult = ORKTrailmakingResult(identifier: "tmResult") | ||
tmResult.numberOfErrors = 10 | ||
let tmTap1 = ORKTrailmakingTap() | ||
tmTap1.timestamp = 20 | ||
let tmTap2 = ORKTrailmakingTap() | ||
tmTap2.timestamp = 30 | ||
tmResult.taps = [tmTap1, tmTap2] | ||
|
||
let tmStepResult = ORKStepResult(stepIdentifier: "trailmaking", results: [tmResult]) | ||
taskResult.results = [tmStepResult] | ||
|
||
if let parsedResult = parseTMResult(taskResult: taskResult) { | ||
// The correct timestamp is the one from the last tap. | ||
XCTAssertEqual(parsedResult.timeSpent, 30) | ||
XCTAssertEqual(parsedResult.errorCnt, 10) | ||
} else { | ||
// Failed to parse the result. | ||
XCTAssert(true) | ||
} | ||
} | ||
} |
Oops, something went wrong.