Commit bf5de42f by chrisndodge

Merge pull request #93 from edx/muhhshoaib/more-js-tests

Muhhshoaib/more js tests
parents a938e7f2 a401dd3f
...@@ -7,7 +7,7 @@ var edx = edx || {}; ...@@ -7,7 +7,7 @@ var edx = edx || {};
edx.instructor_dashboard.proctoring = edx.instructor_dashboard.proctoring || {}; edx.instructor_dashboard.proctoring = edx.instructor_dashboard.proctoring || {};
edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView = Backbone.View.extend({ edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView = Backbone.View.extend({
initialize: function (options) { initialize: function () {
this.collection = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceCollection(); this.collection = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceCollection();
this.proctoredExamCollection = new edx.instructor_dashboard.proctoring.ProctoredExamCollection(); this.proctoredExamCollection = new edx.instructor_dashboard.proctoring.ProctoredExamCollection();
/* unfortunately we have to make some assumptions about what is being set up in HTML */ /* unfortunately we have to make some assumptions about what is being set up in HTML */
...@@ -140,4 +140,5 @@ var edx = edx || {}; ...@@ -140,4 +140,5 @@ var edx = edx || {};
event.preventDefault(); event.preventDefault();
} }
}); });
this.edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView = edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView;
}).call(this, Backbone, $, _); }).call(this, Backbone, $, _);
describe('ProctoredExamAllowanceView', function () {
var html = '';
var expectedProctoredAllowanceJson = [
{
created: "2015-08-10T09:15:45Z",
id: 1,
modified: "2015-08-10T09:15:45Z",
key: "Additional time (minutes)",
value: "1",
proctored_exam: {
content_id: "i4x://edX/DemoX/sequential/9f5e9b018a244ea38e5d157e0019e60c",
course_id: "edX/DemoX/Demo_Course",
exam_name: "Test Exam",
external_id: null,
id: 17,
is_active: true,
is_practice_exam: false,
is_proctored: true,
time_limit_mins: 1
},
user: {
username: 'testuser1',
email: 'testuser1@test.com'
}
}
];
beforeEach(function () {
html = '<span class="tip">' +
'<%- gettext("Allowances") %>' +
'<span> <a id="add-allowance" href="#" class="add blue-button">+' +
'<%- gettext("Add Allowance") %>' +
'</a> </span> </span>' +
'<% var is_allowances = proctored_exam_allowances.length !== 0 %>' +
'<% if (is_allowances) { %>'+
'<div class="wrapper-content wrapper"> <section class="content"> <table class="allowance-table">' +
'<thead><tr class="allowance-headings">' +
'<th class="exam-name">Exam Name</th>' +
'<th class="username">Username</th>' +
'<th class="email">Email</th>' +
'<th class="allowance-name">Allowance Type</th>' +
'<th class="allowance-value">Allowance Value</th>' +
'<th class="c_action">Actions </th>' +
'</tr></thead>' +
'<tbody>' +
'<% _.each(proctored_exam_allowances, function(proctored_exam_allowance){ %>' +
'<tr class="allowance-items">' +
'<td>' +
'<%- interpolate(gettext(" %(exam_display_name)s "), { exam_display_name: proctored_exam_allowance.proctored_exam.exam_name }, true) %>' +
'</td>' +
'<% if (proctored_exam_allowance.user){ %>' +
'<td>' +
'<%- interpolate(gettext(" %(username)s "), { username: proctored_exam_allowance.user.username }, true) %>' +
'</td>' +
'<td>' +
'<%- interpolate(gettext(" %(email)s "), { email: proctored_exam_allowance.user.email }, true) %>' +
'</td>' +
'<% }else{ %>' +
'<td>N/A</td><td>N/A</td>' +
'<% } %>' +
'<td>' +
'<%- interpolate(gettext(" %(allowance_name)s "), { allowance_name: proctored_exam_allowance.key }, true) %>' +
'</td>' +
'<td>' +
'<%= proctored_exam_allowance.value %>' +
'</td>' +
'<td>' +
'<a data-exam-id="<%= proctored_exam_allowance.proctored_exam.id %>" data-key-name="<%= proctored_exam_allowance.key %>" data-user-id="<%= proctored_exam_allowance.user.id %>"class="remove_allowance" href="#">[x]</a>' +
'</td></tr>' +
'<% }); %>' +
'</tbody></table></section></div>' +
'<% } %>';
this.server = sinon.fakeServer.create();
this.server.autoRespond = true;
setFixtures('<div class="special-allowance-container" data-course-id="test_course_id"></div>');
// load the underscore template response before calling the proctored exam allowance view.
this.server.respondWith("GET", "/static/proctoring/templates/course_allowances.underscore",
[
200,
{"Content-Type": "text/html"},
html
]
);
});
afterEach(function() {
this.server.restore();
});
it("should render the proctored exam allowance view properly", function () {
this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance',
[
200,
{
"Content-Type": "application/json"
},
JSON.stringify(expectedProctoredAllowanceJson)
]
);
this.proctored_exam_allowance = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView();
this.server.respond();
this.server.respond();
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).toContain('testuser1');
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).toContain('testuser1@test.com');
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).toContain('Additional time (minutes)');
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).toContain('Test Exam');
});
//
it("should remove the proctored exam allowance", function () {
this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance',
[
200,
{
"Content-Type": "application/json"
},
JSON.stringify(expectedProctoredAllowanceJson)
]
);
this.proctored_exam_allowance = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView();
this.server.respond();
this.server.respond();
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).toContain('testuser1');
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).toContain('testuser1@test.com');
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).toContain('Additional time (minutes)');
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).toContain('Test Exam');
// delete the proctored exam allowance one by one
this.server.respondWith('DELETE', '/api/edx_proctoring/v1/proctored_exam/allowance',
[
200,
{
"Content-Type": "application/json"
},
JSON.stringify([])
]
);
// again fetch the results after the proctored exam allowance deletion
this.server.respondWith('GET', '/api/edx_proctoring/v1/proctored_exam/test_course_id/allowance',
[
200,
{
"Content-Type": "application/json"
},
JSON.stringify([])
]
);
// trigger the remove allowance event.
var spyEvent = spyOnEvent('.remove_allowance', 'click');
$('.remove_allowance').trigger( "click" );
// process the deleted allowance requests.
this.server.respond();
this.server.respond();
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).not.toContain('testuser1');
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).not.toContain('testuser1@test.com');
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).not.toContain('Additional time (minutes)');
expect(this.proctored_exam_allowance.$el.find('tr.allowance-items').html()).not.toContain('Test Exam');
});
});
describe('ProctoredExamView', function () { describe('ProctoredExamAttemptView', function () {
var html = ''; var html = '';
var deletedProctoredExamAttemptJson = [{ var deletedProctoredExamAttemptJson = [{
attempt_url: '/api/edx_proctoring/v1/proctored_exam/attempt/course_id/edX/DemoX/Demo_Course', attempt_url: '/api/edx_proctoring/v1/proctored_exam/attempt/course_id/edX/DemoX/Demo_Course',
...@@ -149,18 +149,11 @@ describe('ProctoredExamView', function () { ...@@ -149,18 +149,11 @@ describe('ProctoredExamView', function () {
JSON.stringify(expectedProctoredExamAttemptJson) JSON.stringify(expectedProctoredExamAttemptJson)
] ]
); );
this.proctored_exam_attempt_view = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptView();
var callbacks = [sinon.spy(), sinon.spy()]; this.server.respond();
this.server.respond();
this.proctored_exam_attempt_view = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptView(
{
el: $('.student-proctored-exam-container'),
template_url: '/static/proctoring/templates/student-proctored-exam-attempts.underscore'
}
);
console.log(this.server.requests); // Logs all requests so far
this.server.respond(); // Process all requests so far
this.server.respond(); // Process all requests so far
expect(this.proctored_exam_attempt_view.$el.find('tr.allowance-items')).toContainHtml('<td> testuser1 </td>'); expect(this.proctored_exam_attempt_view.$el.find('tr.allowance-items')).toContainHtml('<td> testuser1 </td>');
expect(this.proctored_exam_attempt_view.$el.find('tr.allowance-items').html()).toContain('Normal Exam'); expect(this.proctored_exam_attempt_view.$el.find('tr.allowance-items').html()).toContain('Normal Exam');
}); });
...@@ -175,15 +168,7 @@ describe('ProctoredExamView', function () { ...@@ -175,15 +168,7 @@ describe('ProctoredExamView', function () {
JSON.stringify(expectedProctoredExamAttemptJson) JSON.stringify(expectedProctoredExamAttemptJson)
] ]
); );
this.proctored_exam_attempt_view = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptView();
var callbacks = [sinon.spy(), sinon.spy()];
this.proctored_exam_attempt_view = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptView(
{
el: $('.student-proctored-exam-container'),
template_url: '/static/proctoring/templates/student-proctored-exam-attempts.underscore'
}
);
// Process all requests so far // Process all requests so far
this.server.respond(); this.server.respond();
...@@ -242,14 +227,7 @@ describe('ProctoredExamView', function () { ...@@ -242,14 +227,7 @@ describe('ProctoredExamView', function () {
] ]
); );
var callbacks = [sinon.spy(), sinon.spy()]; this.proctored_exam_attempt_view = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptView();
this.proctored_exam_attempt_view = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptView(
{
el: $('.student-proctored-exam-container'),
template_url: '/static/proctoring/templates/student-proctored-exam-attempts.underscore'
}
);
// Process all requests so far // Process all requests so far
this.server.respond(); this.server.respond();
...@@ -293,15 +271,7 @@ describe('ProctoredExamView', function () { ...@@ -293,15 +271,7 @@ describe('ProctoredExamView', function () {
JSON.stringify(expectedProctoredExamAttemptJson) JSON.stringify(expectedProctoredExamAttemptJson)
] ]
); );
this.proctored_exam_attempt_view = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptView();
var callbacks = [sinon.spy(), sinon.spy()];
this.proctored_exam_attempt_view = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptView(
{
el: $('.student-proctored-exam-container'),
template_url: '/static/proctoring/templates/student-proctored-exam-attempts.underscore'
}
);
// Process all requests so far // Process all requests so far
this.server.respond(); this.server.respond();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment