//
//  EntryDetailTests.swift
//  Tests iOS
//
//  Entry detail sheet open/dismiss and mood change tests.
//

import XCTest

final class EntryDetailTests: BaseUITestCase {
    override var seedFixture: String? { "week_of_moods" }

    /// Tap an entry row -> Entry Detail sheet opens -> dismiss it.
    func testTapEntry_OpensDetailSheet_Dismiss() {
        // Find the first entry row by identifier prefix
        let firstEntry = app.firstEntryRow

        guard firstEntry.waitForExistence(timeout: 5) else {
            XCTFail("No entry rows found in seeded data")
            return
        }

        firstEntry.tap()

        let detailScreen = EntryDetailScreen(app: app)
        detailScreen.assertVisible()

        captureScreenshot(name: "entry_detail_open")

        // Dismiss the sheet
        detailScreen.dismiss()
        detailScreen.assertDismissed()
    }

    /// Open entry detail and change mood, then dismiss.
    func testChangeMood_ViaEntryDetail() {
        let firstEntry = app.firstEntryRow

        guard firstEntry.waitForExistence(timeout: 5) else {
            XCTFail("No entry rows found in seeded data")
            return
        }

        firstEntry.tap()

        let detailScreen = EntryDetailScreen(app: app)
        detailScreen.assertVisible()

        // Select a different mood (Bad)
        detailScreen.selectMood(.bad)

        captureScreenshot(name: "mood_changed_to_bad")

        // Dismiss
        detailScreen.dismiss()
        detailScreen.assertDismissed()
    }
}
