diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cacd422a..0baa8d1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,6 +79,10 @@ jobs: if: matrix.platform == 'iOS' run: xcodebuild test -scheme UITests_iPhone -destination 'platform=iOS Simulator,name=iPhone 16 Pro' + - name: Run UI Tests on iPhone + if: matrix.platform == 'iOS' + run: xcodebuild test -scheme UITests_iPad -destination 'platform=iOS Simulator,name=iPad Pro 13-inch' + - name: Run UI Tests on macOS if: matrix.platform == 'macOS' run: xcodebuild test -scheme UITests_macOS -destination 'platform=macOS' diff --git a/App/SidebarViewController.swift b/App/SidebarViewController.swift index ec68628c..1c92918d 100644 --- a/App/SidebarViewController.swift +++ b/App/SidebarViewController.swift @@ -72,6 +72,7 @@ final class SidebarViewController: UICollectionViewController, NSFetchedResultsC init() { super.init(collectionViewLayout: UICollectionViewLayout()) + collectionView.accessibilityIdentifier = "sidebar_collection_view" collectionView.collectionViewLayout = UICollectionViewCompositionalLayout { _, layoutEnvironment in var config = UICollectionLayoutListConfiguration(appearance: .sidebar) config.headerMode = .supplementary @@ -244,6 +245,7 @@ final class SidebarViewController: UICollectionViewController, NSFetchedResultsC config.image = UIImage(systemName: item.icon) config.imageProperties.tintColor = item.iconForegroundColor cell.contentConfiguration = config + cell.accessibilityIdentifier = item.accessibilityIdentifier } } diff --git a/SwiftUI/Model/Enum.swift b/SwiftUI/Model/Enum.swift index 7994f63d..cf65676f 100644 --- a/SwiftUI/Model/Enum.swift +++ b/SwiftUI/Model/Enum.swift @@ -290,6 +290,27 @@ enum MenuItem: Hashable { } } + var accessibilityIdentifier: String { + switch self { + case .tab: + "tab" + case .bookmarks: + "bookmarks" + case .opened: + "opened" + case .categories: + "categories" + case .new: + "new" + case .downloads: + "downloads" + case .settings: + "settings" + case .donation: + "donation" + } + } + var icon: String { switch self { case .bookmarks: diff --git a/UITests_iPad/LoadingUI_iPad_Test.swift b/UITests_iPad/LoadingUI_iPad_Test.swift new file mode 100644 index 00000000..55008cb5 --- /dev/null +++ b/UITests_iPad/LoadingUI_iPad_Test.swift @@ -0,0 +1,45 @@ +// This file is part of Kiwix for iOS & macOS. +// +// Kiwix is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// any later version. +// +// Kiwix is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kiwix; If not, see https://www.gnu.org/licenses/. + +import XCTest + +final class LoadingUI_iPad_Test: XCTestCase { + + @MainActor + func testLaunchingApp_on_iPad() throws { + + if !XCUIDevice.shared.orientation.isLandscape { + XCUIDevice.shared.orientation = .landscapeLeft + } + + let app = XCUIApplication() + app.launchArguments = ["ui_testing"] + app.activate() + + app.buttons.matching(identifier: "ToggleSidebar").element.tap() + + let sidebar = app.collectionViews["sidebar_collection_view"] + + XCTAssert(sidebar.cells["New Tab"].isSelected) + + sidebar.cells["bookmarks"].tap() + sidebar.cells["opened"].tap() + sidebar.cells["categories"].tap() + sidebar.cells["downloads"].tap() + sidebar.cells["new"].tap() + sidebar.cells["settings"].tap() + sidebar.cells["donation"].tap() + } +} diff --git a/UITests_macOS/LoadingUI_macOS_Test.swift b/UITests_macOS/LoadingUI_macOS_Test.swift index 04bc26ce..e557fbee 100644 --- a/UITests_macOS/LoadingUI_macOS_Test.swift +++ b/UITests_macOS/LoadingUI_macOS_Test.swift @@ -20,6 +20,7 @@ final class LoadingUI_macOS_Test: XCTestCase { func testSideBarItems() throws { // UI tests must launch the application that they test. let app = XCUIApplication() + app.launchArguments = ["ui_testing"] app.activate() app/*@START_MENU_TOKEN@*/.staticTexts["Bookmarks"]/*[[".cells.staticTexts[\"Bookmarks\"]",".staticTexts[\"Bookmarks\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.click() diff --git a/project.yml b/project.yml index 3ceb0cf4..1b80d53f 100644 --- a/project.yml +++ b/project.yml @@ -167,6 +167,20 @@ targets: dependencies: - target: Kiwix + UITests_iPad: + type: bundle.ui-testing + supportedDestinations: [iOS] + settings: + PRODUCT_BUNDLE_IDENTIFIER: org.kiwix.UITests + # TEST_HOST: $(BUILT_PRODUCTS_DIR)/Kiwix.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Kiwix + BUNDLE_LOADER: $(TEST_HOST) + entitlements: + path: Support/Kiwix-unitTest.entitlements + sources: + - path: UITests_iPad + dependencies: + - target: Kiwix + schemes: Kiwix: build: @@ -198,3 +212,12 @@ schemes: - UITests_iPhone commandLineArguments: testing: true + UITests_iPad: + build: + targets: + Kiwix: all + test: + targets: + - UITests_iPad + commandLineArguments: + testing: true