Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions Bedtime/Bedtime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@
objectVersion = 77;
objects = {

/* Begin PBXContainerItemProxy section */
373AAF072E91B7E900D8ED84 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 373AAED52E91B7E900D8ED84 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 373AAEDC2E91B7E900D8ED84;
remoteInfo = Bedtime;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
373AAEDD2E91B7E900D8ED84 /* Bedger.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Bedger.app; sourceTree = BUILT_PRODUCTS_DIR; };
373AAF022E91B7E900D8ED84 /* BedtimeUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BedtimeUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFileSystemSynchronizedRootGroup section */
Expand All @@ -16,6 +27,11 @@
path = Bedtime;
sourceTree = "<group>";
};
373AAF012E91B7E900D8ED84 /* BedtimeUITests */ = {
isa = PBXFileSystemSynchronizedRootGroup;
path = BedtimeUITests;
sourceTree = "<group>";
};
/* End PBXFileSystemSynchronizedRootGroup section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -26,13 +42,21 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
373AAF052E91B7E900D8ED84 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
373AAED42E91B7E900D8ED84 = {
isa = PBXGroup;
children = (
373AAEDF2E91B7E900D8ED84 /* Bedtime */,
373AAF012E91B7E900D8ED84 /* BedtimeUITests */,
373AAEDE2E91B7E900D8ED84 /* Products */,
);
sourceTree = "<group>";
Expand All @@ -41,6 +65,7 @@
isa = PBXGroup;
children = (
373AAEDD2E91B7E900D8ED84 /* Bedger.app */,
373AAF022E91B7E900D8ED84 /* BedtimeUITests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -70,6 +95,29 @@
productReference = 373AAEDD2E91B7E900D8ED84 /* Bedger.app */;
productType = "com.apple.product-type.application";
};
373AAF032E91B7E900D8ED84 /* BedtimeUITests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 373AAF092E91B7EA00D8ED84 /* Build configuration list for PBXNativeTarget "BedtimeUITests" */;
buildPhases = (
373AAF042E91B7E900D8ED84 /* Sources */,
373AAF052E91B7E900D8ED84 /* Frameworks */,
373AAF062E91B7E900D8ED84 /* Resources */,
);
buildRules = (
);
dependencies = (
373AAF082E91B7E900D8ED84 /* PBXTargetDependency */,
);
fileSystemSynchronizedGroups = (
373AAF012E91B7E900D8ED84 /* BedtimeUITests */,
);
name = BedtimeUITests;
packageProductDependencies = (
);
productName = BedtimeUITests;
productReference = 373AAF022E91B7E900D8ED84 /* BedtimeUITests.xctest */;
productType = "com.apple.product-type.bundle.ui-testing";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
Expand All @@ -83,6 +131,10 @@
373AAEDC2E91B7E900D8ED84 = {
CreatedOnToolsVersion = 26.0;
};
373AAF032E91B7E900D8ED84 = {
CreatedOnToolsVersion = 26.0;
TestTargetID = 373AAEDC2E91B7E900D8ED84;
};
};
};
buildConfigurationList = 373AAED82E91B7E900D8ED84 /* Build configuration list for PBXProject "Bedtime" */;
Expand All @@ -100,6 +152,7 @@
projectRoot = "";
targets = (
373AAEDC2E91B7E900D8ED84 /* Bedtime */,
373AAF032E91B7E900D8ED84 /* BedtimeUITests */,
);
};
/* End PBXProject section */
Expand All @@ -112,6 +165,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
373AAF062E91B7E900D8ED84 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand All @@ -122,8 +182,23 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
373AAF042E91B7E900D8ED84 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
373AAF082E91B7E900D8ED84 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 373AAEDC2E91B7E900D8ED84 /* Bedtime */;
targetProxy = 373AAF072E91B7E900D8ED84 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin XCBuildConfiguration section */
373AAEEC2E91B7EA00D8ED84 /* Debug */ = {
isa = XCBuildConfiguration;
Expand Down Expand Up @@ -322,6 +397,42 @@
};
name = Release;
};
373AAF0A2E91B7EA00D8ED84 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 9J44X82D53;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 0.9.0;
PRODUCT_BUNDLE_IDENTIFIER = com.burnsides.bedtime.uitests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = Bedtime;
};
name = Debug;
};
373AAF0B2E91B7EA00D8ED84 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 9J44X82D53;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
MARKETING_VERSION = 0.9.0;
PRODUCT_BUNDLE_IDENTIFIER = com.burnsides.bedtime.uitests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = Bedtime;
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand All @@ -343,6 +454,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
373AAF092E91B7EA00D8ED84 /* Build configuration list for PBXNativeTarget "BedtimeUITests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
373AAF0A2E91B7EA00D8ED84 /* Debug */,
373AAF0B2E91B7EA00D8ED84 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 373AAED52E91B7E900D8ED84 /* Project object */;
Expand Down
6 changes: 6 additions & 0 deletions Bedtime/Bedtime/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ struct ContentView: View {
.frame(maxWidth: 600)
.frame(maxWidth: .infinity)
}
.accessibilityIdentifier("home_screen")
.background(Color.backgroundBehindCards)
.navigationTitle("Bedger")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button("Settings", systemImage: "gear") {
showingSettings.toggle()
}
.accessibilityIdentifier("settings_button")
}
}
.refreshable {
Expand All @@ -125,6 +127,10 @@ struct ContentView: View {
}
}
.task {
#if DEBUG
healthKitManager.prepareForUITestingIfNeeded()
guard !UITestingSupport.isActive else { return }
#endif
try? await healthKitManager.fetchSleepData()
}
}
Expand Down
9 changes: 9 additions & 0 deletions Bedtime/Bedtime/Models/HealthKitManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,13 @@ class HealthKitManager: ObservableObject {

self.sleepSessions = Dictionary(grouping: sessions) { $0.dateForGrouping }
}

#if DEBUG
func prepareForUITestingIfNeeded() {
guard UITestingSupport.isActive else { return }
isAuthorized = true
sleepSessions = UITestingSupport.mockSleepSessions()
errorMessage = nil
}
#endif
}
57 changes: 57 additions & 0 deletions Bedtime/Bedtime/Support/UITestingSupport.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#if DEBUG
import Foundation
import HealthKit

enum UITestingSupport {
static var isActive: Bool {
ProcessInfo.processInfo.arguments.contains("-ui_testing")
}

static func mockSleepSessions() -> [Date: [SleepSession]] {
let source = HKSourceRevision(source: HKSource.default(), version: nil)
let calendar = Calendar.current
let today = calendar.startOfDay(for: Date())

func session(
dayOffset: Int,
startHour: Int,
startMinute: Int,
endHour: Int,
endMinute: Int
) -> SleepSession {
let base = calendar.date(byAdding: .day, value: dayOffset, to: today) ?? today
let start = calendar.date(
bySettingHour: startHour,
minute: startMinute,
second: 0,
of: base
) ?? base
let endDayOffset = endHour < startHour ? 1 : 0
let endBase = calendar.date(byAdding: .day, value: endDayOffset, to: base) ?? base
let end = calendar.date(
bySettingHour: endHour,
minute: endMinute,
second: 0,
of: endBase
) ?? endBase

return SleepSession(
startDate: start,
endDate: end,
sleepType: .asleepCore,
source: source
)
}

let lastNight = session(dayOffset: -1, startHour: 23, startMinute: 15, endHour: 7, endMinute: 5)
let twoNightsAgo = session(dayOffset: -2, startHour: 22, startMinute: 45, endHour: 6, endMinute: 30)
let threeNightsAgo = session(dayOffset: -3, startHour: 23, startMinute: 30, endHour: 7, endMinute: 45)

return [
lastNight.dateForGrouping: [lastNight],
twoNightsAgo.dateForGrouping: [twoNightsAgo],
threeNightsAgo.dateForGrouping: [threeNightsAgo],
]
}
}
#endif
1 change: 1 addition & 0 deletions Bedtime/Bedtime/Views/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ struct SettingsView: View {
}
.navigationTitle("Settings")
.navigationBarTitleDisplayMode(.inline)
.accessibilityIdentifier("settings_screen")
.toolbar {
if horizontalSizeClass == .compact {
ToolbarItem(placement: .confirmationAction) {
Expand Down
31 changes: 31 additions & 0 deletions Bedtime/BedtimeUITests/ScreenshotTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import XCTest

/// UI tests that capture screenshots for pull request previews.
///
/// Screenshots are saved as XCTAttachments with `.keepAlways` so Xcode Cloud
/// includes them in the test result bundle. `ci_post_xcodebuild.sh` can then
/// upload them to Imgur (or another host) and embed the URLs in a PR comment.
final class ScreenshotTests: XCTestCase {

override func setUpWithError() throws {
continueAfterFailure = false
}

@MainActor
func testPullRequestScreenshots() throws {
let app = XCUIApplication()
app.launchArguments.append("-ui_testing")
app.launch()

XCTAssertTrue(app.scrollViews["home_screen"].waitForExistence(timeout: 10))
attachScreenshot(named: "01-home", in: app)

app.buttons["settings_button"].tap()
XCTAssertTrue(app.navigationBars["Settings"].waitForExistence(timeout: 5))
attachScreenshot(named: "02-settings", in: app)

if app.buttons["Done"].exists {
app.buttons["Done"].tap()
}
}
}
10 changes: 10 additions & 0 deletions Bedtime/BedtimeUITests/XCTestCase+Screenshots.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import XCTest

extension XCTestCase {
func attachScreenshot(named name: String, in app: XCUIApplication, file: StaticString = #filePath, line: UInt = #line) {
let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.name = name
attachment.lifetime = .keepAlways
add(attachment)
}
}
Loading