| 
 | 1 | +// SPDX-FileCopyrightText: Nextcloud GmbH  | 
 | 2 | +// SPDX-FileCopyrightText: 2025 Iva Horn  | 
 | 3 | +// SPDX-License-Identifier: GPL-3.0-or-later  | 
 | 4 | + | 
 | 5 | +import XCTest  | 
 | 6 | + | 
 | 7 | +///  | 
 | 8 | +/// User interface tests for the download limits management on shares.  | 
 | 9 | +///  | 
 | 10 | +@MainActor  | 
 | 11 | +final class AutoUploadUITests: BaseUIXCTestCase {  | 
 | 12 | +    // MARK: - Lifecycle  | 
 | 13 | +    override func setUp() async throws {  | 
 | 14 | +        try await super.setUp()  | 
 | 15 | +        continueAfterFailure = false  | 
 | 16 | + | 
 | 17 | +        // Handle alerts presented by the system.  | 
 | 18 | +        addUIInterruptionMonitor(withDescription: "Allow Notifications", for: "Allow")  | 
 | 19 | +        addUIInterruptionMonitor(withDescription: "Save Password", for: "Not Now")  | 
 | 20 | + | 
 | 21 | +        // Launch the app.  | 
 | 22 | +        app = XCUIApplication()  | 
 | 23 | +        app.launchArguments = ["UI_TESTING"]  | 
 | 24 | +        app.launch()  | 
 | 25 | + | 
 | 26 | +        try await logIn()  | 
 | 27 | + | 
 | 28 | +        // Set up test backend communication.  | 
 | 29 | +        backend = UITestBackend()  | 
 | 30 | +    }  | 
 | 31 | + | 
 | 32 | +    private func goToAutoUpload() async throws {  | 
 | 33 | +        addUIInterruptionMonitor(withDescription: "Are you sure you want to upload all photos?", for: "Confirm")  | 
 | 34 | + | 
 | 35 | +        app.tabBars["Tab Bar"].buttons["More"].tap()  | 
 | 36 | + | 
 | 37 | +        app.tables/*@START_MENU_TOKEN@*/.staticTexts["Settings"]/*[[".cells.staticTexts[\"Settings\"]",".staticTexts[\"Settings\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()  | 
 | 38 | + | 
 | 39 | +        let collectionViewsQuery = app.collectionViews  | 
 | 40 | +        collectionViewsQuery/*@START_MENU_TOKEN@*/.staticTexts["Auto upload"]/*[[".cells",".buttons[\"Auto upload\"].staticTexts[\"Auto upload\"]",".staticTexts[\"Auto upload\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/.tap()  | 
 | 41 | + | 
 | 42 | +        try await aSmallMoment()  | 
 | 43 | + | 
 | 44 | +        let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")  | 
 | 45 | +        let allowButton = springboard.buttons["Allow Full Access"]  | 
 | 46 | + | 
 | 47 | +        if allowButton.await() {  | 
 | 48 | +            allowButton.tap()  | 
 | 49 | +        }  | 
 | 50 | +    }  | 
 | 51 | + | 
 | 52 | +    func testAutoUploadAllPhotos() async throws {  | 
 | 53 | +        try await goToAutoUpload()  | 
 | 54 | + | 
 | 55 | +        let collectionViewsQuery = app.collectionViews  | 
 | 56 | + | 
 | 57 | +        let turnOnAutoUploadingSwitch = collectionViewsQuery.switches["Turn on auto uploading"]  | 
 | 58 | + | 
 | 59 | +        collectionViewsQuery/*@START_MENU_TOKEN@*/.switches["Auto upload photos"]/*[[".cells.switches[\"Auto upload photos\"]",".switches[\"Auto upload photos\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.swipeUp()  | 
 | 60 | + | 
 | 61 | +        if turnOnAutoUploadingSwitch.await() {  | 
 | 62 | +            turnOnAutoUploadingSwitch.tap()  | 
 | 63 | +        }  | 
 | 64 | + | 
 | 65 | +        app.tabBars["Tab Bar"].buttons["Files"].tap()  | 
 | 66 | + | 
 | 67 | +        try await aSmallMoment()  | 
 | 68 | + | 
 | 69 | +        pullToRefresh()  | 
 | 70 | + | 
 | 71 | +        let photosItem = app.collectionViews["NCCollectionViewCommon"]/*@START_MENU_TOKEN@*/.staticTexts["Photos"]/*[[".cells[\"Photos\"].staticTexts[\"Photos\"]",".cells[\"Cell\/Photos\"].staticTexts[\"Photos\"]",".staticTexts[\"Photos\"]"],[[[-1,2],[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/  | 
 | 72 | +        if photosItem.await() {  | 
 | 73 | +            photosItem.tap()  | 
 | 74 | +        }  | 
 | 75 | + | 
 | 76 | +        try await aSmallMoment()  | 
 | 77 | +          | 
 | 78 | +        XCTAssertTrue(app.collectionViews.cells.count == 6)  | 
 | 79 | +    }  | 
 | 80 | + | 
 | 81 | +    func testAutoUploadNewPhotos() async throws {  | 
 | 82 | +        try await goToAutoUpload()  | 
 | 83 | + | 
 | 84 | +        let backUpNewPhotosVideosOnlySwitch = app.collectionViews.switches["NewPhotosToggle"]  | 
 | 85 | + | 
 | 86 | +        if backUpNewPhotosVideosOnlySwitch.await() {  | 
 | 87 | +            backUpNewPhotosVideosOnlySwitch.switches.firstMatch.tap()  | 
 | 88 | +        }  | 
 | 89 | + | 
 | 90 | +        let collectionViewsQuery = app.collectionViews  | 
 | 91 | + | 
 | 92 | +        let turnOnAutoUploadingSwitch = collectionViewsQuery.switches["Turn on auto uploading"]  | 
 | 93 | + | 
 | 94 | +        collectionViewsQuery/*@START_MENU_TOKEN@*/.switches["Auto upload photos"]/*[[".cells.switches[\"Auto upload photos\"]",".switches[\"Auto upload photos\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.swipeUp()  | 
 | 95 | + | 
 | 96 | +        if turnOnAutoUploadingSwitch.await() {  | 
 | 97 | +            turnOnAutoUploadingSwitch.tap()  | 
 | 98 | +        }  | 
 | 99 | + | 
 | 100 | +        app.tabBars["Tab Bar"].buttons["Files"].tap()  | 
 | 101 | + | 
 | 102 | +        try await aSmallMoment()  | 
 | 103 | + | 
 | 104 | +        pullToRefresh()  | 
 | 105 | + | 
 | 106 | +        let photosItem = app.collectionViews["NCCollectionViewCommon"]/*@START_MENU_TOKEN@*/.staticTexts["Photos"]/*[[".cells[\"Photos\"].staticTexts[\"Photos\"]",".cells[\"Cell\/Photos\"].staticTexts[\"Photos\"]",".staticTexts[\"Photos\"]"],[[[-1,2],[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/  | 
 | 107 | + | 
 | 108 | +        // Does not seem possible to take a screenshot on Simulator or easily transfer a new photo in Simulator.  | 
 | 109 | +        // Thus for now we can only rely on the Photos folder not existing at all to test this.  | 
 | 110 | +        XCTAssertFalse(photosItem.exists)  | 
 | 111 | +    }  | 
 | 112 | + | 
 | 113 | +    override func tearDown() async throws {  | 
 | 114 | +        let tabBar = app.tabBars["Tab Bar"]  | 
 | 115 | +        tabBar.buttons["Files"].tap()  | 
 | 116 | +        let nccollectionviewcommonCollectionView = app.collectionViews["NCCollectionViewCommon"]  | 
 | 117 | +        let cell = nccollectionviewcommonCollectionView/*@START_MENU_TOKEN@*/.cells["Cell/Photos"]/*[[".cells[\"Photos\"]",".cells[\"Cell\/Photos\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/  | 
 | 118 | +        if !cell.exists { return }  | 
 | 119 | + | 
 | 120 | +        cell.otherElements.containing(.button, identifier:"Cell/Photos/shareButton").children(matching: .button).element(boundBy: 1).tap()  | 
 | 121 | +        let tablesQuery = app.tables  | 
 | 122 | +        tablesQuery/*@START_MENU_TOKEN@*/.staticTexts["Delete folder"]/*[[".cells.staticTexts[\"Delete folder\"]",".staticTexts[\"Delete folder\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()  | 
 | 123 | +        app.alerts["Delete folder?"].scrollViews.otherElements.buttons["Yes"].tap()  | 
 | 124 | + | 
 | 125 | +        cell.awaitInexistence()  | 
 | 126 | +    }  | 
 | 127 | +}  | 
0 commit comments