Skip to content

fix: Correction of existing tests#1874

Open
killian-mathias wants to merge 11 commits intomasterfrom
fix/tests
Open

fix: Correction of existing tests#1874
killian-mathias wants to merge 11 commits intomasterfrom
fix/tests

Conversation

@killian-mathias
Copy link
Copy Markdown
Contributor

Refonte des tests en intégrant les traductions, en créant des fonctions pour les tâches répétitives.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

PR Reviewer Guide 🔍

(Review updated until commit 2707353)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 Security concerns

Sensitive information exposure:
The CI workflow (.github/workflows/ci.yml) creates kDriveUITests/Env.swift containing test account credentials (UITEST_ACCOUNT_EMAIL, UITEST_ACCOUNT_PASSWORD) from GitHub secrets. While using secrets is correct, ensure that:

  1. Env.swift is listed in .gitignore to prevent accidental commits
  2. The file is not persisted in build artifacts or test outputs
  3. CI logs do not echo the file contents
    Additionally, the resetAppForUITestsIfNeeded() method in Logging.swift deletes all Keychain tokens and user data when the resetData launch argument is present. While guarded by #if DEBUG, ensure this argument is never used in production builds or beta testing to prevent accidental data loss.
⚡ Recommended focus areas for review

Fragile UI Test Selectors

Multiple tests use element(boundBy:) with hardcoded indices (e.g., app.buttons.element(boundBy: 0) in login(), app.images.element(boundBy: 5) in testCreateOfficeFile, buttons.allElementsBoundByIndex[1] in createDirectoryWithPhoto). These selectors are brittle and will break when the UI layout changes. Use accessibility identifiers or labels instead of relying on element order.

let loginButton = app.buttons.element(boundBy: 0)
Dead Code

The login() method contains commented-out code (lines 591-595) that appears to be a leftover from debugging. This should be removed to maintain code cleanliness.

//        wait(delay: 5)
//        XCTAssertTrue(
//            app.buttons[KDriveResourcesStrings.Localizable.fileListTitle].waitForExistence(timeout: 5),
//            "Last modification text should display"
//        )
Hardcoded Localization Check

In testAddCategories, the logic KDriveResourcesStrings.Localizable.buttonBack != "Back" hardcodes an English string comparison to determine which accessibility identifier to use. This defeats the purpose of localization and will fail if the locale changes or if the translation differs. Use a more robust identifier strategy that doesn't rely on string content comparison.

let value = KDriveResourcesStrings.Localizable.buttonBack != "Back" ? KDriveResourcesStrings.Localizable.buttonBack : "BackButton"
app.buttons[value].firstMatch.tap()

Comment thread kDriveCore/Utils/Logging.swift
Comment thread kDriveUITests/DriveUITest.swift Outdated
Comment on lines +146 to +151
photospickerApp/*@START_MENU_TOKEN@*/
.images["Photo, 30 mars 2018, 21:14"]/*[[".otherElements.images[\"Photo, 30 mars 2018, 21:14\"]",".images[\"Photo, 30 mars 2018, 21:14\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/
.coordinate(withNormalizedOffset: CGVector(
dx: 0,
dy: 0
)).tap()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The hardcoded photo date "30 mars 2018, 21:14" assumes a specific photo exists in the library, which will cause test failures on different simulators or devices. Use photospickerApp.images.firstMatch or select by index to choose any available photo. [general, importance: 7]

Suggested change
photospickerApp/*@START_MENU_TOKEN@*/
.images["Photo, 30 mars 2018, 21:14"]/*[[".otherElements.images[\"Photo, 30 mars 2018, 21:14\"]",".images[\"Photo, 30 mars 2018, 21:14\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/
.coordinate(withNormalizedOffset: CGVector(
dx: 0,
dy: 0
)).tap()
photospickerApp.images.firstMatch
.coordinate(withNormalizedOffset: CGVector(
dx: 0.5,
dy: 0.5
)).tap()

// Leave office edition page
let officeBackButton = app.webViews.staticTexts["chevron_left_ios"]
XCTAssertTrue(officeBackButton.waitForExistence(timeout: 4), "back button should be displayed")
let officeBackButton = app.images.element(boundBy: 5)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Accessing UI elements by index is fragile and will break if the UI layout changes even slightly. Replace with a specific accessibility identifier or label to locate the back button reliably. [general, importance: 6]

Suggested change
let officeBackButton = app.images.element(boundBy: 5)
let officeBackButton = app.images["officeBackButton"].firstMatch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can manage to get the element by ID and not rely on hardcoded indexes it is indeed better 👍

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Persistent review updated to latest commit dfdc0a7

Comment on lines +85 to +89
let documentFileURLs = try FileManager.default.contentsOfDirectory(
at: FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!,
includingPropertiesForKeys: nil,
options: .skipsHiddenFiles
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Replace the force unwrap with safe optional binding to prevent a crash if the document directory URL cannot be retrieved. Use guard let to safely unwrap the optional array result. [possible issue, importance: 7]

Suggested change
let documentFileURLs = try FileManager.default.contentsOfDirectory(
at: FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!,
includingPropertiesForKeys: nil,
options: .skipsHiddenFiles
)
guard let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else {
return
}
let documentFileURLs = try FileManager.default.contentsOfDirectory(
at: documentDirectory,
includingPropertiesForKeys: nil,
options: .skipsHiddenFiles
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do it as well to explicit the issue in console

Comment thread kDriveUITests/DriveUITest.swift Outdated
let photospickerApp = XCUIApplication(bundleIdentifier: "com.apple.mobileslideshow.photospicker")
photospickerApp/*@START_MENU_TOKEN@*/
.images["Photo, 30 mars 2018, 21:14"]/*[[".otherElements.images[\"Photo, 30 mars 2018, 21:14\"]",".images[\"Photo, 30 mars 2018, 21:14\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/
.coordinate(withNormalizedOffset: CGVector()).tap()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Specify the center coordinates using CGVector(dx: 0.5, dy: 0.5) instead of the default zero vector. The default CGVector() creates a zero offset (top-left corner), which may miss the interactive area of the photo element. [possible issue, importance: 6]

Suggested change
.coordinate(withNormalizedOffset: CGVector()).tap()
.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()

@adrien-coye
Copy link
Copy Markdown
Contributor

I prepared my review, we'll discuss it tomorrow 🙌

Copy link
Copy Markdown
Contributor

@adrien-coye adrien-coye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did review this PR face to face.
It looks good, but I'd like to go further with this PR :

  • CI step
  • Switch to EN-UK
  • A couple of small remarks

@@ -301,30 +372,33 @@ class AppUITest: XCTestCase {
}

func testCreateSharedDirectory() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For every "create" task, I would like to see a cleanup function to remove said file.
It could be a direct call to the API to make sure the test account stays relatively clean.

Comment thread kDriveCore/Utils/Logging.swift
Comment on lines +85 to +89
let documentFileURLs = try FileManager.default.contentsOfDirectory(
at: FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!,
includingPropertiesForKeys: nil,
options: .skipsHiddenFiles
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do it as well to explicit the issue in console

Comment thread kDriveUITests/DriveUITest.swift
@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit eccd2ad

@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit 7a5e315

Comment thread kDriveUITests/DriveUITest.swift Outdated
// MARK: - Tests setup

func testLogin() {
setUp()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Do not manually invoke setUp() inside test methods. XCTest automatically calls this method before each test. Manual invocation causes double initialization of the test environment and XCUIApplication instance. Rename the custom configuration method (e.g., to configureTest()) and invoke that instead. [possible issue, importance: 8]

Suggested change
setUp()
func testLogin() {
configureTest()
launchAppFromScratch()
login()
}

let closeButton = app.buttons["Fermer"]
XCTAssertTrue(closeButton.waitForExistence(timeout: 3), "Close button should be visible")
let closeButton = app.buttons[KDriveResourcesStrings.Localizable.buttonClose]
closeButton.tap()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Restore the existence check before tapping the button. The previous code verified the button existed with waitForExistence(timeout: 3), but this safety check was removed when localizing the string. Without this check, the test crashes if the button isn't immediately available. [possible issue, importance: 7]

Suggested change
closeButton.tap()
let closeButton = app.buttons[KDriveResourcesStrings.Localizable.buttonClose]
XCTAssertTrue(closeButton.waitForExistence(timeout: 3), "Close button should be visible")
closeButton.tap()

Comment thread kDriveUITests/DriveUITest.swift Outdated
Comment on lines +146 to +147
XCTAssertTrue(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Fix the backwards assertion logic. The code asserts that the photo library is empty, but then immediately attempts to tap the second image element (index 1), which causes an out-of-bounds crash when the collection is empty. Change to XCTAssertFalse to ensure photos exist before tapping. [possible issue, importance: 9]

Suggested change
XCTAssertTrue(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
XCTAssertFalse(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()

@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit 9e408c6

Comment thread kDriveUITests/DriveUITest.swift Outdated
Comment on lines +146 to +147
XCTAssertTrue(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The assertion logic is inverted - it fails when photos exist (the expected state) and would pass when empty, causing the subsequent element(boundBy: 1) access to crash with an out-of-bounds error. Replace with a count check to ensure at least one photo exists before tapping. [possible issue, importance: 9]

Suggested change
XCTAssertTrue(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
XCTAssertGreaterThan(photospickerApp.images.count, 0, "No photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()

Comment on lines +302 to 303
let closeButton = app.buttons[KDriveResourcesStrings.Localizable.buttonClose]
closeButton.tap()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The removal of the waitForExistence check before the first closeButton.tap() removes a safety guard that ensures the UI element is ready. This may cause the test to tap a non-existent button if the UI hasn't finished transitioning, leading to intermittent failures. [possible issue, importance: 6]

Suggested change
let closeButton = app.buttons[KDriveResourcesStrings.Localizable.buttonClose]
closeButton.tap()
let closeButton = app.buttons[KDriveResourcesStrings.Localizable.buttonClose]
XCTAssertTrue(closeButton.waitForExistence(timeout: 3), "Close button should be visible")
closeButton.tap()

Comment on lines +433 to +434
let officeBackButton = app.images.element(boundBy: 5)
XCTAssertTrue(officeBackButton.waitForExistence(timeout: 10), "back button should be displayed")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Accessing UI elements by hardcoded index boundBy: 5 is fragile and will break if the UI layout changes or additional images are added. Replace with an accessibility identifier query to reliably locate the back button regardless of layout changes. [general, importance: 5]

Suggested change
let officeBackButton = app.images.element(boundBy: 5)
XCTAssertTrue(officeBackButton.waitForExistence(timeout: 10), "back button should be displayed")
let officeBackButton = app.images["OfficeBackButton"]
XCTAssertTrue(officeBackButton.waitForExistence(timeout: 10), "back button should be displayed")

@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit d376b5e

Comment thread kDriveUITests/DriveUITest.swift Outdated
Comment on lines +145 to +146
let photospickerApp = XCUIApplication(bundleIdentifier: "com.apple.mobileslideshow.photospicker")
XCTAssertTrue(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The assertion verifies that no photos exist (isEmpty == true), but the subsequent line attempts to tap the second image (index 1), which will crash or fail when the library is empty. Change the assertion to verify images exist (isEmpty == false) and use index 0 to select the first available image. [possible issue, importance: 9]

Suggested change
let photospickerApp = XCUIApplication(bundleIdentifier: "com.apple.mobileslideshow.photospicker")
XCTAssertTrue(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
XCTAssertFalse(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
photospickerApp.images.element(boundBy: 0).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()

Comment thread kDriveUITests/DriveUITest.swift Outdated
Comment on lines +224 to +228
setUp()
launchAppFromScratch(resetData: false)

let laterButton = app.buttons[KDriveResourcesStrings.Localizable.buttonLater]
if laterButton.exists {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Remove the manual setUp() invocation inside test methods. setUp() is an XCTest lifecycle method automatically called before each test; invoking it manually reinitializes the app property and test state, leading to unpredictable behavior or crashes. [possible issue, importance: 7]

Suggested change
setUp()
launchAppFromScratch(resetData: false)
let laterButton = app.buttons[KDriveResourcesStrings.Localizable.buttonLater]
if laterButton.exists {
func testRenameFile() {
let testName = "UITest - Rename file-\(Date())"
let newTestName = "\(testName)_update"
launchAppFromScratch(resetData: false)

Comment on lines 303 to 304
closeButton.tap()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Restore the waitForExistence timeout assertion before tapping the button. Without this wait, the test attempts to tap immediately, causing race condition failures if the button hasn't appeared in the view hierarchy yet. [possible issue, importance: 7]

Suggested change
closeButton.tap()
let closeButton = app.buttons[KDriveResourcesStrings.Localizable.buttonClose]
XCTAssertTrue(closeButton.waitForExistence(timeout: 3), "Close button should be visible")
closeButton.tap()

@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit 65713e0

Comment thread .github/workflows/ci.yml Outdated
UITEST_ACCOUNT_PASSWORD: ${{ secrets.UITEST_ACCOUNT_PASSWORD }}
run: |
touch $ENV_PATH
echo -e "enum Env {\n static let testAccountEmail = \"$UITEST_ACCOUNT_EMAIL\"\n static let testAccountPassword = \"$UITEST_ACCOUNT_PASSWORD\"\n}" > $ENV_PATH \ -testLanguage en-UK \ -testRegion UK
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Remove the erroneously appended test arguments (-testLanguage and -testRegion) from the echo command. These appear to be copy-pasted from the subsequent test command and will cause invalid Swift syntax in the generated Env.swift file. [possible issue, importance: 9]

Suggested change
echo -e "enum Env {\n static let testAccountEmail = \"$UITEST_ACCOUNT_EMAIL\"\n static let testAccountPassword = \"$UITEST_ACCOUNT_PASSWORD\"\n}" > $ENV_PATH \ -testLanguage en-UK \ -testRegion UK
echo -e "enum Env {\n static let testAccountEmail = \"$UITEST_ACCOUNT_EMAIL\"\n static let testAccountPassword = \"$UITEST_ACCOUNT_PASSWORD\"\n}" > $ENV_PATH

Comment on lines +95 to +97
func testLogin() {
setUp()
launchAppFromScratch()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Remove the explicit setUp() call from test methods. XCTest automatically invokes setUp() before each test method, so calling it manually causes double initialization which may reset app state unexpectedly. [general, importance: 7]

Suggested change
func testLogin() {
setUp()
launchAppFromScratch()
func testLogin() {
launchAppFromScratch()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is correct, some calls to setUp() are still present. This is called by the XCTest framework on its own.

Comment on lines +302 to 303
let closeButton = app.buttons[KDriveResourcesStrings.Localizable.buttonClose]
closeButton.tap()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Restore the waitForExistence assertion before tapping the close button. Removing this check introduces a race condition where the tap may occur before the button is fully rendered and interactable. [general, importance: 6]

Suggested change
let closeButton = app.buttons[KDriveResourcesStrings.Localizable.buttonClose]
closeButton.tap()
let closeButton = app.buttons[KDriveResourcesStrings.Localizable.buttonClose]
XCTAssertTrue(closeButton.waitForExistence(timeout: 3), "Close button should be visible")
closeButton.tap()

@adrien-coye adrien-coye added the CI label Apr 10, 2026
@adrien-coye adrien-coye added this to the 5.12.3 milestone Apr 10, 2026
@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit 6d81aba

Comment thread .github/workflows/ci.yml Outdated
UITEST_ACCOUNT_PASSWORD: ${{ secrets.UITEST_ACCOUNT_PASSWORD }}
run: |
touch $ENV_PATH
echo -e "enum Env {\n static let testAccountEmail = \"$UITEST_ACCOUNT_EMAIL\"\n static let testAccountPassword = \"$UITEST_ACCOUNT_PASSWORD\"\n}" > $ENV_PATH \
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Remove the trailing backslash to prevent the shell command from escaping the newline and attempting to execute the next YAML line as part of the shell command, which would cause a workflow syntax error. [possible issue, importance: 9]

Suggested change
echo -e "enum Env {\n static let testAccountEmail = \"$UITEST_ACCOUNT_EMAIL\"\n static let testAccountPassword = \"$UITEST_ACCOUNT_PASSWORD\"\n}" > $ENV_PATH \
echo -e "enum Env {\n static let testAccountEmail = \"$UITEST_ACCOUNT_EMAIL\"\n static let testAccountPassword = \"$UITEST_ACCOUNT_PASSWORD\"\n}" > $ENV_PATH

Comment thread kDriveUITests/DriveUITest.swift Outdated
Comment on lines +146 to +147
XCTAssertTrue(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The assertion verifies that the photo library is empty, but the subsequent line attempts to access the second image (index 1). This contradiction will cause the test to crash when accessing an empty collection. Remove the assertion or change it to verify that images exist before tapping. [possible issue, importance: 9]

Suggested change
XCTAssertTrue(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
XCTAssertFalse(photospickerApp.images.debugDescription.isEmpty, "Photo library should not be empty")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()

Comment thread kDriveCore/Utils/Logging.swift Outdated
Comment on lines +69 to +70
UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
UserDefaults.shared.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Force unwrapping Bundle.main.bundleIdentifier could cause a crash if the identifier is nil (e.g., in certain test environments). Use optional binding to safely unwrap the value before passing it to the removal method. [possible issue, importance: 7]

Suggested change
UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
UserDefaults.shared.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
guard let bundleIdentifier = Bundle.main.bundleIdentifier else { return }
UserDefaults.standard.removePersistentDomain(forName: bundleIdentifier)
UserDefaults.shared.removePersistentDomain(forName: bundleIdentifier)

@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit 7fedeef

Comment thread .github/workflows/ci.yml Outdated
- name: Setup
run: tuist install && tuist generate --no-open
- name: UITest
env: TEST_RUNNER_LAUNCH_ARGS: "-AppleLanguages (en-GB) -AppleLocale en_GB"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Fix the malformed YAML syntax for the env key. The current inline format may be parsed as a string rather than a mapping, causing the environment variable to not be set correctly. Use proper YAML mapping syntax with the variable name on a new indented line. [possible issue, importance: 9]

Suggested change
env: TEST_RUNNER_LAUNCH_ARGS: "-AppleLanguages (en-GB) -AppleLocale en_GB"
env:
TEST_RUNNER_LAUNCH_ARGS: "-AppleLanguages (en-GB) -AppleLocale en_GB"

Comment thread kDriveUITests/DriveUITest.swift Outdated
let shareAndRights = collectionViewsQuery.cells.staticTexts["Partage et droits"]
let shareAndRights = collectionViewsQuery.cells.staticTexts[KDriveResourcesStrings.Localizable.buttonFileRights]
shareAndRights.tap()
let directoryShareAndRights = app.navigationBars["Partage et droits du dossier \(root)"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Replace the hardcoded French navigation bar title with the English equivalent or a localized string to match the en-GB locale configuration used in the tests. The app runs in English (en-GB) per the launch arguments, so checking for a French title will cause the test to fail. [possible issue, importance: 9]

Suggested change
let directoryShareAndRights = app.navigationBars["Partage et droits du dossier \(root)"]
let directoryShareAndRights = app.navigationBars["Share and rights of folder \(root)"]

Comment thread kDriveUITests/DriveUITest.swift Outdated
Comment on lines +149 to +151
.buttons["Add"]/*[[".navigationBars",".buttons[\"Terminé\"]",".buttons[\"Add\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/
.firstMatch.tap()
let buttonSave = app.buttons[KDriveResourcesStrings.Localizable.buttonSave]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Remove the Xcode test recorder placeholder comments (/*@START_MENU_TOKEN@*/ and associated metadata) from the UI test code. These artifacts indicate auto-generated code that should be cleaned up for better readability and maintainability. [general, importance: 4]

Suggested change
.buttons["Add"]/*[[".navigationBars",".buttons[\"Terminé\"]",".buttons[\"Add\"]"],[[[-1,2],[-1,1],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/
.firstMatch.tap()
let buttonSave = app.buttons[KDriveResourcesStrings.Localizable.buttonSave]
photospickerApp.buttons["Add"].firstMatch.tap()

@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit 8cd0d0b

Comment thread kDriveUITests/DriveUITest.swift Outdated
Comment on lines +561 to +564
app/*@START_MENU_TOKEN@*/
.buttons[KDriveResourcesStrings.Localizable
.buttonBack]/*[[".navigationBars",".buttons[\"Filtres\"]",".buttons[\"BackButton\"]",".buttons"],[[[-1,2],[-1,1],[-1,3],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/
.firstMatch.tap()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Remove Xcode UI test recording artifacts (START_MENU_TOKEN comments). These are automatically generated by Xcode during test recording and should be cleaned up to maintain readable, maintainable code. Use a clean multi-line statement instead. [general, importance: 6]

Suggested change
app/*@START_MENU_TOKEN@*/
.buttons[KDriveResourcesStrings.Localizable
.buttonBack]/*[[".navigationBars",".buttons[\"Filtres\"]",".buttons[\"BackButton\"]",".buttons"],[[[-1,2],[-1,1],[-1,3],[-1,0,1]],[[-1,2],[-1,1]]],[0]]@END_MENU_TOKEN@*/
.firstMatch.tap()
app.buttons[KDriveResourcesStrings.Localizable.buttonBack]
.firstMatch.tap()

Comment thread kDriveUITests/DriveUITest.swift Outdated
Comment on lines +145 to +146
XCTAssertFalse(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Replace the fragile debugDescription.isEmpty check with a proper count validation. The current code assumes at least 2 images exist (accessing index 1) but only checks if the description string is non-empty. Verify images.count > 1 before accessing a specific index to prevent crashes when the photo library has insufficient images. [possible issue, importance: 8]

Suggested change
XCTAssertFalse(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
XCTAssertGreaterThan(photospickerApp.images.count, 1, "Need at least 2 photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()

Comment on lines +491 to +494
app.staticTexts[testName].firstMatch.tap()
XCTAssertTrue(
app.staticTexts["20180330_211419_3650.jpeg"].waitForExistence(timeout: 3),
"Photo should be back in directory"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Avoid hardcoding the expected filename "20180330_211419_3650.jpeg" as it assumes a specific photo exists in the simulator's photo library. Store the actual filename returned from the photo picker during upload and use that variable for assertions, or verify the file exists by checking the cell count or a dynamic identifier. [possible issue, importance: 6]

Suggested change
app.staticTexts[testName].firstMatch.tap()
XCTAssertTrue(
app.staticTexts["20180330_211419_3650.jpeg"].waitForExistence(timeout: 3),
"Photo should be back in directory"
// Store the filename from the upload flow and use it here
XCTAssertTrue(
app.staticTexts[uploadedPhotoName].waitForExistence(timeout: 3),
"Photo should be back in directory"
)

@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit 2258f23

@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit b815d17

@github-actions
Copy link
Copy Markdown

Persistent review updated to latest commit 2707353

Comment thread kDriveCore/Utils/Logging.swift
}
let photospickerApp = XCUIApplication(bundleIdentifier: "com.apple.mobileslideshow.photospicker")
XCTAssertFalse(photospickerApp.images.debugDescription.isEmpty, "No photos in photo library")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add a bounds check before accessing element(boundBy: 1) to prevent crashes when the photo library contains fewer than 2 images. Accessing an index beyond the available elements will cause the UI test to crash. [possible issue, importance: 6]

Suggested change
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
XCTAssertGreaterThan(photospickerApp.images.count, 1, "Photo library needs at least 2 images")
photospickerApp.images.element(boundBy: 1).coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()

Comment on lines +239 to +243
var deleteString = String()
for _ in newTestName {
deleteString += XCUIKeyboardKey.delete.rawValue
}
fileNameTextField.typeText(deleteString)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Calculate the delete string length based on the current text field content (root) rather than newTestName. The text field contains the existing folder name (root), so deleting newTestName.count characters may delete too many or too few characters, causing test failures or unexpected behavior. [possible issue, importance: 8]

Suggested change
var deleteString = String()
for _ in newTestName {
deleteString += XCUIKeyboardKey.delete.rawValue
}
fileNameTextField.typeText(deleteString)
var deleteString = String()
for _ in root {
deleteString += XCUIKeyboardKey.delete.rawValue
}
fileNameTextField.typeText(deleteString)

Copy link
Copy Markdown
Contributor

@adrien-coye adrien-coye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a new review of this PR.
We discussed how to work with the CI.
Beyond using a defer to make sure the cleanup is applied all the time, there is some extraneous setUp() calls that are not needed.

Comment thread kDriveUITests/DriveUITest.swift Outdated
passwordField.typeText(Env.testAccountPassword)
passwordField.typeText("\n")

// wait(delay: 5)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not need it we should just remove it before we merge this PR.

Comment on lines +95 to +97
func testLogin() {
setUp()
launchAppFromScratch()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is correct, some calls to setUp() are still present. This is called by the XCTest framework on its own.

@github-actions
Copy link
Copy Markdown

Failed to generate code suggestions for PR

@github-actions
Copy link
Copy Markdown

Failed to generate code suggestions for PR

@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Failed to generate code suggestions for PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants