diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02c1c11a..91ce5c2a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,9 +75,13 @@ jobs: env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - - name: Run UI Tests on iOS + - name: Run UI Tests on iPhone if: matrix.platform == 'iOS' - run: xcodebuild test -scheme UITests_iOS -destination 'platform=iOS Simulator,name=iPhone 16 Pro' + run: xcodebuild test -scheme UITests_iPhone -destination 'platform=iOS Simulator,name=iPhone 16 Pro' + + - name: Run UI Tests on iPad + if: matrix.platform == 'iOS' + run: xcodebuild test -scheme UITests_iPad -destination 'platform=iOS Simulator,name=iPad Pro 13-inch (M4)' - name: Run UI Tests on macOS if: matrix.platform == 'macOS' diff --git a/.swiftlint.yml b/.swiftlint.yml index 9b5dc7c4..8d2a30b1 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -4,5 +4,6 @@ included: - Views/Settings/ excluded: - Support/LocalString.swift - - UITests_iOS + - UITests_iPhone + - UITests_iPad - UITests_macOS diff --git a/App/CompactViewController.swift b/App/CompactViewController.swift index 5e758f8b..b792a8cb 100644 --- a/App/CompactViewController.swift +++ b/App/CompactViewController.swift @@ -211,7 +211,7 @@ private struct CompactView: View { presentedSheet = .library(downloads: false) } label: { Label(LocalString.common_tab_menu_library, systemImage: "folder") - } + }.accessibilityIdentifier("Library") Spacer() } if !Brand.hideShareButton { 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_iOS/LoadingUI_iOS_Test.swift b/UITests_iOS/LoadingUI_iOS_Test.swift deleted file mode 100644 index f201be25..00000000 --- a/UITests_iOS/LoadingUI_iOS_Test.swift +++ /dev/null @@ -1,33 +0,0 @@ -// 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_iOS_Test: XCTestCase { - - @MainActor - func testLaunchingApp_onIPhone() throws { - let app = XCUIApplication() - app.launchArguments = ["ui_testing"] - app.activate() - app/*@START_MENU_TOKEN@*/.buttons["Library"]/*[[".otherElements.buttons[\"Library\"]",".buttons[\"Library\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap() - app/*@START_MENU_TOKEN@*/.buttons["New"]/*[[".tabBars",".buttons[\"New\"]",".buttons[\"newspaper\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[1]]@END_MENU_TOKEN@*/.tap() - app/*@START_MENU_TOKEN@*/.buttons["Downloads"]/*[[".tabBars",".buttons[\"Downloads\"]",".buttons[\"tray.and.arrow.down\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[1]]@END_MENU_TOKEN@*/.tap() - app/*@START_MENU_TOKEN@*/.buttons["Opened"]/*[[".tabBars",".buttons[\"Opened\"]",".buttons[\"folder\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[1]]@END_MENU_TOKEN@*/.tap() - app/*@START_MENU_TOKEN@*/.buttons["Categories"]/*[[".tabBars",".buttons[\"Categories\"]",".buttons[\"books.vertical\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[1]]@END_MENU_TOKEN@*/.tap() - app/*@START_MENU_TOKEN@*/.buttons["Done"]/*[[".otherElements[\"Done\"].buttons.firstMatch",".otherElements.buttons[\"Done\"]",".buttons[\"Done\"]"],[[[-1,2],[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap() - - } -} 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_iPhone/LoadingUI_iPhone_Test.swift b/UITests_iPhone/LoadingUI_iPhone_Test.swift new file mode 100644 index 00000000..a78d7c85 --- /dev/null +++ b/UITests_iPhone/LoadingUI_iPhone_Test.swift @@ -0,0 +1,46 @@ +// 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_iPhone_Test: XCTestCase { + + @MainActor + func testLaunchingApp_onIPhone() throws { + if !XCUIDevice.shared.orientation.isPortrait { + XCUIDevice.shared.orientation = .portrait + } + + let app = XCUIApplication() + app.launchArguments = ["ui_testing"] + app.activate() + + XCTAssertFalse(app.buttons["Go Back"].isEnabled) + XCTAssertFalse(app.buttons["Go Forward"].isEnabled) + XCTAssertFalse(app.buttons["Share"].isEnabled) + XCTAssertFalse(app.buttons["List"].isEnabled) + XCTAssertFalse(app.buttons["Random Page"].isEnabled) + + app.buttons["Library"].tap() + + XCTAssertTrue(app.buttons["Categories"].isSelected) + + app.buttons["New"].tap() + app.buttons["Downloads"].tap() + app.buttons["Opened"].tap() + app.buttons["Categories"].tap() + app.buttons["Done"].tap() + } +} diff --git a/UITests_macOS/LoadingUI_macOS_Test.swift b/UITests_macOS/LoadingUI_macOS_Test.swift index 04bc26ce..d6e56f05 100644 --- a/UITests_macOS/LoadingUI_macOS_Test.swift +++ b/UITests_macOS/LoadingUI_macOS_Test.swift @@ -20,13 +20,13 @@ 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() - let cellsQuery = app.cells - cellsQuery/*@START_MENU_TOKEN@*/.containing(.staticText, identifier: "Opened").firstMatch/*[[".element(boundBy: 3)",".containing(.staticText, identifier: \"Opened\").firstMatch"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.click() - cellsQuery/*@START_MENU_TOKEN@*/.containing(.staticText, identifier: "Categories").firstMatch/*[[".element(boundBy: 4)",".containing(.staticText, identifier: \"Categories\").firstMatch"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.click() - app/*@START_MENU_TOKEN@*/.staticTexts["Downloads"]/*[[".cells.staticTexts[\"Downloads\"]",".staticTexts[\"Downloads\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.click() - cellsQuery/*@START_MENU_TOKEN@*/.containing(.staticText, identifier: "New").firstMatch/*[[".element(boundBy: 6)",".containing(.staticText, identifier: \"New\").firstMatch"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.click() + app.staticTexts["Bookmarks"].click() + app.staticTexts["Opened"].click() + app.staticTexts["Categories"].click() + app.staticTexts["Downloads"].click() + app.staticTexts["New"].click() } } diff --git a/project.yml b/project.yml index 8e5f8c17..1b80d53f 100644 --- a/project.yml +++ b/project.yml @@ -153,7 +153,7 @@ targets: dependencies: - target: Kiwix - UITests_iOS: + UITests_iPhone: type: bundle.ui-testing supportedDestinations: [iOS] settings: @@ -163,7 +163,21 @@ targets: entitlements: path: Support/Kiwix-unitTest.entitlements sources: - - path: UITests_iOS + - path: UITests_iPhone + 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 @@ -189,12 +203,21 @@ schemes: - UITests_macOS commandLineArguments: testing: true - UITests_iOS: + UITests_iPhone: build: targets: Kiwix: all test: targets: - - UITests_iOS + - UITests_iPhone + commandLineArguments: + testing: true + UITests_iPad: + build: + targets: + Kiwix: all + test: + targets: + - UITests_iPad commandLineArguments: testing: true