Skip to content

Adding UI tests #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions AppleWatch/Views/Components/WatchlistSelectorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct WatchlistSelectorView: View {
Text(list.itemTitle)
}
}
.accessibilityIdentifier("\(list.itemTitle)")
}
} header: {
Text("Your Lists")
Expand Down
54 changes: 54 additions & 0 deletions CronicaUITests/AppNavigator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// AppNavigator.swift
// CronicaUITests
//
// Created by Moataz Akram on 13/09/2024.
//

import XCTest
@testable import Cronica

final class AppNavigator {
let app: XCUIApplication

init(app: XCUIApplication) {
self.app = app
}

func navigateToTab(_ tab: Screens) {
dismissWelcomeScreenIfAppearingOnLaunch()
let tabBar = app.tabBars["Tab Bar"]

switch tab {
case .home:
tabBar.buttons["Home"].tap()
case .explore:
tabBar.buttons["Discover"].tap()
case .watchlist:
tabBar.buttons["Watchlist"].tap()
case .search:
tabBar.buttons["Search"].tap()
case .notifications:
navigateToHomeTab()
app.buttons["Notifications"].tap()
case .settings:
navigateToHomeTab()
app.buttons["Settings"].tap()
}
}

private func navigateToHomeTab() {
let tabBar = app.tabBars["Tab Bar"]
tabBar.buttons["Home"].tap()
}

func dismissWelcomeScreenIfAppearingOnLaunch() {
let welcomeViewPredicate = NSPredicate(format: "identifier == 'Welcome View'")
let welcomeView = app.otherElements.containing(welcomeViewPredicate).firstMatch
let continueButton = welcomeView.buttons["Continue"]
if continueButton.exists {
continueButton.tap()
}
}

}
87 changes: 87 additions & 0 deletions CronicaUITests/CronicaUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// CronicaUITests.swift
// CronicaUITests
//
// Created by Moataz Akram on 08/09/2024.
//

@testable import Cronica
import XCTest

final class CronicaUITests: XCTestCase {
var app: XCUIApplication!
var appNavigator: AppNavigator!
override func setUp() {
super.setUp()
app = XCUIApplication()
app.launch()
appNavigator = AppNavigator(app: app)
}

override func tearDown() {
app = nil
appNavigator = nil
super.tearDown()
}

func testHomeScreen() {
appNavigator.navigateToTab(.home)

let homeViewPredicate = NSPredicate(format: "identifier == 'Home View'")
let homeView = app.otherElements.containing(homeViewPredicate).firstMatch

let exists = homeView.waitForExistence(timeout: 1)
XCTAssertTrue(exists, "Home View should appear.")
}

func testDiscoverScreen() {
appNavigator.navigateToTab(.explore)

let homeViewPredicate = NSPredicate(format: "identifier == 'Discover View'")
let homeView = app.otherElements.containing(homeViewPredicate).firstMatch

let exists = homeView.waitForExistence(timeout: 1)
XCTAssertTrue(exists, "Discover View should appear.")
}

func testWatchListScreen() {
appNavigator.navigateToTab(.watchlist)

let watchlistViewPredicate = NSPredicate(format: "identifier == 'Watchlist View'")
let watchlistView = app.otherElements.containing(watchlistViewPredicate).firstMatch

let exists = watchlistView.waitForExistence(timeout: 1)
XCTAssertTrue(exists, "Watchlist View should appear.")
}

func testSearchScreen() {
appNavigator.navigateToTab(.search)

let searchViewPredicate = NSPredicate(format: "identifier == 'Search View'")
let searchView = app.otherElements.containing(searchViewPredicate).firstMatch

let exists = searchView.waitForExistence(timeout: 1)
XCTAssertTrue(exists, "Search View should appear.")
}

func testSettingsScreen() {
appNavigator.navigateToTab(.settings)

let settingsViewPredicate = NSPredicate(format: "identifier == 'Settings View'")
let settingsView = app.otherElements.containing(settingsViewPredicate).firstMatch

let exists = settingsView.waitForExistence(timeout: 1)
XCTAssertTrue(exists, "Settings View should appear.")
}

func testNotificationListScreen() {
appNavigator.navigateToTab(.notifications)

let notificationListViewPredicate = NSPredicate(format: "identifier == 'Notification List View'")
let notificationListView = app.otherElements.containing(notificationListViewPredicate).firstMatch

let exists = notificationListView.waitForExistence(timeout: 1)
XCTAssertTrue(exists, "Notification List should appear.")
}

}
32 changes: 32 additions & 0 deletions CronicaUITests/CronicaUITestsLaunchTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// CronicaUITestsLaunchTests.swift
// CronicaUITests
//
// Created by Moataz Akram on 08/09/2024.
//

import XCTest

final class CronicaUITestsLaunchTests: XCTestCase {

override class var runsForEachTargetApplicationUIConfiguration: Bool {
true
}

override func setUpWithError() throws {
continueAfterFailure = false
}

func testLaunch() throws {
let app = XCUIApplication()
app.launch()

// Insert steps here to perform after app launch but before taking a screenshot,
// such as logging into a test account or navigating somewhere in the app

let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.name = "Launch Screen"
attachment.lifetime = .keepAlways
add(attachment)
}
}
76 changes: 76 additions & 0 deletions CronicaUITests/HomeUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// HomeUITests.swift
// CronicaUITests
//
// Created by Moataz Akram on 12/09/2024.
//

import XCTest
@testable import Cronica

final class HomeUITests: XCTestCase {
var app: XCUIApplication!
var appNavigator: AppNavigator!

override func setUp() {
super.setUp()
app = XCUIApplication()
app.launchArguments.append("--mock-data")
app.launch()
appNavigator = AppNavigator(app: app)
}

override func tearDown() {
app = nil
appNavigator = nil
super.tearDown()
}

func testFullHomeScreen() {
appNavigator.navigateToTab(.home)

let navigationHomeTitle = app.navigationBars["Home"].staticTexts["Home"]
XCTAssertTrue(navigationHomeTitle.exists)

// MARK: Trending section -> do not appear when no internet connection
let trendingTitle = app.staticTexts["Trending"]
XCTAssertTrue(trendingTitle.exists)
let todaySubtitle = app.staticTexts["Today"]
XCTAssertTrue(todaySubtitle.exists)

let trendingList = app.scrollViews["Trending Horizontal List"]
XCTAssertTrue(trendingList.exists, "Trending List should appear.")

// MARK: Upcoming section
let upcomingTitle = app.staticTexts["Up Coming"]
XCTAssertTrue(upcomingTitle.exists)
let upcomingSubtitle = app.staticTexts["Coming Soon To Theaters"]
XCTAssertTrue(upcomingSubtitle.exists)

let upcomingList = app.scrollViews["Up Coming Horizontal List"]
if !upcomingList.exists {
app.swipeUp()
}
XCTAssertTrue(upcomingList.exists, "Up Coming List should appear.")

// MARK: Latest Movies section
let latestMoviesTitle = app.staticTexts["Latest Movies"]
XCTAssertTrue(latestMoviesTitle.exists)
let latestMoviesSubtitle = app.staticTexts["Recently Released"]
XCTAssertTrue(latestMoviesSubtitle.exists)

let latestMoviesList = app.scrollViews["Latest Movies Horizontal List"]
if !latestMoviesList.exists {
app.swipeUp()
}
XCTAssertTrue(latestMoviesList.exists, "Latest Movies List should appear.")

// MARK: bottom section
app.swipeUp()
let tmdbImage = app.images["PrimaryCompact"].firstMatch
XCTAssertTrue(tmdbImage.exists)
let bottomText = app.staticTexts["This product uses the TMDb API but is not endorsed or certified by TMDb."]
XCTAssertTrue(bottomText.exists)
}

}
Loading