Skip to content

chore: fix skipped test cases in frontend app support tools#462

Open
Akanshu-2u wants to merge 15 commits intoopenedx:masterfrom
Akanshu-2u:akanshu/fix-skipped-test-cases-in-frontend-app-support-tools
Open

chore: fix skipped test cases in frontend app support tools#462
Akanshu-2u wants to merge 15 commits intoopenedx:masterfrom
Akanshu-2u:akanshu/fix-skipped-test-cases-in-frontend-app-support-tools

Conversation

@Akanshu-2u
Copy link

Description
Certain test cases were failing in frontend-app-support-tools due to the migration from Enzyme to React Testing Library (RTL). The existing functions and utilities were not properly adapted to work with RTL and were more suited for Enzyme. Therefore, I made the necessary changes to align them with the new testing library.

ProgramInspector.test.jsx

  1. Unskipped the test: Removed it.skip from "check if SSO is present" test
  2. Fixed mock persistence: Changed mockImplementationOnce to mockImplementation in beforeEach for all mocks to work across multiple API calls
  3. Used consistent query approach: Kept document.querySelector instead of RTL role queries since input elements lacked proper id attributes for accessibility
  4. Corrected test expectations: Changed from expecting "tpa-saml (Provider)" to expecting "SSO Record Not Found" to match actual test data
  5. Proper mock setup: Set up the getProgramEnrollmentsInspector mock before rendering in the failing test

CourseEnrollment.test.jsx

1. Migrated from Enzyme to React Testing Library (RTL):

    - Replaced Enzyme's mount(), find(), simulate() with RTL's render(), screen.getByText(), fireEvent()
    - Updated test selectors to use screen queries and document.querySelector()

2. Fixed Form Event Handling:

    - Changed from simulate('change') to fireEvent.change() with proper target values
    - Updated select field values to match actual options (e.g., 'other' instead of 'Other')

3. Added Proper Async Handling:

   - Used waitFor() for asynchronous operations
   - Added act() wrapper for form submissions
   - Ensured form state updates before assertions

4. Fixed Test Assertions:

  - Updated button presence checks to use toHaveAttribute('hidden') instead of not.toBeInTheDocument() since hidden buttons are still in DOM
  - Fixed error message assertions to use RTL queries

5. Added Missing Import:

 - Added import * as api from '../data/api' for API mocking

Entitlements.test.jsx

  - Removed .skip: Unskipped all previously skipped tests
  - Fixed dropdown interactions: Used act() wrapper for dropdown clicks to handle state updates
  - Fixed async operations: Added proper waitFor() for UI state changes
  - Fixed test data: Used correct test data and assertions
  - Fixed API mocking: Proper setup of entitlements and course data API mocks

CourseReset.test.jsx

  - Removed .skip: Unskipped all previously skipped tests
  - Fixed async/await: Added proper act() and waitFor() for async operations
  - Fixed user interactions: Used proper fireEvent and userEvent for button clicks
  - Fixed timer tests: Added jest.useFakeTimers() for polling functionality tests
  - Fixed API mocking: Proper setup of getLearnerCourseResetList and postCourseReset mocks

CourseSummary.test.jsx

  - Fixed API mocking: Added proper jest.spyOn(api, 'getCourseData') mocks for each test
  - Fixed mock cleanup: Added proper beforeEach and afterEach to reset mocks
  - Fixed test structure: Ensured each test has its own API mock setup
  - Fixed error test: The "Course Summary Fetch Errors" test was expecting the correct title behavior when errors occur

Ticket:
#446

@Akanshu-2u Akanshu-2u closed this Jul 10, 2025
@Akanshu-2u Akanshu-2u reopened this Jan 19, 2026
@Akanshu-2u Akanshu-2u marked this pull request as draft January 19, 2026 09:37
@Akanshu-2u Akanshu-2u marked this pull request as ready for review January 19, 2026 11:16
@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.59%. Comparing base (13e4b71) to head (b0afdc7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #462      +/-   ##
==========================================
+ Coverage   85.94%   89.59%   +3.64%     
==========================================
  Files         185      185              
  Lines        3879     3882       +3     
  Branches      962      959       -3     
==========================================
+ Hits         3334     3478     +144     
+ Misses        527      390     -137     
+ Partials       18       14       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants