Skip to content

Commit 5dc5324

Browse files
shreyadsouzaCalvin-Xushamit05Shreya D'Souza
authored
AddBabyView testing (#51)
# Merge AddBabyView Testing <img width="255" alt="Screenshot 2025-03-12 at 8 04 59 PM" src="https://github.com/user-attachments/assets/9f421b84-cf68-41d8-81ee-5f511c9c1751" /> This adds testing for AddBabyView, including delete baby functionality. ## 📝 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). --------- Co-authored-by: Pinlin [Calvin] Xu <calvinxu806@gmail.com> Co-authored-by: shamit05 <54602838+shamit05@users.noreply.github.com> Co-authored-by: Shamit Surana <shamit.surana@gmail.com> Co-authored-by: Shreya D'Souza <shreyadsouza99@gmail.com>
1 parent aa5314c commit 5dc5324

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

Feedbridge.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
2FE5DCB129EE6107004B9AB4 /* AccountOnboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FE5DCAC29EE6107004B9AB4 /* AccountOnboarding.swift */; };
4646
2FF53D8D2A8729D600042B76 /* FeedbridgeStandard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FF53D8C2A8729D600042B76 /* FeedbridgeStandard.swift */; };
4747
35B62D5D2D80C20C0096904E /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35B62D5C2D80C20C0096904E /* SettingsView.swift */; };
48+
35B62F7A2D8257EC0096904E /* AddBabyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35B62F792D8257E80096904E /* AddBabyTests.swift */; };
4849
53F30C282D7FBB670077FD21 /* AddDataViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53F30C272D7FBB670077FD21 /* AddDataViewTests.swift */; };
4950
5680DD3E2AB8CD84004E6D4A /* ContributionsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5680DD3D2AB8CD84004E6D4A /* ContributionsTest.swift */; };
5051
56E708352BB06B7100B08F0A /* SpeziLicense in Frameworks */ = {isa = PBXBuildFile; productRef = 56E708342BB06B7100B08F0A /* SpeziLicense */; };
@@ -113,6 +114,7 @@
113114
2FF53D8C2A8729D600042B76 /* FeedbridgeStandard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedbridgeStandard.swift; sourceTree = "<group>"; };
114115
358F60B12D73FEE000721B85 /* DashboardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardView.swift; sourceTree = "<group>"; };
115116
35B62D5C2D80C20C0096904E /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
117+
35B62F792D8257E80096904E /* AddBabyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddBabyTests.swift; sourceTree = "<group>"; };
116118
35E52D2B2D794472005A6BB7 /* WeightCharts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeightCharts.swift; sourceTree = "<group>"; };
117119
35E52D302D79475E005A6BB7 /* StoolCharts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoolCharts.swift; sourceTree = "<group>"; };
118120
35E52D332D7947D3005A6BB7 /* StoolsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoolsView.swift; sourceTree = "<group>"; };
@@ -338,6 +340,7 @@
338340
653A256A28338800005D4D48 /* FeedbridgeUITests */ = {
339341
isa = PBXGroup;
340342
children = (
343+
35B62F792D8257E80096904E /* AddBabyTests.swift */,
341344
53F30C272D7FBB670077FD21 /* AddDataViewTests.swift */,
342345
2F4E237D2989A2FE0013F3D9 /* OnboardingTests.swift */,
343346
653A256B28338800005D4D48 /* SchedulerTests.swift */,
@@ -612,6 +615,7 @@
612615
53F30C282D7FBB670077FD21 /* AddDataViewTests.swift in Sources */,
613616
2F4E237E2989A2FE0013F3D9 /* OnboardingTests.swift in Sources */,
614617
653A256C28338800005D4D48 /* SchedulerTests.swift in Sources */,
618+
35B62F7A2D8257EC0096904E /* AddBabyTests.swift in Sources */,
615619
);
616620
runOnlyForDeploymentPostprocessing = 0;
617621
};
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//
2+
// AddBabyTests.swift
3+
// Feedbridge
4+
//
5+
// Created by Shreya D'Souza on 3/11/25.
6+
//
7+
// SPDX-FileCopyrightText: 2025 Stanford University
8+
//
9+
// SPDX-License-Identifier: MIT
10+
//
11+
12+
import XCTest
13+
import XCTestExtensions
14+
15+
@MainActor
16+
class AddBabyTests: XCTestCase {
17+
/// Sets up the test environment before each test case.
18+
/// Ensures that there are no existing babies and launches the app with test configurations.
19+
override func setUp() async throws {
20+
continueAfterFailure = false
21+
22+
let app = XCUIApplication()
23+
app.launchArguments = ["--setupTestAccount", "--skipOnboarding"]
24+
app.deleteAndLaunch(withSpringboardAppName: "Feedbridge")
25+
26+
// Clear existing babies before each test
27+
deleteAllBabies(app)
28+
}
29+
30+
/// Deletes all babies using the UI delete button, ensuring a clean state before each test.
31+
/// - Parameter app: The XCUIApplication instance.
32+
private func deleteAllBabies(_ app: XCUIApplication) {
33+
app.buttons["Settings"].tap()
34+
35+
let deleteButton = app.buttons["Delete Baby, Delete Baby"]
36+
37+
// If the delete button exists, repeatedly tap it to remove all babies
38+
while deleteButton.waitForExistence(timeout: 2) {
39+
deleteButton.tap()
40+
app.buttons["Delete"].tap()
41+
}
42+
}
43+
44+
/// Tests the process of adding a new baby and verifying that the baby is correctly displayed in the UI.
45+
func testAddBaby() {
46+
let app = XCUIApplication()
47+
app.buttons["Settings"].tap()
48+
49+
// Verify initial state: No baby should be selected
50+
XCTAssertTrue(app.staticTexts["Select Baby"].exists, "Select baby dropdown should be visible")
51+
XCTAssertTrue(app.staticTexts["No baby selected"].exists, "No babies should exist")
52+
53+
// Open the dropdown menu and select "Add New Baby"
54+
let dropdown = app.buttons["Baby icon, Select Baby, Menu dropdown"]
55+
dropdown.tap()
56+
let addNew = app.buttons["Add New Baby"]
57+
XCTAssertTrue(addNew.exists, "Should be an option to add a baby")
58+
addNew.tap()
59+
60+
// Ensure that the Save button is initially disabled
61+
let saveButton = app.buttons["Save"]
62+
XCTAssertFalse(saveButton.isEnabled, "Save button should be disabled initially")
63+
64+
// Enter baby's name
65+
let nameField = app.textFields["Baby's Name"]
66+
nameField.tap()
67+
nameField.typeText("Benjamin")
68+
69+
// Verify that a duplicate name warning is not displayed
70+
XCTAssertFalse(app.staticTexts["This name is already taken"].exists, "Duplicate name warning should not appear")
71+
72+
// Date Picker: Select March 2025 (valid past date)
73+
let datePickersQuery = app.datePickers.firstMatch
74+
datePickersQuery.tap()
75+
app.staticTexts["1"].tap()
76+
app.buttons["PopoverDismissRegion"].tap() // Close the date picker
77+
78+
// Ensure the Save button is enabled now that valid data is entered
79+
XCTAssertTrue(saveButton.isEnabled, "Save button should be enabled when valid data is entered")
80+
81+
// Save the baby data
82+
saveButton.tap()
83+
84+
// Verify that the new baby is correctly added and displayed in the UI
85+
XCTAssertTrue(app.staticTexts["Benjamin"].exists, "Baby's name should be displayed")
86+
XCTAssertTrue(app.buttons["Baby icon, Benjamin, Menu dropdown"].exists, "Baby dropdown should show new baby")
87+
XCTAssertTrue(app.buttons["Delete Baby, Delete Baby"].exists, "Delete button should be displayed for the new baby")
88+
XCTAssertTrue(app.staticTexts["Use Kilograms"].exists, "The 'Use Kilograms' text should be displayed")
89+
}
90+
}

0 commit comments

Comments
 (0)