Files
Reflect/Tests iOS/PremiumCustomizationTests.swift
Trey T d97db4910e Rewrite all UI tests following fail-fast TEST_RULES patterns
Rewrote 60+ test files to follow honeydue-style test guidelines:
- defaultTimeout=2s, navigationTimeout=5s — fail fast, no long waits
- No coordinate taps (except onboarding paged TabView swipes)
- No sleep(), no retry loops
- No guard...else { return } silent passes — XCTFail everywhere
- All elements by accessibility ID via UITestID constants
- Screen objects for all navigation/actions/assertions
- One logical assertion per test method

Added missing accessibility identifiers to app views:
- MonthView.swift: added AccessibilityID.MonthView.grid to ScrollView
- YearView.swift: added AccessibilityID.YearView.heatmap to ScrollView

Framework rewrites:
- BaseUITestCase: added session ID, localeArguments, extraLaunchArguments
- WaitHelpers: waitForExistenceOrFail, waitUntilHittableOrFail,
  waitForNonExistence, scrollIntoView, forceTap
- All 7 screen objects rewritten with fail-fast semantics
- TEST_RULES.md added with non-negotiable rules

Known remaining issues:
- OnboardingTests: paged TabView swipes unreliable on iOS 26 simulator
- SettingsLegalLinksTests: EULA/Privacy buttons too deep in DEBUG scroll
- Customization horizontal picker scrolling needs further tuning

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 17:00:30 -05:00

82 lines
3.0 KiB
Swift

//
// PremiumCustomizationTests.swift
// Tests iOS
//
// Premium customization gate tests: verify upgrade banner and subscribe
// button appear when trial is expired and user is not subscribed.
// TC-075
//
import XCTest
final class PremiumCustomizationTests: BaseUITestCase {
override var seedFixture: String? { "single_mood" }
override var bypassSubscription: Bool { false }
override var expireTrial: Bool { true }
/// TC-075: Upgrade banner visible on Customize tab when trial expired.
func testCustomizeTab_UpgradeBannerVisible_WhenTrialExpired() {
let settingsScreen = TabBarScreen(app: app).tapSettings()
settingsScreen.assertVisible()
settingsScreen.assertUpgradeBannerVisible()
captureScreenshot(name: "customize_upgrade_banner")
}
/// TC-075: Subscribe button visible on Customize tab when trial expired.
func testCustomizeTab_SubscribeButtonVisible_WhenTrialExpired() {
let settingsScreen = TabBarScreen(app: app).tapSettings()
settingsScreen.assertVisible()
settingsScreen.subscribeButton
.waitForExistenceOrFail(
timeout: navigationTimeout,
message: "Subscribe button should be visible when trial is expired"
)
captureScreenshot(name: "customize_subscribe_button")
}
/// TC-075: Tapping subscribe button opens subscription sheet without crash.
func testCustomizeTab_SubscribeButtonOpensSheet() {
let settingsScreen = TabBarScreen(app: app).tapSettings()
settingsScreen.assertVisible()
settingsScreen.subscribeButton
.waitUntilHittableOrFail(timeout: navigationTimeout, message: "Subscribe button should be hittable")
.forceTap()
// Verify the subscription sheet appears without crashing.
// StoreKit may not load products in test environments, so just verify
// we didn't crash and can still interact with the app after dismissing.
captureScreenshot(name: "subscription_sheet_opened")
// Dismiss the sheet
app.swipeDown()
// Verify we can still see the settings screen (no crash)
settingsScreen.assertVisible()
captureScreenshot(name: "settings_after_subscription_sheet_dismissed")
}
/// TC-075: Settings sub-tab shows upgrade CTA when trial expired.
func testSettingsSubTab_ShowsPaywallGate_WhenTrialExpired() {
let settingsScreen = TabBarScreen(app: app).tapSettings()
settingsScreen.assertVisible()
settingsScreen.tapSettingsTab()
// Either the upgrade banner or subscribe button should be present
let bannerExists = settingsScreen.upgradeBanner.waitForExistence(timeout: navigationTimeout)
let buttonExists = settingsScreen.subscribeButton.waitForExistence(timeout: defaultTimeout)
XCTAssertTrue(
bannerExists || buttonExists,
"Settings sub-tab should show upgrade CTA when trial is expired"
)
captureScreenshot(name: "settings_subtab_paywall_gate")
}
}