Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent the model from fetching if the course_id is missing #1234

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ edx = edx || {};
initialize: function() {
this.setElement($('.student-proctored-exam-container'));
this.course_id = this.$el.data('course-id');

if (!this.course_id) return; // No course defined.

this.template = null;
this.model = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptModel();

Expand Down Expand Up @@ -133,22 +136,32 @@ edx = edx || {};
self.hydrate();
});
},

hydrateDone: function(self) {
var $searchIcon, $spinner;
self.render();
$spinner = $(document.getElementById('attempt-loading-indicator'));
$spinner.addClass('hidden');
$searchIcon = $(document.getElementById('attempt-search-indicator'));
$searchIcon.removeClass('hidden');
},

hydrate: function() {
/* This function will load the bound collection */

/* add and remove a class when we do the initial loading */
/* we might - at some point - add a visual element to the */
/* loading, like a spinner */
var self = this;

if (!self.course_id) {
// If there's no course_id, there's no point in fetching, so we remove the loading state.
self.hydrateDone(self);
return;
}

self.collection.fetch({
success: function() {
var $searchIcon, $spinner;
self.render();
$spinner = $(document.getElementById('attempt-loading-indicator'));
$spinner.addClass('hidden');
$searchIcon = $(document.getElementById('attempt-search-indicator'));
$searchIcon.removeClass('hidden');
}
success: self.hydrateDone(self)
});
},
collectionChanged: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ describe('ProctoredExamAttemptView', function() {
afterEach(function() {
this.server.restore();
});

it('should not fetch if student-proctored-exam-container is missing', function() {
setFixtures('<div>(void)</div>'); // Remove the student-proctored-exam-container from the template
this.proctored_exam_attempt_view = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptView();

expect(this.server.calls.length).toBe(0);
});

it('should render the proctored exam attempt view properly', function() {
this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/attempt/grouped/course_id/test_course_id',
[
Expand Down
Loading