Files
Reflect/Tests iOS/ShareNoDataTests.swift
Trey t c701bf9d3b Add 3 passing UI tests (batch 7): insights collapse, pull-to-refresh, share no data
- TC-046: Insights section collapse/expand via header tap
- TC-047: Pull-to-refresh gesture on Insights tab
- TC-119: Share with empty data handles gracefully
- Added accessibility IDs to InsightsSectionView sections and MonthView share button
- Marked 6 tests RED: TC-040 (DEBUG triple-tap), TC-041 (dead code),
  TC-091 (DEBUG paywall lab), TC-113/114/115 (SharingListView dead code)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 10:50:46 -06:00

82 lines
2.9 KiB
Swift

//
// ShareNoDataTests.swift
// Tests iOS
//
// TC-119: Share with no mood data verifies graceful behavior.
//
import XCTest
final class ShareNoDataTests: BaseUITestCase {
override var seedFixture: String? { "empty" }
override var bypassSubscription: Bool { true }
/// TC-119: With no mood data, Year view share button is absent or sharing handles empty state.
func testShare_NoData_GracefulBehavior() {
let tabBar = TabBarScreen(app: app)
tabBar.tapYear()
// Wait for year view to load
_ = app.waitForExistence(timeout: 3)
captureScreenshot(name: "share_no_data_year")
// With no mood data, there should be no year card share button
let shareButton = app.element(UITestID.Year.shareButton)
let shareExists = shareButton.waitForExistence(timeout: 3)
if shareExists {
// If the share button exists despite no data, tap it and verify
// the sharing picker handles empty state gracefully
shareButton.tapWhenReady()
_ = app.waitForExistence(timeout: 2)
captureScreenshot(name: "share_no_data_picker")
// Look for "No designs available" text or a valid picker
let noDesigns = app.staticTexts["No designs available"].firstMatch
let exitButton = app.buttons["Exit"].firstMatch
let pickerPresent = noDesigns.waitForExistence(timeout: 3) ||
exitButton.waitForExistence(timeout: 3)
// Either the picker shows empty state or renders normally
// Both are acceptable the key is no crash
if exitButton.exists {
exitButton.tap()
}
}
// Navigate to Month view and check share button there too
tabBar.tapMonth()
_ = app.waitForExistence(timeout: 3)
captureScreenshot(name: "share_no_data_month")
let monthShareButton = app.element(UITestID.Month.shareButton)
let monthShareExists = monthShareButton.waitForExistence(timeout: 3)
// With empty data, month share button should be absent
// or if present, should handle gracefully (no crash)
if monthShareExists {
monthShareButton.tapWhenReady()
_ = app.waitForExistence(timeout: 2)
captureScreenshot(name: "share_no_data_month_picker")
let exitButton = app.buttons["Exit"].firstMatch
if exitButton.waitForExistence(timeout: 3) {
exitButton.tap()
}
}
// Final verification: app is still responsive
tabBar.tapDay()
let emptyState = app.element(UITestID.Day.emptyStateNoData)
let moodHeader = app.element(UITestID.Day.moodHeader)
XCTAssertTrue(
emptyState.waitForExistence(timeout: 5) || moodHeader.waitForExistence(timeout: 2),
"App should remain functional after share-with-no-data flow"
)
}
}