Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
Added tests for the schedule parser, and moved it to it's own file
Browse files Browse the repository at this point in the history
Modified the linter
  • Loading branch information
JGulbronson committed Apr 19, 2014
1 parent 3bf3013 commit 6ce1a5e
Show file tree
Hide file tree
Showing 8 changed files with 866 additions and 283 deletions.
12 changes: 10 additions & 2 deletions server/static/js/js_tests/main.js
@@ -1,11 +1,15 @@
// TODO(jeff): Reuse main.js from the main Javascript folder, adding in the
// testing libraries mocha and chai
require.config({
baseUrl: '../',
paths: {
'ext/jquery': 'ext/jquery-1.8.1',
'ext/underscore': 'ext/underscore-1.3.3',
'ext/underscore.string': 'ext/underscore.string-2.0.0',
'moment': 'ext/moment',
'moment-timezone': 'ext/moment-timezone',
'mocha': 'js_tests/vendor/mocha',
'chai': 'js_tests/vendor/chai',
'chai': 'js_tests/vendor/chai'
},
shim: {
'ext/underscore': {
Expand All @@ -20,7 +24,10 @@ require.config({
return _.string;
}
},
},
'ext/moment': {
exports: 'moment'
}
}
});

require(['require', 'chai', 'mocha', 'ext/jquery'],
Expand All @@ -31,6 +38,7 @@ require(['require', 'chai', 'mocha', 'ext/jquery'],

require([
'transcript_test.js',
'schedule_test.js'
], function(require) {
mocha.run();
});
Expand Down
110 changes: 110 additions & 0 deletions server/static/js/js_tests/schedule_test.js
@@ -0,0 +1,110 @@
define(function(require) {
var expect = require('chai').expect;
var $ = require('jquery');
var schedule_parser = require('schedule_parser');

describe('Schedule parsing', function() {
var parsedSchedulePromise = $.get(
'/sample_schedule.txt').then(function(r) {
return schedule_parser.parseSchedule(r);
});

it('extracts the term name', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.term_name).to.equal("Winter 2014");
done();
});
});

it('produces no failed items', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.failed_items.length).to.equal(0);
done();
});
});

it('extracts the correct number of items', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.processed_items.length).to.equal(343);
done();
});
});

it('extracts the first item\'s building', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.processed_items[0].building).to.equal("OPT");
done();
});
});

it('extracts the first item\'s course ID', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.processed_items[0].course_id).to.equal("cs138");
done();
});
});

it('extracts the first item\'s prof name', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.processed_items[0].prof_name).to.equal(
"Michael Godfrey");
done();
});
});

it('extracts the first item\'s start date', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.processed_items[0].start_date).to.equal(
1389106800);
done();
});
});

it('extracts the first item\'s end date', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.processed_items[0].end_date).to.equal(
1389111600);
done();
});
});

it('extracts the last item\'s building', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.processed_items[342].building).to.equal("DC");
done();
});
});

it('extracts the last item\'s course ID', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.processed_items[342].course_id).to.equal(
"stat230");
done();
});
});

it('extracts the last item\'s prof name', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.processed_items[342].prof_name).to.equal(
"Christian Boudreau");
done();
});
});

it('extracts the last item\'s start date', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.processed_items[342].start_date).to.equal(
1396629000);
done();
});
});

it('extracts the last item\'s end date', function(done) {
parsedSchedulePromise.then(function(scheduleData) {
expect(scheduleData.processed_items[342].end_date).to.equal(
1396632000);
done();
});
});
});
});
2 changes: 0 additions & 2 deletions server/static/js/js_tests/transcript_test.js
@@ -1,5 +1,3 @@
/* global it, describe */

define(function(require) {
var expect = require('chai').expect;
var transcript = require('transcript');
Expand Down

0 comments on commit 6ce1a5e

Please sign in to comment.