diff --git a/Game-2048UITests/Game_2048UITests.swift b/Game-2048UITests/Game_2048UITests.swift index 2df0880..d33cedf 100644 --- a/Game-2048UITests/Game_2048UITests.swift +++ b/Game-2048UITests/Game_2048UITests.swift @@ -9,32 +9,56 @@ import XCTest final class Game_2048UITests: XCTestCase { - override func setUpWithError() throws { - // Put setup code here. This method is called before the invocation of each test method in the class. + var app: XCUIApplication! - // In UI tests it is usually best to stop immediately when a failure occurs. + override func setUpWithError() throws { + // Initialize the app before each test method + app = XCUIApplication() continueAfterFailure = false - - // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + app.launch() } override func tearDownWithError() throws { - // Put teardown code here. This method is called after the invocation of each test method in the class. + // Clean up after each test method + app = nil } - func testExample() throws { - // UI tests must launch the application that they test. - let app = XCUIApplication() - app.launch() + func testLaunchScreenAndTransitionToGameView() throws { + // Verify the app starts on the LaunchScreen + let titleText = app.staticTexts["2048"] + XCTAssertTrue(titleText.exists, "The 2048 title should be visible on the launch screen.") + + // Verify the transition to the GameView after 2 seconds + let exists = NSPredicate(format: "exists == 1") + let gameViewText = app.staticTexts["Score"] // Assuming 'Score' is visible in GameView + expectation(for: exists, evaluatedWith: gameViewText, handler: nil) + + waitForExpectations(timeout: 3) { error in + if error != nil { + XCTFail("GameView did not appear after the launch screen.") + } + } + } + + func testGamePlaySwipeLeft() throws { + // Ensure we're on the GameView + let scoreLabel = app.staticTexts["Score"] + XCTAssertTrue(scoreLabel.exists, "Game should be on the GameView after the launch screen.") + + // Perform a swipe left gesture + let gameBoard = app.otherElements["GameBoard"] // Ensure the GameView has the correct accessibility identifier set for the grid/board + gameBoard.swipeLeft() - // Use XCTAssert and related functions to verify your tests produce the correct results. + // Since it's hard to predict specific gameplay results in a UI test, verify that the score label updates + let scoreValue = scoreLabel.label + XCTAssertNotEqual(scoreValue, "0", "Score should update after swiping left.") } func testLaunchPerformance() throws { if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { - // This measures how long it takes to launch your application. + // Measures how long it takes to launch the app. measure(metrics: [XCTApplicationLaunchMetric()]) { - XCUIApplication().launch() + app.launch() } } }