Improve Test Coverage for `challengeCtrl.js` (Current: 61.24%)
- Dominant language
- Python
- Stars
- 2k
- Forks
- 984
- Avg merge
- 2h 54m
- Merged PRs (30d)
- 14
Description
**Description:**
The file `EvalAI/frontend/src/js/controllers/challengeCtrl.js` currently has **61.24%** test coverage (as per Codecov). To improve this, comprehensive unit tests need to be added targeting untested and partially covered functionality — especially around API-driven logic, asynchronous behaviors, and UI state transitions.
This issue proposes enhancing coverage through **mocking, controlled inputs**, and **Jasmine’s `spyOn`** to simulate and verify the behavior of key functions.
---
### ✅ Key Areas to Cover
#### 1. **API Interactions**
Functions: `manageWorker`, `sendApprovalRequest`, `getTeamName`
* [ ] Mock `utilities.sendRequest`
* [ ] Validate:
* Proper API parameters
* Success callback handling
* Error handling with appropriate alerts or state fallback
#### 2. **UI Controls & Toggles**
Functions: `toggleParticipation`, `toggleLeaderboard`, `toggleShowLeaderboardByLatest`
* [ ] Mock:
* `$mdDialog`
* `$interval`
* `$rootScope.notify`
* [ ] Validate correct toggling of UI states and user feedback messaging
#### 3. **Leaderboard & Time-based Logic**
Function: `getAllEntriesOnPublicLeaderboard`
* [ ] Mock timestamps using `moment.js`
* [ ] Validate:
* Proper leaderboard grouping by time periods (e.g., "Today", "Yesterday")
* Accurate date formatting and category rendering
#### 4. **Form & Submission Metadata Handling**
Functions: `loadPhaseAttributes`, `isCurrentSubmissionMetaAttributeValid`, `toggleSelection`
* [ ] Simulate realistic phase and metadata input
* [ ] Test for correct validation logic and state updates
---
### 📈 Goal
Increase test coverage for `challengeCtrl.js` to **90%+**, ensuring:
* All asynchronous behaviors are properly tested
* UI state and transitions are fully verified
* External dependencies (e.g., `$mdDialog`, `moment`, `utilities.sendRequest`) are reliably mocked
* Future refactors or regressions are caught early
---
Contributor guide
Assessment
This issue has not been assessed yet.