Commit 1cd050f9 by Clinton Blackburn

Properly wrapping tests

Updated offending tests with a describe block representing the object being tested (e.g. course model). This will result in a proper grouping of specs when Jasmine displays the results.
parent f1e16b16
......@@ -25,18 +25,20 @@ define([
collection = new CourseCollection();
});
describe('parse', function () {
it('should return the results list in the response', function () {
expect(collection.parse(response)).toEqual(response.results);
});
describe('Course collection', function () {
describe('parse', function () {
it('should return the results list in the response', function () {
expect(collection.parse(response)).toEqual(response.results);
});
it('should fetch the next page of results', function () {
spyOn(collection, 'fetch').and.returnValue(null);
response.next = '/api/v2/courses/?page=2';
it('should fetch the next page of results', function () {
spyOn(collection, 'fetch').and.returnValue(null);
response.next = '/api/v2/courses/?page=2';
collection.parse(response);
expect(collection.url).toEqual(response.next);
expect(collection.fetch).toHaveBeenCalledWith({remove: false});
collection.parse(response);
expect(collection.url).toEqual(response.next);
expect(collection.fetch).toHaveBeenCalledWith({remove: false});
});
});
});
}
......
......@@ -98,123 +98,125 @@ define([
model = Course.findOrCreate(data, {parse: true});
});
describe('removeParentProducts', function () {
it('should remove all parent products from the products collection', function () {
var products = model.get('products');
describe('Course model', function () {
describe('removeParentProducts', function () {
it('should remove all parent products from the products collection', function () {
var products = model.get('products');
// Sanity check to ensure the products were properly parsed
expect(products.length).toEqual(3);
// Sanity check to ensure the products were properly parsed
expect(products.length).toEqual(3);
// Remove the parent products
model.removeParentProducts();
// Remove the parent products
model.removeParentProducts();
// Only the children survived...
expect(products.length).toEqual(2);
expect(products.where({structure: 'child'}).length).toEqual(2);
// Only the children survived...
expect(products.length).toEqual(2);
expect(products.where({structure: 'child'}).length).toEqual(2);
});
});
});
// NOTE (CCB): There is a bug preventing this from being called 'toJSON'.
// See https://github.com/karma-runner/karma/issues/1534.
describe('#toJSON', function () {
it('should not modify verification_deadline if verification_deadline is empty', function () {
var json,
values = [null, ''];
_.each(values, function (value) {
model.set('verification_deadline', value);
json = model.toJSON();
expect(json.verification_deadline).toEqual(value);
// NOTE (CCB): There is a bug preventing this from being called 'toJSON'.
// See https://github.com/karma-runner/karma/issues/1534.
describe('#toJSON', function () {
it('should not modify verification_deadline if verification_deadline is empty', function () {
var json,
values = [null, ''];
_.each(values, function (value) {
model.set('verification_deadline', value);
json = model.toJSON();
expect(json.verification_deadline).toEqual(value);
});
});
});
it('should add a timezone to verification_deadline if verification_deadline is not empty', function () {
var json,
deadline = '2015-01-01T00:00:00';
it('should add a timezone to verification_deadline if verification_deadline is not empty', function () {
var json,
deadline = '2015-01-01T00:00:00';
model.set('verification_deadline', deadline);
json = model.toJSON();
model.set('verification_deadline', deadline);
json = model.toJSON();
expect(json.verification_deadline).toEqual(deadline + '+00:00');
expect(json.verification_deadline).toEqual(deadline + '+00:00');
});
});
});
describe('save', function () {
var expectedAjaxData = function (data) {
var products,
expected = {
id: data.id,
name: data.name,
verification_deadline: moment.utc(data.verification_deadline).format()
};
describe('save', function () {
var expectedAjaxData = function (data) {
var products,
expected = {
id: data.id,
name: data.name,
verification_deadline: moment.utc(data.verification_deadline).format()
};
products = _.filter(data.products, function (product) {
return product.structure === 'child';
});
products = _.filter(data.products, function (product) {
return product.structure === 'child';
});
expected.products = _.map(products, function (product) {
return product;
});
expected.products = _.map(products, function (product) {
return product;
});
return expected;
};
return expected;
};
it('should POST to the publication endpoint', function () {
var args,
cookie = 'save-test';
it('should POST to the publication endpoint', function () {
var args,
cookie = 'save-test';
spyOn($, 'ajax');
$.cookie('ecommerce_csrftoken', cookie);
spyOn($, 'ajax');
$.cookie('ecommerce_csrftoken', cookie);
model.save();
model.save();
// $.ajax should have been called
expect($.ajax).toHaveBeenCalled();
// $.ajax should have been called
expect($.ajax).toHaveBeenCalled();
// Ensure the data was POSTed to the correct endpoint
args = $.ajax.calls.argsFor(0)[0];
expect(args.type).toEqual('POST');
expect(args.url).toEqual('/api/v2/publication/');
expect(args.contentType).toEqual('application/json');
expect(args.headers).toEqual({'X-CSRFToken': cookie});
expect(JSON.parse(args.data)).toEqual(expectedAjaxData(data));
// Ensure the data was POSTed to the correct endpoint
args = $.ajax.calls.argsFor(0)[0];
expect(args.type).toEqual('POST');
expect(args.url).toEqual('/api/v2/publication/');
expect(args.contentType).toEqual('application/json');
expect(args.headers).toEqual({'X-CSRFToken': cookie});
expect(JSON.parse(args.data)).toEqual(expectedAjaxData(data));
});
});
});
describe('getOrCreateSeat', function () {
it('should return existing seats', function () {
var mapping = {
'honor': honorSeat,
'verified': verifiedSeat
};
describe('getOrCreateSeat', function () {
it('should return existing seats', function () {
var mapping = {
'honor': honorSeat,
'verified': verifiedSeat
};
_.each(mapping, function (expected, seatType) {
expect(model.getOrCreateSeat(seatType).toJSON()).toEqual(expected);
_.each(mapping, function (expected, seatType) {
expect(model.getOrCreateSeat(seatType).toJSON()).toEqual(expected);
});
});
});
it('should return null if an audit seat does not already exist', function () {
expect(model.getOrCreateSeat('audit')).toBeUndefined();
});
it('should return null if an audit seat does not already exist', function () {
expect(model.getOrCreateSeat('audit')).toBeUndefined();
});
it('should create a new CourseSeat if one does not exist', function () {
var seat;
it('should create a new CourseSeat if one does not exist', function () {
var seat;
// Sanity check to confirm a new seat is created later
expect(model.seats().length).toEqual(2);
// Sanity check to confirm a new seat is created later
expect(model.seats().length).toEqual(2);
// A new seat should be created
seat = model.getOrCreateSeat('professional');
expect(model.seats().length).toEqual(3);
// A new seat should be created
seat = model.getOrCreateSeat('professional');
expect(model.seats().length).toEqual(3);
// The new seat's class/type should correspond to the passed in seat type
expect(seat).toEqual(jasmine.any(ProfessionalSeat));
// The new seat's class/type should correspond to the passed in seat type
expect(seat).toEqual(jasmine.any(ProfessionalSeat));
});
});
});
describe('products', function () {
it('is a ProductCollection', function () {
expect(model.get('products')).toEqual(jasmine.any(ProductCollection));
describe('products', function () {
it('is a ProductCollection', function () {
expect(model.get('products')).toEqual(jasmine.any(ProductCollection));
});
});
});
}
......
......@@ -36,80 +36,82 @@ define([
model = CourseSeat.findOrCreate(data, {parse: true});
});
describe('getSeatType', function () {
it('should return a seat type corresponding to the certificate type', function () {
var mappings = {
'credit': 'credit',
'honor': 'honor',
'no-id-professional': 'professional',
'professional': 'professional',
'verified': 'verified'
};
describe('Course seat model', function () {
describe('getSeatType', function () {
it('should return a seat type corresponding to the certificate type', function () {
var mappings = {
'credit': 'credit',
'honor': 'honor',
'no-id-professional': 'professional',
'professional': 'professional',
'verified': 'verified'
};
_.each(mappings, function (seatType, certificateType) {
model.set('certificate_type', certificateType);
expect(model.getSeatType()).toEqual(seatType);
_.each(mappings, function (seatType, certificateType) {
model.set('certificate_type', certificateType);
expect(model.getSeatType()).toEqual(seatType);
});
});
});
it('should return audit for empty certificate types', function () {
var certificate_types = ['', null];
it('should return audit for empty certificate types', function () {
var certificate_types = ['', null];
_.each(certificate_types, function (certificateType) {
model.set('certificate_type', certificateType);
expect(model.getSeatType()).toEqual('audit');
_.each(certificate_types, function (certificateType) {
model.set('certificate_type', certificateType);
expect(model.getSeatType()).toEqual('audit');
});
});
});
});
describe('getSeatTypeDisplayName', function () {
it('should return a value corresponding to the certificate type', function () {
var mappings = {
'credit': 'Credit',
'honor': 'Honor',
'no-id-professional': 'Professional',
'professional': 'Professional',
'verified': 'Verified'
};
describe('getSeatTypeDisplayName', function () {
it('should return a value corresponding to the certificate type', function () {
var mappings = {
'credit': 'Credit',
'honor': 'Honor',
'no-id-professional': 'Professional',
'professional': 'Professional',
'verified': 'Verified'
};
_.each(mappings, function (seatType, certificateType) {
model.set('certificate_type', certificateType);
expect(model.getSeatTypeDisplayName()).toEqual(seatType);
_.each(mappings, function (seatType, certificateType) {
model.set('certificate_type', certificateType);
expect(model.getSeatTypeDisplayName()).toEqual(seatType);
});
});
});
it('should return Audit for empty certificate types', function () {
var certificate_types = ['', null];
it('should return Audit for empty certificate types', function () {
var certificate_types = ['', null];
_.each(certificate_types, function (certificateType) {
model.set('certificate_type', certificateType);
expect(model.getSeatTypeDisplayName()).toEqual('Audit');
_.each(certificate_types, function (certificateType) {
model.set('certificate_type', certificateType);
expect(model.getSeatTypeDisplayName()).toEqual('Audit');
});
});
});
});
describe('getCertificateDisplayName', function () {
it('should return a value corresponding to the certificate type', function () {
var mappings = {
'credit': 'Verified Certificate',
'honor': 'Honor Certificate',
'no-id-professional': 'Professional Certificate',
'professional': 'Professional Certificate',
'verified': 'Verified Certificate'
};
describe('getCertificateDisplayName', function () {
it('should return a value corresponding to the certificate type', function () {
var mappings = {
'credit': 'Verified Certificate',
'honor': 'Honor Certificate',
'no-id-professional': 'Professional Certificate',
'professional': 'Professional Certificate',
'verified': 'Verified Certificate'
};
_.each(mappings, function (seatType, certificateType) {
model.set('certificate_type', certificateType);
expect(model.getCertificateDisplayName()).toEqual(seatType);
_.each(mappings, function (seatType, certificateType) {
model.set('certificate_type', certificateType);
expect(model.getCertificateDisplayName()).toEqual(seatType);
});
});
});
it('should return (No Certificate) for empty certificate types', function () {
var certificate_types = ['', null];
it('should return (No Certificate) for empty certificate types', function () {
var certificate_types = ['', null];
_.each(certificate_types, function (certificateType) {
model.set('certificate_type', certificateType);
expect(model.getCertificateDisplayName()).toEqual('(No Certificate)');
_.each(certificate_types, function (certificateType) {
model.set('certificate_type', certificateType);
expect(model.getCertificateDisplayName()).toEqual('(No Certificate)');
});
});
});
});
......
......@@ -36,40 +36,42 @@ define([
model = Product.findOrCreate(data, {parse: true});
});
// NOTE (CCB): There is a bug preventing this from being called 'toJSON'.
// See https://github.com/karma-runner/karma/issues/1534.
describe('#toJSON', function () {
it('should not modify expires if expires is empty', function () {
var json,
values = [null, ''];
describe('Product model', function () {
// NOTE (CCB): There is a bug preventing this from being called 'toJSON'.
// See https://github.com/karma-runner/karma/issues/1534.
describe('#toJSON', function () {
it('should not modify expires if expires is empty', function () {
var json,
values = [null, ''];
_.each(values, function (value) {
model.set('expires', value);
json = model.toJSON();
expect(json.expires).toEqual(value);
_.each(values, function (value) {
model.set('expires', value);
json = model.toJSON();
expect(json.expires).toEqual(value);
});
});
});
it('should add a timezone to expires if expires is not empty', function () {
var json,
deadline = '2015-01-01T00:00:00';
it('should add a timezone to expires if expires is not empty', function () {
var json,
deadline = '2015-01-01T00:00:00';
model.set('expires', deadline);
json = model.toJSON();
model.set('expires', deadline);
json = model.toJSON();
expect(json.expires).toEqual(deadline + '+00:00');
});
expect(json.expires).toEqual(deadline + '+00:00');
});
it('should re-nest the un-nested attributes', function () {
var json = model.toJSON();
it('should re-nest the un-nested attributes', function () {
var json = model.toJSON();
// Sanity check
expect(model.get('certificate_type')).toEqual('verified');
expect(model.get('course_key')).toEqual('edX/DemoX/Demo_Course');
expect(model.get('id_verification_required')).toEqual(true);
// Sanity check
expect(model.get('certificate_type')).toEqual('verified');
expect(model.get('course_key')).toEqual('edX/DemoX/Demo_Course');
expect(model.get('id_verification_required')).toEqual(true);
// Very the attributes have been re-nested
expect(json.attribute_values).toEqual(data.attribute_values);
// Very the attributes have been re-nested
expect(json.attribute_values).toEqual(data.attribute_values);
});
});
});
}
......
......@@ -16,28 +16,30 @@ define([
VerifiedSeat) {
'use strict';
describe('getCourseSeatModel', function () {
it('should return the CourseSeat child class corresponding to a seat type', function () {
expect(CourseUtils.getCourseSeatModel('audit')).toEqual(AuditSeat);
expect(CourseUtils.getCourseSeatModel('honor')).toEqual(HonorSeat);
expect(CourseUtils.getCourseSeatModel('professional')).toEqual(ProfessionalSeat);
expect(CourseUtils.getCourseSeatModel('verified')).toEqual(VerifiedSeat);
});
describe('CourseUtils', function () {
describe('getCourseSeatModel', function () {
it('should return the CourseSeat child class corresponding to a seat type', function () {
expect(CourseUtils.getCourseSeatModel('audit')).toEqual(AuditSeat);
expect(CourseUtils.getCourseSeatModel('honor')).toEqual(HonorSeat);
expect(CourseUtils.getCourseSeatModel('professional')).toEqual(ProfessionalSeat);
expect(CourseUtils.getCourseSeatModel('verified')).toEqual(VerifiedSeat);
});
it('should return CourseSeat if the seat type is unknown', function () {
expect(CourseUtils.getCourseSeatModel(null)).toEqual(CourseSeat);
it('should return CourseSeat if the seat type is unknown', function () {
expect(CourseUtils.getCourseSeatModel(null)).toEqual(CourseSeat);
});
});
});
describe('orderSeatTypesForDisplay', function () {
it('should return a list ordered seat types', function () {
var data = [
['audit', 'professional', 'credit'],
['audit', 'honor', 'verified', 'professional', 'credit']
];
describe('orderSeatTypesForDisplay', function () {
it('should return a list ordered seat types', function () {
var data = [
['audit', 'professional', 'credit'],
['audit', 'honor', 'verified', 'professional', 'credit']
];
_.each(data, function (expected) {
expect(CourseUtils.orderSeatTypesForDisplay(_.shuffle(expected))).toEqual(expected);
_.each(data, function (expected) {
expect(CourseUtils.orderSeatTypesForDisplay(_.shuffle(expected))).toEqual(expected);
});
});
});
});
......
......@@ -4,29 +4,31 @@ define([
function (Utils) {
'use strict';
describe('stripTimezone', function () {
it('should return the input value if the input is empty', function () {
expect(Utils.stripTimezone('')).toEqual('');
expect(Utils.stripTimezone(null)).toBeNull();
expect(Utils.stripTimezone(undefined)).toBeUndefined();
});
describe('Utils', function () {
describe('stripTimezone', function () {
it('should return the input value if the input is empty', function () {
expect(Utils.stripTimezone('')).toEqual('');
expect(Utils.stripTimezone(null)).toBeNull();
expect(Utils.stripTimezone(undefined)).toBeUndefined();
});
it('should return the datetime without the timezone component', function () {
var dt = '2015-01-01T00:00:00';
expect(Utils.stripTimezone(dt + 'Z')).toEqual(dt);
it('should return the datetime without the timezone component', function () {
var dt = '2015-01-01T00:00:00';
expect(Utils.stripTimezone(dt + 'Z')).toEqual(dt);
});
});
});
describe('restoreTimezone', function () {
it('should return the input value if the input is empty', function () {
expect(Utils.restoreTimezone('')).toEqual('');
expect(Utils.restoreTimezone(null)).toBeNull();
expect(Utils.restoreTimezone(undefined)).toBeUndefined();
});
describe('restoreTimezone', function () {
it('should return the input value if the input is empty', function () {
expect(Utils.restoreTimezone('')).toEqual('');
expect(Utils.restoreTimezone(null)).toBeNull();
expect(Utils.restoreTimezone(undefined)).toBeUndefined();
});
it('should return the datetime with the timezone component', function () {
var dt = '2015-01-01T00:00:00';
expect(Utils.restoreTimezone(dt)).toEqual(dt + '+00:00');
it('should return the datetime with the timezone component', function () {
var dt = '2015-01-01T00:00:00';
expect(Utils.restoreTimezone(dt)).toEqual(dt + '+00:00');
});
});
});
}
......
......@@ -13,10 +13,12 @@ define([
view = new CourseSeatFormFieldView({model: model});
});
describe('cleanIdVerificationRequired', function () {
it('should always return a boolean', function () {
expect(view.cleanIdVerificationRequired('false')).toEqual(false);
expect(view.cleanIdVerificationRequired('true')).toEqual(true);
describe('course seat form field view', function () {
describe('cleanIdVerificationRequired', function () {
it('should always return a boolean', function () {
expect(view.cleanIdVerificationRequired('false')).toEqual(false);
expect(view.cleanIdVerificationRequired('true')).toEqual(true);
});
});
});
}
......
......@@ -13,22 +13,25 @@ define([
view = new CourseSeatFormFieldView({model: model}).render();
});
describe('getFieldValue', function () {
it('should return a boolean if the name is id_verification_required', function () {
// NOTE (CCB): Ideally _.each should be used here to loop over an array of Boolean values.
// However, the tests fail when that implementation is used, hence the repeated code.
model.set('id_verification_required', false);
expect(model.get('id_verification_required')).toEqual(false);
expect(view.getFieldValue('id_verification_required')).toEqual(false);
describe('professional course seat form field view', function () {
describe('getFieldValue', function () {
it('should return a boolean if the name is id_verification_required', function () {
// NOTE (CCB): Ideally _.each should be used here to loop over an array of Boolean values.
// However, the tests fail when that implementation is used, hence the repeated code.
model.set('id_verification_required', false);
expect(model.get('id_verification_required')).toEqual(false);
expect(view.getFieldValue('id_verification_required')).toEqual(false);
model.set('id_verification_required', true);
expect(model.get('id_verification_required')).toEqual(true);
expect(view.getFieldValue('id_verification_required')).toEqual(true);
});
model.set('id_verification_required', true);
expect(model.get('id_verification_required')).toEqual(true);
expect(view.getFieldValue('id_verification_required')).toEqual(true);
});
// NOTE (CCB): This test is flaky (hence it being skipped). Occasionally, calls to the parent class fail.
xit('should always return professional if the name is certificate_type', function () {
expect(view.getFieldValue('certificate_type')).toEqual('professional');
// NOTE (CCB): This test is flaky (hence it being skipped).
// Occasionally, calls to the parent class fail.
xit('should always return professional if the name is certificate_type', function () {
expect(view.getFieldValue('certificate_type')).toEqual('professional');
});
});
});
}
......
......@@ -13,16 +13,18 @@ define([
view = new VerifiedCourseSeatFormFieldView({model: model}).render();
});
describe('getData', function () {
it('should return the data from the DOM/model', function () {
var data = {
certificate_type: 'verified',
id_verification_required: 'true',
price: '100',
expires: ''
};
describe('verified course seat form field view', function () {
describe('getData', function () {
it('should return the data from the DOM/model', function () {
var data = {
certificate_type: 'verified',
id_verification_required: 'true',
price: '100',
expires: ''
};
expect(view.getData()).toEqual(data);
expect(view.getData()).toEqual(data);
});
});
});
}
......
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