Commit 8a5d8b5c by Nickersoft

Added test coverage to create/edit view

parent b2d74f0d
......@@ -11,7 +11,10 @@ var isBrowser = window.__karma__ === undefined,
if (isBrowser) {
// The browser cannot read directories, so all files must be enumerated below.
specs = [
config.baseUrl + 'js/test/specs/test_spec.js'
config.baseUrl + 'js/test/specs/course_create_view_spec.js',
config.baseUrl + 'js/test/specs/course_edit_view_spec.js',
config.baseUrl + 'js/test/specs/course_detail_view_spec.js',
config.baseUrl + 'js/test/specs/course_list_view_spec.js'
];
} else {
// the E-Commerce application loads gettext identity library via django, thus
......
define([
'jquery',
'views/course_create_edit_view',
'views/alert_view',
'models/course_model'
],
function ($,
CourseCreateEditView,
AlertView,
Course) {
'use strict';
describe('course create view', function () {
var view,
model;
beforeEach(function () {
model = new Course();
view = new CourseCreateEditView({ model: model, editing: false }).render();
});
it('should throw an error if submitted with blank fields', function () {
var errorHTML = '<strong>Error!</strong> Please complete all required fields.';
view.formView.submit($.Event('click'));
expect(view.$el.find('.alert').length).toBe(1);
expect(view.$el.find('.alert').html()).toBe(errorHTML);
});
});
}
);
define([
'underscore.string',
'moment',
'views/course_create_edit_view',
'views/course_seat_form_fields/honor_course_seat_form_field_view',
'views/course_seat_form_fields/verified_course_seat_form_field_view',
'models/course_model',
'utils/utils',
],
function (_s,
moment,
CourseCreateEditView,
HonorCourseSeatFormFieldView,
VerifiedCourseSeatFormFieldView,
Course,
Utils) {
'use strict';
describe('course edit view', function () {
var view,
model,
data = {
id: 'edX/DemoX/Demo_Course',
url: 'http://ecommerce.local:8002/api/v2/courses/edX/DemoX/Demo_Course/',
name: 'edX Demonstration Course',
verification_deadline: null,
type: 'verified',
products_url: 'http://ecommerce.local:8002/api/v2/courses/edX/DemoX/Demo_Course/products/',
last_edited: '2015-07-27T00:27:23Z',
products: [
{
id: 9,
url: 'http://ecommerce.local:8002/api/v2/products/9/',
structure: 'child',
product_class: 'Seat',
title: 'Seat in edX Demonstration Course with honor certificate',
price: '0.00',
expires: null,
attribute_values: [
{
name: 'certificate_type',
value: 'honor'
},
{
name: 'course_key',
value: 'edX/DemoX/Demo_Course'
},
{
name: 'id_verification_required',
value: false
}
],
is_available_to_buy: true
},
{
id: 8,
url: 'http://ecommerce.local:8002/api/v2/products/8/',
structure: 'child',
product_class: 'Seat',
title: 'Seat in edX Demonstration Course with verified certificate (and ID verification)',
price: '15.00',
expires: '2020-01-01T00:00:00Z',
attribute_values: [
{
name: 'certificate_type',
value: 'verified'
},
{
name: 'course_key',
value: 'edX/DemoX/Demo_Course'
},
{
name: 'id_verification_required',
value: true
}
],
is_available_to_buy: true
},
{
id: 7,
url: 'http://ecommerce.local:8002/api/v2/products/7/',
structure: 'parent',
product_class: 'Seat',
title: 'Seat in edX Demonstration Course',
price: null,
expires: null,
attribute_values: [
{
name: 'course_key',
value: 'edX/DemoX/Demo_Course'
}
],
is_available_to_buy: false
}
]
};
beforeEach(function () {
model = Course.findOrCreate(data, {parse: true});
view = new CourseCreateEditView({ model: model, editing: true }).render();
});
it('should display course details in form fields', function () {
var checked_radios = view.$el.find('.course-types input[type=radio]:checked'),
type_label = checked_radios.siblings('.course-type-display-name');
expect(view.$el.find('[name=id]').val()).toEqual(model.get('id'));
expect(view.$el.find('[name=name]').val()).toEqual(model.get('name'));
expect(type_label.text()).toEqual(_s.capitalize(model.get('type')));
});
it('should display correct course seats given course type', function () {
var honorElement = view.$el.find('.row.course-seat.honor'),
verifiedElement = view.$el.find('.row.course-seat.verified');
expect(honorElement.length).toBe(1);
expect(honorElement.find('.seat-price').text()).toBe('$0.00');
expect(verifiedElement.length).toBe(1);
expect(verifiedElement.find('[name=price]').val()).toBe('15.00');
expect(verifiedElement.find('[name=expires]').val()).toBe(Utils.stripTimezone('2020-01-01T00:00:00Z'));
});
it('should remove the edit form if the view is removed', function () {
view.remove();
expect(view.$el.find('.course-form-view').length).toEqual(0);
});
});
}
);
......@@ -48,7 +48,7 @@ define([
*/
stripTimezone: function (datetime) {
if (datetime) {
datetime = moment.utc(datetime).format('YYYY-MM-DDTHH:mm:ss');
datetime = moment.utc(new Date(datetime)).format('YYYY-MM-DDTHH:mm:ss');
}
return datetime;
......
......@@ -4,7 +4,8 @@ define([
'backbone.super',
'underscore',
'views/course_form_view',
'text!templates/course_create_edit.html'
'text!templates/course_create_edit.html',
'bootstrap'
],
function ($,
Backbone,
......
......@@ -4,7 +4,7 @@
aria-describedby="courseType<%= type %>HelpBlock"
<% if(disabled) { print('disabled="disabled"'); } %>
<% if(checked) { print('checked'); } %>>
<%= displayName %>
<div class="course-type-display-name"><%= displayName %></div>
<span id="courseType<%= type %>HelpBlock" class="help-block">
<%= helpText %>
</span>
......
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