Commit 5e24752c by Andy Armstrong

Add ability to run individual Jasmine tests

Note: this change also upgrades Jasmine to the latest version.
parent 808b3feb
...@@ -35,6 +35,10 @@ javascript: ...@@ -35,6 +35,10 @@ javascript:
node_modules/.bin/uglifyjs $(STATIC_JS)/src/oa_shared.js $(STATIC_JS)/src/*.js $(STATIC_JS)/src/studio/*.js > "$(STATIC_JS)/openassessment-studio.min.js" node_modules/.bin/uglifyjs $(STATIC_JS)/src/oa_shared.js $(STATIC_JS)/src/*.js $(STATIC_JS)/src/studio/*.js > "$(STATIC_JS)/openassessment-studio.min.js"
sass:
./scripts/sass.sh
install-test: install-test:
pip install -q -r requirements/test.txt pip install -q -r requirements/test.txt
...@@ -44,7 +48,7 @@ install-dev: ...@@ -44,7 +48,7 @@ install-dev:
gem install sass gem install sass
pip install -q -r requirements/dev.txt pip install -q -r requirements/dev.txt
install: install-wheels install-python install-js install-nltk-data install-test install-dev javascript install: install-wheels install-python install-js install-nltk-data install-test install-dev javascript sass
quality: quality:
jshint openassessment/xblock/static/js/src -c .jshintrc --verbose jshint openassessment/xblock/static/js/src -c .jshintrc --verbose
...@@ -52,11 +56,11 @@ quality: ...@@ -52,11 +56,11 @@ quality:
test: quality test: quality
./scripts/test.sh ./scripts/test.sh
test-js: render-templates:
./scripts/render-templates.sh
test-js: render-templates
./scripts/test-js.sh ./scripts/test-js.sh
test-js-debug: test-js-debug: render-templates
./scripts/js-debugger.sh ./scripts/js-debugger.sh
sass:
./scripts/sass.sh
...@@ -8,16 +8,19 @@ module.exports = function(config) { ...@@ -8,16 +8,19 @@ module.exports = function(config) {
plugins: [ plugins: [
'karma-coverage',
'karma-jasmine', 'karma-jasmine',
'karma-jasmine-jquery',
'karma-chrome-launcher', 'karma-chrome-launcher',
'karma-phantomjs-launcher', 'karma-phantomjs-launcher',
'karma-coverage',
'karma-sinon',
'karma-jasmine-html-reporter',
'karma-spec-reporter' 'karma-spec-reporter'
], ],
// frameworks to use // frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'], frameworks: ['jasmine-jquery', 'jasmine', 'sinon'],
// list of files / patterns to load in the browser // list of files / patterns to load in the browser
...@@ -60,7 +63,7 @@ module.exports = function(config) { ...@@ -60,7 +63,7 @@ module.exports = function(config) {
reporters: ['spec', 'coverage'], reporters: ['spec', 'coverage'],
coverageReporter: { coverageReporter: {
type : 'text' type : 'text'
}, },
// web server port // web server port
......
...@@ -44,26 +44,6 @@ describe("OpenAssessment.BaseView", function() { ...@@ -44,26 +44,6 @@ describe("OpenAssessment.BaseView", function() {
var server = null; var server = null;
var view = null; var view = null;
/**
Wait for subviews to load before executing callback.
Args:
callback (function): Function that takes no arguments.
**/
var loadSubviews = function(callback) {
runs(function() {
view.load();
});
waitsFor(function() {
return !$(".openassessment__steps__step").hasClass('is--loading');
});
runs(function() {
return callback();
});
};
beforeEach(function() { beforeEach(function() {
// Load the DOM fixture // Load the DOM fixture
loadFixtures('oa_base.html'); loadFixtures('oa_base.html');
...@@ -74,31 +54,29 @@ describe("OpenAssessment.BaseView", function() { ...@@ -74,31 +54,29 @@ describe("OpenAssessment.BaseView", function() {
// Create the object under test // Create the object under test
var el = $("#openassessment").get(0); var el = $("#openassessment").get(0);
view = new OpenAssessment.BaseView(runtime, el, server); view = new OpenAssessment.BaseView(runtime, el, server);
view.load();
expect($(".openassessment__steps__step").hasClass('is--loading')).toBeFalsy();
}); });
it("Loads each step", function() { it("Loads each step", function() {
loadSubviews(function() { expect(server.fragmentsLoaded).toContain("submission");
expect(server.fragmentsLoaded).toContain("submission"); expect(server.fragmentsLoaded).toContain("student_training");
expect(server.fragmentsLoaded).toContain("student_training"); expect(server.fragmentsLoaded).toContain("self_assessment");
expect(server.fragmentsLoaded).toContain("self_assessment"); expect(server.fragmentsLoaded).toContain("peer_assessment");
expect(server.fragmentsLoaded).toContain("peer_assessment"); expect(server.fragmentsLoaded).toContain("grade");
expect(server.fragmentsLoaded).toContain("grade");
});
}); });
it("Only load the peer section once on submit", function() { it("Only load the peer section once on submit", function() {
loadSubviews(function() { // Simulate a server error
// Simulate a server error view.peerView.peerAssess();
view.peerView.peerAssess(); var numPeerLoads = 0;
var numPeerLoads = 0; for (var i = 0; i < server.fragmentsLoaded.length; i++) {
for (var i = 0; i < server.fragmentsLoaded.length; i++) { if (server.fragmentsLoaded[i] == 'peer_assessment') {
if (server.fragmentsLoaded[i] == 'peer_assessment') { numPeerLoads++;
numPeerLoads++;
}
} }
// Peer should be called twice, once when loading the views, }
// and again after the peer has been assessed. // Peer should be called twice, once when loading the views,
expect(numPeerLoads).toBe(2); // and again after the peer has been assessed.
}); expect(numPeerLoads).toBe(2);
}); });
}); });
...@@ -59,7 +59,7 @@ describe("OpenAssessment.PeerView", function() { ...@@ -59,7 +59,7 @@ describe("OpenAssessment.PeerView", function() {
}); });
it("Sends a peer assessment to the server", function() { it("Sends a peer assessment to the server", function() {
spyOn(server, 'peerAssess').andCallThrough(); spyOn(server, 'peerAssess').and.callThrough();
// Select options in the rubric // Select options in the rubric
var optionsSelected = {}; var optionsSelected = {};
...@@ -90,7 +90,7 @@ describe("OpenAssessment.PeerView", function() { ...@@ -90,7 +90,7 @@ describe("OpenAssessment.PeerView", function() {
it("Re-enables the peer assess button on error", function() { it("Re-enables the peer assess button on error", function() {
// Simulate a server error // Simulate a server error
spyOn(server, 'peerAssess').andCallFake(function() { spyOn(server, 'peerAssess').and.callFake(function() {
expect(view.peerSubmitEnabled()).toBe(false); expect(view.peerSubmitEnabled()).toBe(false);
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
defer.rejectWith(this, ['ENOUNKNOWN', 'Error occurred!']); defer.rejectWith(this, ['ENOUNKNOWN', 'Error occurred!']);
...@@ -106,7 +106,7 @@ describe("OpenAssessment.PeerView", function() { ...@@ -106,7 +106,7 @@ describe("OpenAssessment.PeerView", function() {
jasmine.getFixtures().fixturesPath = 'base/fixtures'; jasmine.getFixtures().fixturesPath = 'base/fixtures';
loadFixtures('oa_peer_complete.html'); loadFixtures('oa_peer_complete.html');
// Simulate a server error // Simulate a server error
spyOn(server, 'renderContinuedPeer').andCallFake(function() { spyOn(server, 'renderContinuedPeer').and.callFake(function() {
expect(view.continueAssessmentEnabled()).toBe(false); expect(view.continueAssessmentEnabled()).toBe(false);
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
defer.rejectWith(this, ['Error occurred!']); defer.rejectWith(this, ['Error occurred!']);
......
...@@ -54,7 +54,7 @@ describe("OpenAssessment.SelfView", function() { ...@@ -54,7 +54,7 @@ describe("OpenAssessment.SelfView", function() {
}); });
it("Sends a self assessment to the server", function() { it("Sends a self assessment to the server", function() {
spyOn(server, 'selfAssess').andCallThrough(); spyOn(server, 'selfAssess').and.callThrough();
// Select options in the rubric // Select options in the rubric
var optionsSelected = {}; var optionsSelected = {};
...@@ -81,7 +81,7 @@ describe("OpenAssessment.SelfView", function() { ...@@ -81,7 +81,7 @@ describe("OpenAssessment.SelfView", function() {
it("Re-enables the self assess button on error", function() { it("Re-enables the self assess button on error", function() {
// Simulate a server error // Simulate a server error
spyOn(server, 'selfAssess').andCallFake(function() { spyOn(server, 'selfAssess').and.callFake(function() {
expect(view.selfSubmitEnabled()).toBe(false); expect(view.selfSubmitEnabled()).toBe(false);
return $.Deferred(function(defer) { return $.Deferred(function(defer) {
defer.rejectWith(this, ['ENOUNKNOWN', 'Error occurred!']); defer.rejectWith(this, ['ENOUNKNOWN', 'Error occurred!']);
......
...@@ -90,7 +90,7 @@ describe("OpenAssessment.StaffInfoView", function() { ...@@ -90,7 +90,7 @@ describe("OpenAssessment.StaffInfoView", function() {
"workflow_uuid": "abc123", "workflow_uuid": "abc123",
"msg": "Great success." "msg": "Great success."
}; };
spyOn(server, 'scheduleTraining').andCallThrough(); spyOn(server, 'scheduleTraining').and.callThrough();
// Load the fixture // Load the fixture
loadFixtures('oa_base.html'); loadFixtures('oa_base.html');
...@@ -131,7 +131,7 @@ describe("OpenAssessment.StaffInfoView", function() { ...@@ -131,7 +131,7 @@ describe("OpenAssessment.StaffInfoView", function() {
var view = new OpenAssessment.StaffInfoView(el, server, baseView); var view = new OpenAssessment.StaffInfoView(el, server, baseView);
view.load(); view.load();
spyOn(server, 'rescheduleUnfinishedTasks').andCallThrough(); spyOn(server, 'rescheduleUnfinishedTasks').and.callThrough();
// Test the Rescheduling // Test the Rescheduling
view.rescheduleUnfinishedTasks(); view.rescheduleUnfinishedTasks();
...@@ -151,7 +151,7 @@ describe("OpenAssessment.StaffInfoView", function() { ...@@ -151,7 +151,7 @@ describe("OpenAssessment.StaffInfoView", function() {
var view = new OpenAssessment.StaffInfoView(el, server, baseView); var view = new OpenAssessment.StaffInfoView(el, server, baseView);
view.load(); view.load();
spyOn(server, 'rescheduleUnfinishedTasks').andCallThrough(); spyOn(server, 'rescheduleUnfinishedTasks').and.callThrough();
// Test the Rescheduling // Test the Rescheduling
view.rescheduleUnfinishedTasks(); view.rescheduleUnfinishedTasks();
...@@ -163,7 +163,7 @@ describe("OpenAssessment.StaffInfoView", function() { ...@@ -163,7 +163,7 @@ describe("OpenAssessment.StaffInfoView", function() {
it("updates submission cancellation button when comments changes", function() { it("updates submission cancellation button when comments changes", function() {
// Prevent the server's response from resolving, // Prevent the server's response from resolving,
// so we can see what happens before view gets re-rendered. // so we can see what happens before view gets re-rendered.
spyOn(server, 'cancelSubmission').andCallFake(function() { spyOn(server, 'cancelSubmission').and.callFake(function() {
return $.Deferred(function(defer) {}).promise(); return $.Deferred(function(defer) {}).promise();
}); });
...@@ -190,7 +190,7 @@ describe("OpenAssessment.StaffInfoView", function() { ...@@ -190,7 +190,7 @@ describe("OpenAssessment.StaffInfoView", function() {
}); });
it("submits the cancel submission comments to the server", function() { it("submits the cancel submission comments to the server", function() {
spyOn(server, 'cancelSubmission').andCallThrough(); spyOn(server, 'cancelSubmission').and.callThrough();
// Load the fixture // Load the fixture
loadFixtures('oa_student_info.html'); loadFixtures('oa_student_info.html');
......
...@@ -65,7 +65,7 @@ describe("OpenAssessment.StudentTrainingView", function() { ...@@ -65,7 +65,7 @@ describe("OpenAssessment.StudentTrainingView", function() {
"Criterion 2": "Poor", "Criterion 2": "Poor",
"Criterion 3": "Fair" "Criterion 3": "Fair"
}; };
spyOn(server, 'trainingAssess').andCallThrough(); spyOn(server, 'trainingAssess').and.callThrough();
// Select rubric options // Select rubric options
var optionsSelected = {}; var optionsSelected = {};
...@@ -111,8 +111,8 @@ describe("OpenAssessment.StudentTrainingView", function() { ...@@ -111,8 +111,8 @@ describe("OpenAssessment.StudentTrainingView", function() {
it("reloads the assessment steps when the user submits an assessment", function() { it("reloads the assessment steps when the user submits an assessment", function() {
// Simulate that the user answered the problem correctly, so there are no corrections // Simulate that the user answered the problem correctly, so there are no corrections
server.corrections = {}; server.corrections = {};
spyOn(server, 'trainingAssess').andCallThrough(); spyOn(server, 'trainingAssess').and.callThrough();
spyOn(baseView, 'loadAssessmentModules').andCallThrough(); spyOn(baseView, 'loadAssessmentModules').and.callThrough();
// Select rubric options // Select rubric options
var optionsSelected = {}; var optionsSelected = {};
......
...@@ -18,7 +18,7 @@ describe("OpenAssessment.FileUploader", function() { ...@@ -18,7 +18,7 @@ describe("OpenAssessment.FileUploader", function() {
var successPromise = $.Deferred( var successPromise = $.Deferred(
function(defer) { defer.resolve(); } function(defer) { defer.resolve(); }
).promise(); ).promise();
spyOn($, 'ajax').andReturn(successPromise); spyOn($, 'ajax').and.returnValue(successPromise);
// Stub the event logger // Stub the event logger
spyOn(Logger, 'log'); spyOn(Logger, 'log');
......
...@@ -24,7 +24,7 @@ describe("OpenAssessment.Server", function() { ...@@ -24,7 +24,7 @@ describe("OpenAssessment.Server", function() {
call completes successfully. call completes successfully.
**/ **/
var stubAjax = function(success, responseData) { var stubAjax = function(success, responseData) {
spyOn($, 'ajax').andReturn( spyOn($, 'ajax').and.returnValue(
$.Deferred(function(defer) { $.Deferred(function(defer) {
if (success) { defer.resolveWith(this, [responseData]); } if (success) { defer.resolveWith(this, [responseData]); }
else { defer.reject(); } else { defer.reject(); }
......
...@@ -175,7 +175,7 @@ describe("OpenAssessment.StudioView", function() { ...@@ -175,7 +175,7 @@ describe("OpenAssessment.StudioView", function() {
server.isReleased = true; server.isReleased = true;
// Stub the confirmation step (avoid showing the dialog) // Stub the confirmation step (avoid showing the dialog)
spyOn(view, 'confirmPostReleaseUpdate').andCallFake( spyOn(view, 'confirmPostReleaseUpdate').and.callFake(
function(onConfirm) { onConfirm(); } function(onConfirm) { onConfirm(); }
); );
......
...@@ -210,7 +210,7 @@ describe("OpenAssessment.EditSettingsView", function() { ...@@ -210,7 +210,7 @@ describe("OpenAssessment.EditSettingsView", function() {
// Spy on the assessment view's validate() method so we can // Spy on the assessment view's validate() method so we can
// verify that it doesn't get called (thus marking the DOM) // verify that it doesn't get called (thus marking the DOM)
spyOn(assessmentViews[PEER], 'validate').andCallThrough(); spyOn(assessmentViews[PEER], 'validate').and.callThrough();
// Expect that the parent view is still valid // Expect that the parent view is still valid
expect(view.validate()).toBe(true); expect(view.validate()).toBe(true);
......
...@@ -3,12 +3,18 @@ ...@@ -3,12 +3,18 @@
"version": "0.0.1", "version": "0.0.1",
"repository": "https://github.com/edx/edx-ora2.git", "repository": "https://github.com/edx/edx-ora2.git",
"devDependencies": { "devDependencies": {
"karma": "~0.12", "karma": "^0.12.16",
"karma-chrome-launcher": "0.1.3",
"karma-coverage": "^0.2.6", "karma-coverage": "^0.2.6",
"karma-jasmine": "0.1.5", "karma-jasmine": "^0.3.6",
"karma-jasmine-jquery": "^0.1.1",
"karma-chrome-launcher": "^0.1.4",
"karma-phantomjs-launcher": "^0.1.4", "karma-phantomjs-launcher": "^0.1.4",
"karma-sinon": "^1.0.3",
"karma-jasmine-html-reporter": "~0.1",
"karma-spec-reporter": "^0.0.20", "karma-spec-reporter": "^0.0.20",
"jasmine": "^2.3.0",
"phantomjs": "^1.9.11",
"sinon": "^1.10.3",
"uglify-js": "2.3.6", "uglify-js": "2.3.6",
"jshint": "2.8.0" "jshint": "2.8.0"
}, },
......
#!/usr/bin/env bash #!/usr/bin/env bash
cd `dirname $BASH_SOURCE` && cd .. cd `dirname $BASH_SOURCE` && cd ..
./scripts/install.sh test
echo "Starting JavaScript tests in a browser..." echo "Starting JavaScript tests in a browser..."
./node_modules/karma/bin/karma start --single-run=false --browsers Chrome ./node_modules/karma/bin/karma start --single-run=false --browsers Chrome --reporters=html --autoWatch
#!/usr/bin/env bash
cd `dirname $BASH_SOURCE` && cd ..
echo "Generating HTML fixtures for JavaScript tests..."
export DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE:-"settings.test"}
./scripts/render_templates.py openassessment/xblock/static/js/fixtures/templates.json
...@@ -2,9 +2,5 @@ ...@@ -2,9 +2,5 @@
cd `dirname $BASH_SOURCE` && cd .. cd `dirname $BASH_SOURCE` && cd ..
echo "Generating HTML fixtures for JavaScript tests..."
export DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE:-"settings.test"}
./scripts/render_templates.py openassessment/xblock/static/js/fixtures/templates.json
echo "Running JavaScript tests..." echo "Running JavaScript tests..."
npm test npm test
...@@ -6,5 +6,6 @@ set -e ...@@ -6,5 +6,6 @@ set -e
cd `dirname $BASH_SOURCE` && cd .. cd `dirname $BASH_SOURCE` && cd ..
export DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE:-"settings.test_with_coverage"} export DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE:-"settings.test_with_coverage"}
./scripts/test-python.sh $1 ./scripts/test-python.sh $1
./scripts/render-templates.sh
./scripts/test-js.sh ./scripts/test-js.sh
./scripts/build-docs.sh ./scripts/build-docs.sh
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