Skip to content

Conversation

@adamNagy56
Copy link
Contributor

Adds test case for attaching PDF file to SpeedGrader comments in FilesE2E test.

refs: MBL-19326
affects: Teacher
release note:

Checklist

  • Run E2E test suite

refs: MBL-19326
affects: Teacher
release note:
refs: MBL-19326
affects: Teacher
release note:
Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Review Summary

This PR enhances the E2E test for file attachments in SpeedGrader by adding comment attachment testing functionality. The overall approach is solid, but there are several areas that need attention for improved test reliability and code quality.

Positive Aspects

Good test coverage expansion - Adding comment attachment tests fills an important gap in the test suite
New FileChooserPage object - Well-structured page object with clear, reusable methods
Proper logging - Comprehensive logging throughout the test for debugging
Assertion improvements - Good use of comment count assertions to verify state changes

Issues Found

  • File cleanup missing (FilesE2ETest.kt:163-177) - The PDF file created in Downloads is never deleted, causing test pollution
  • Thread.sleep anti-pattern (FilesE2ETest.kt:215) - Hardcoded 5-second sleep makes tests slow and unreliable; use proper wait conditions instead
  • Brittle file picker navigation (FilesE2ETest.kt:188-210) - UIAutomator logic relies on device-specific UI text that may vary across Android versions
  • Resource leak potential (FilesE2ETest.kt:163-177) - PDF document creation doesn't use use blocks, risking resource leaks if exceptions occur
  • Storage location concerns (FilesE2ETest.kt:163) - Using DIRECTORY_DOWNLOADS may require runtime permissions and behaves inconsistently across devices
  • Missing newline (FileChooserPage.kt:102) - File should end with a newline per Kotlin style guide

Recommendations

  1. Refactor file handling: Move test files to app-specific directories using getExternalFilesDir() to avoid permission issues
  2. Add cleanup: Implement an @After method or try-finally block to ensure test files are deleted
  3. Replace Thread.sleep: Use Espresso IdlingResource or explicit wait conditions
  4. Extract file picker logic: Create a reusable helper method for UIAutomator file selection with better error handling
  5. Use proper resource management: Wrap PdfDocument and FileOutputStream in use blocks

Test Coverage Note

The test currently validates:

  • Comment attachment display
  • Comment count updates
  • File upload workflow

Consider adding negative test cases:

  • Upload cancellation
  • Invalid file types
  • Network failure scenarios

Overall, this is a valuable addition to the test suite that improves comment attachment coverage. With the issues addressed, it will be much more reliable across different devices and Android versions.


Log.d(STEP_TAG, "Select 'Device' as file source.")
fileChooserPage.chooseDevice()

Copy link

Choose a reason for hiding this comment

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

Complex UIAutomator navigation logic: This navigation fallback logic is brittle and relies on specific UI text and descriptions that may vary across Android versions and device manufacturers. Consider:

  1. Using more robust selectors or abstracting this into a reusable helper method
  2. Adding error handling and logging if the file cannot be found
  3. Consider using a more reliable file selection approach, perhaps by placing test files in a known location or using content URIs

Copy link
Contributor

Choose a reason for hiding this comment

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

As it is written here, isn't there a better method to find and select a file from the file system? This seems a bit fragile like this. I am fine with this as long as there isn't any better solution that can be easily implemented, but it would be worth to check it in a timebox (max 1-2 hours).

@github-actions
Copy link

github-actions bot commented Jan 8, 2026

📊 Code Coverage Report

✅ Student

  • PR Coverage: 43.55%
  • Master Coverage: 43.55%
  • Delta: +0.00%

✅ Teacher

  • PR Coverage: 25.61%
  • Master Coverage: 25.61%
  • Delta: +0.00%

✅ Pandautils

  • PR Coverage: 22.91%
  • Master Coverage: 22.91%
  • Delta: +0.00%

📈 Overall Average

  • PR Coverage: 30.69%
  • Master Coverage: 30.69%
  • Delta: +0.00%

@github-actions
Copy link

github-actions bot commented Jan 8, 2026

🧪 Unit Test Results

✅ 📱 Teacher App

  • Tests: 369 total, 0 failed, 0 skipped
  • Duration: 30.909s
  • Success Rate: 100%

✅ 📦 Submodules

  • Tests: 2515 total, 0 failed, 0 skipped
  • Duration: 57.800s
  • Success Rate: 100%

📊 Summary

  • Total Tests: 2884
  • Failed: 0
  • Skipped: 0
  • Status: ✅ All tests passed!

Last updated: Thu, 08 Jan 2026 15:16:29 GMT

@github-actions
Copy link

github-actions bot commented Jan 8, 2026

Teacher Install Page

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2025 - present Instructure, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

year is 2026 here... :D

pdfFile.createNewFile()

Log.d(PREPARATION_TAG, "Write content to PDF file '${pdfFile.name}'.")
android.graphics.pdf.PdfDocument().apply {
Copy link
Contributor

Choose a reason for hiding this comment

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

you u remove the android.graphics.pdf part and import it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also there are some other classes/methods which can be imported, please review and change them to import if it's possible


Log.d(STEP_TAG, "Select 'Device' as file source.")
fileChooserPage.chooseDevice()

Copy link
Contributor

Choose a reason for hiding this comment

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

As it is written here, isn't there a better method to find and select a file from the file system? This seems a bit fragile like this. I am fine with this as long as there isn't any better solution that can be easily implemented, but it would be worth to check it in a timebox (max 1-2 hours).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants