WL-124 added the jasmine tests for the autoenrollment csv
Added bokchoy tests and assets (csv files) for CSV auto reg and enrollment. Set the env flag "ALLOW_AUTOMATED_SIGNUPS": true in bok_choy.env.json Resolved quality issues. resolved cherry pick conflicts Improved bokchoy tests as per code review suggestions. added the BDD in the docstrings for all the test scenarios changed the bok choy test string Improved bokchoy tests as per further code review suggestions. Made a MembershipPageAutoEnrollSection a separate PageObject.
This commit is contained in:
committed by
Afzal Wali
parent
ec74398d74
commit
97b45cc2a7
20
lms/static/coffee/fixtures/autoenrollment.html
Normal file
20
lms/static/coffee/fixtures/autoenrollment.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<div class="auto_enroll auto_enroll_csv">
|
||||
<h2> ${_("Register/Enroll Students")} </h2>
|
||||
|
||||
<p>
|
||||
${_("To register and enroll a list of users in this course, choose a CSV file that contains the following columns in this exact order: email, username, name, and country. Please include one student per row and do not include any headers, footers, or blank lines.")}
|
||||
</p>
|
||||
|
||||
<form id="student-auto-enroll-form">
|
||||
<div class="customBrowseBtn">
|
||||
<input disabled="disabled" id="browseFile" placeholder="choose file"/>
|
||||
|
||||
<div class="file-browse btn btn-primary">
|
||||
<span class="browse"> Browse </span>
|
||||
<input class="file_field" id="browseBtn" name="students_list" type="file" accept=".csv"/>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" name="enrollment_signup_button">${_("Upload CSV")}</button>
|
||||
</form>
|
||||
<div class="results"></div>
|
||||
</div>
|
||||
@@ -0,0 +1,73 @@
|
||||
describe 'AutoEnrollment', ->
|
||||
beforeEach ->
|
||||
loadFixtures 'coffee/fixtures/autoenrollment.html'
|
||||
@autoenrollment = new AutoEnrollmentViaCsv $('.auto_enroll_csv')
|
||||
|
||||
it 'binds to the enrollment_signup_button on click event', ->
|
||||
expect(@autoenrollment.$enrollment_signup_button).toHandle 'click'
|
||||
|
||||
it 'binds to the browse button on change event', ->
|
||||
expect(@autoenrollment.$browse_button).toHandle 'change'
|
||||
|
||||
it 'binds the ajax call and the result will be success', ->
|
||||
spyOn($, "ajax").andCallFake((params) =>
|
||||
params.success({row_errors: [], general_errors: [], warnings: []})
|
||||
{always: ->}
|
||||
)
|
||||
# mock the render_notification_view which returns the html (since we are only using the existing notification model)
|
||||
@autoenrollment.render_notification_view = jasmine.createSpy("render_notification_view(type, title, message, details) spy").andCallFake =>
|
||||
return '<div><div class="message message-confirmation"><h3 class="message-title">Success</h3><div class="message-copy"><p>All accounts were created successfully.</p></div></div><div>'
|
||||
|
||||
submitCallback = jasmine.createSpy().andReturn()
|
||||
@autoenrollment.$student_enrollment_form.submit(submitCallback)
|
||||
@autoenrollment.$enrollment_signup_button.click()
|
||||
expect($('.results .message-copy').text()).toEqual('All accounts were created successfully.')
|
||||
expect(submitCallback).toHaveBeenCalled()
|
||||
|
||||
it 'binds the ajax call and the result will be error', ->
|
||||
spyOn($, "ajax").andCallFake((params) =>
|
||||
params.success({
|
||||
row_errors: [{
|
||||
'username': 'testuser1',
|
||||
'email': 'testemail1@email.com',
|
||||
'response': 'Username already exists'
|
||||
}],
|
||||
general_errors: [{
|
||||
'response': 'cannot read the line 2'
|
||||
}],
|
||||
warnings: []
|
||||
})
|
||||
{always: ->}
|
||||
)
|
||||
# mock the render_notification_view which returns the html (since we are only using the existing notification model)
|
||||
@autoenrollment.render_notification_view = jasmine.createSpy("render_notification_view(type, title, message, details) spy").andCallFake =>
|
||||
return '<div><div class="message message-error"><h3 class="message-title">Errors</h3><div class="message-copy"><p>The following errors were generated:</p><ul class="list-summary summary-items"><li class="summary-item">cannot read the line 2</li><li class="summary-item">testuser1 (testemail1@email.com): (Username already exists)</li></ul></div></div></div>'
|
||||
|
||||
submitCallback = jasmine.createSpy().andReturn()
|
||||
@autoenrollment.$student_enrollment_form.submit(submitCallback)
|
||||
@autoenrollment.$enrollment_signup_button.click()
|
||||
expect($('.results .list-summary').text()).toEqual('cannot read the line 2testuser1 (testemail1@email.com): (Username already exists)');
|
||||
expect(submitCallback).toHaveBeenCalled()
|
||||
|
||||
it 'binds the ajax call and the result will be warnings', ->
|
||||
spyOn($, "ajax").andCallFake((params) =>
|
||||
params.success({
|
||||
row_errors: [],
|
||||
general_errors: [],
|
||||
warnings: [{
|
||||
'username': 'user1',
|
||||
'email': 'user1email',
|
||||
'response': 'email is in valid'
|
||||
}]
|
||||
})
|
||||
{always: ->}
|
||||
)
|
||||
# mock the render_notification_view which returns the html (since we are only using the existing notification model)
|
||||
@autoenrollment.render_notification_view = jasmine.createSpy("render_notification_view(type, title, message, details) spy").andCallFake =>
|
||||
return '<div><div class="message message-warning"><h3 class="message-title">Warnings</h3><div class="message-copy"><p>The following warnings were generated:</p><ul class="list-summary summary-items"><li class="summary-item">user1 (user1email): (email is in valid)</li></ul></div></div></div>'
|
||||
|
||||
submitCallback = jasmine.createSpy().andReturn()
|
||||
@autoenrollment.$student_enrollment_form.submit(submitCallback)
|
||||
@autoenrollment.$enrollment_signup_button.click()
|
||||
expect($('.results .list-summary').text()).toEqual('user1 (user1email): (email is in valid)')
|
||||
expect(submitCallback).toHaveBeenCalled()
|
||||
@@ -174,7 +174,7 @@ class AuthListWidget extends MemberListWidget
|
||||
else
|
||||
@reload_list()
|
||||
|
||||
class AutoEnrollmentViaCsv
|
||||
class @AutoEnrollmentViaCsv
|
||||
constructor: (@$container) ->
|
||||
# Wrapper for the AutoEnrollmentViaCsv subsection.
|
||||
# This object handles buttons, success and failure reporting,
|
||||
@@ -220,7 +220,6 @@ class AutoEnrollmentViaCsv
|
||||
@$results.empty()
|
||||
errors = []
|
||||
warnings = []
|
||||
|
||||
result_from_server_is_success = true
|
||||
|
||||
if data_from_server.general_errors.length
|
||||
@@ -241,41 +240,35 @@ class AutoEnrollmentViaCsv
|
||||
warning['is_general_error'] = false
|
||||
warnings.push warning
|
||||
|
||||
render_response = (label, type, student_results) =>
|
||||
if type is 'success'
|
||||
task_res_section = $ '<div/>', class: 'message message-confirmation'
|
||||
message_title = $ '<h3/>', class: 'message-title', text: label
|
||||
task_res_section.append message_title
|
||||
@$results.append task_res_section
|
||||
return
|
||||
|
||||
if type is 'error'
|
||||
task_res_section = $ '<div/>', class: 'message message-error'
|
||||
if type is 'warning'
|
||||
task_res_section = $ '<div/>', class: 'message message-warning'
|
||||
|
||||
message_title = $ '<h3/>', class: 'message-title', text: label
|
||||
task_res_section. append message_title
|
||||
messages_copy = $ '<div/>', class: 'message-copy'
|
||||
task_res_section. append messages_copy
|
||||
messages_summary = $ '<ul/>', class: 'list-summary summary-items'
|
||||
messages_copy.append messages_summary
|
||||
|
||||
render_response = (title, message, type, student_results) =>
|
||||
details = []
|
||||
for student_result in student_results
|
||||
if student_result.is_general_error
|
||||
response_message = student_result.response
|
||||
details.push student_result.response
|
||||
else
|
||||
response_message = student_result.username + ' ('+ student_result.email + '): ' + ' (' + student_result.response + ')'
|
||||
messages_summary.append $ '<li/>', class: 'summary-item', text: response_message
|
||||
details.push response_message
|
||||
|
||||
@$results.append task_res_section
|
||||
@$results.append @render_notification_view type, title, message, details
|
||||
|
||||
if errors.length
|
||||
render_response gettext("The following errors were generated:"), 'error', errors
|
||||
render_response gettext('Errors'), gettext("The following errors were generated:"), 'error', errors
|
||||
if warnings.length
|
||||
render_response gettext("The following warnings were generated:"), 'warning', warnings
|
||||
render_response gettext('Warnings'), gettext("The following warnings were generated:"), 'warning', warnings
|
||||
if result_from_server_is_success
|
||||
render_response gettext("All accounts were created successfully."), 'success', []
|
||||
render_response gettext('Success'), gettext("All accounts were created successfully."), 'confirmation', []
|
||||
|
||||
render_notification_view: (type, title, message, details) ->
|
||||
notification_model = new NotificationModel()
|
||||
notification_model.set({
|
||||
'type': type,
|
||||
'title': title,
|
||||
'message': message,
|
||||
'details': details,
|
||||
});
|
||||
view = new NotificationView(model:notification_model);
|
||||
view.render()
|
||||
return view.$el.html()
|
||||
|
||||
class BetaTesterBulkAddition
|
||||
constructor: (@$container) ->
|
||||
|
||||
Reference in New Issue
Block a user