Commit 7d4952d9 by Will Daly

Added some JS testing infrastructure

parent c880c21c
...@@ -15,7 +15,6 @@ var ...@@ -15,7 +15,6 @@ var
sdist sdist
develop-eggs develop-eggs
.installed.cfg .installed.cfg
lib
lib64 lib64
__pycache__ __pycache__
......
<div id="openassessment-edit">
<textarea class="openassessment-editor"></textarea>
<input type="button" class="openassessment-save-button" value="Save"/>
<input type="button" class="openassessment-cancel-button" value="Cancel"/>
</div>
/*
Tests for OA XBlock editing.
*/
describe("OpenAssessment editor", function() {
var runtime = null;
beforeEach(function() {
// Load the DOM fixture
jasmine.getFixtures().fixturesPath = 'base/fixtures'
loadFixtures('oa_edit.html');
// Mock the runtime
runtime = {
notify: function(type, data) {},
// Dummy handler URL returns whatever it's passed in for the handler name
handlerUrl: function(element, handler) {
return handler;
}
};
spyOn(runtime, 'notify');
});
it("loads the XML definition", function() {
// Stub AJAX calls to always return successful
spyOn($, 'ajax').andCallFake(function(params) {
params.success({
'success': true,
'xml': '<openassessment></openassessment>',
'msg': ''
});
});
// Initialize the editor
var editor = OpenAssessmentEditor(runtime, $('#openassessment-edit'));
// Expect that the XML definition was loaded
var editorContents = $('.openassessment-editor').text();
expect(editorContents).toEqual('<openassessment></openassessment>');
});
it("saves the XML definition", function() {
expect(false).toBe(true);
});
it("reverts the XML definition on cancellation", function() {
expect(false).toBe(true);
});
it("displays validation errors but preserves the author's changes", function() {
expect(false).toBe(true);
});
});
/*
Dummy test to verify that Karma is working.
Replace this with a real test when we've written JS with non-trivial logic.
*/
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
});
/* JavaScript for Studio editing view of Open Assessment XBlock */ /* JavaScript for Studio editing view of Open Assessment XBlock */
function OpenAssessmentBlock(runtime, element) { function OpenAssessmentEditor(runtime, element) {
function displayError(errorMsg) { function displayError(errorMsg) {
runtime.notify('error', {msg: errorMsg}); runtime.notify('error', {msg: errorMsg});
......
...@@ -39,7 +39,7 @@ class StudioMixin(object): ...@@ -39,7 +39,7 @@ class StudioMixin(object):
rendered_template = get_template('openassessmentblock/oa_edit.html').render(Context({})) rendered_template = get_template('openassessmentblock/oa_edit.html').render(Context({}))
frag = Fragment(rendered_template) frag = Fragment(rendered_template)
frag.add_javascript(pkg_resources.resource_string(__name__, "static/js/src/oa_edit.js")) frag.add_javascript(pkg_resources.resource_string(__name__, "static/js/src/oa_edit.js"))
frag.initialize_js('OpenAssessmentBlock') frag.initialize_js('OpenAssessmentEditor')
return frag return frag
@XBlock.json_handler @XBlock.json_handler
......
// base path, that will be used to resolve files and exclude // Karma configuration
basePath = '.';
module.exports = function(config) {
// list of files / patterns to load in the browser config.set({
files = [
JASMINE, // base path that will be used to resolve all patterns (eg. files, exclude)
JASMINE_ADAPTER, basePath: 'apps/openassessment/xblock/static/js',
'./**/src/*.js',
'./**/spec/*.js'
]; // frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
// list of files to exclude frameworks: ['jasmine'],
exclude = [
"karma.conf.js"
]; // list of files / patterns to load in the browser
files: [
// use dots reporter, as travis terminal does not support escaping sequences 'lib/jquery.min.js',
// possible values: 'dots', 'progress', 'junit', 'teamcity' 'lib/*.js',
// CLI --reporters progress 'src/*.js',
reporters = ['progress']; 'spec/*.js',
// web server port // fixtures
// CLI --port 9876 {
port = 9876; pattern: 'fixtures/*.html',
served: true, included: false
// cli runner port },
// CLI --runner-port 9100 ],
runnerPort = 9100;
// enable / disable colors in the output (reporters and logs) // list of files to exclude
// CLI --colors --no-colors exclude: [
colors = true;
],
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
// CLI --log-level debug // preprocess matching files before serving them to the browser
logLevel = LOG_INFO; // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
// enable / disable watching file and executing tests whenever any file changes
// CLI --auto-watch --no-auto-watch },
autoWatch = true;
// Start these browsers, currently available: // test results reporter to use
// - Chrome // possible values: 'dots', 'progress'
// - ChromeCanary // available reporters: https://npmjs.org/browse/keyword/karma-reporter
// - Firefox reporters: ['progress'],
// - Opera
// - Safari (only Mac)
// - PhantomJS // web server port
// - IE (only Windows) port: 9876,
// CLI --browsers Chrome,Firefox,Safari
browsers = ["Firefox"];
// enable / disable colors in the output (reporters and logs)
// If browser does not capture in given timeout [ms], kill it colors: true,
// CLI --capture-timeout 5000
captureTimeout = 5000;
// level of logging
// Auto run tests on start (when browsers are captured) and exit // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
// CLI --single-run --no-single-run logLevel: config.LOG_INFO,
singleRun = true;
// report which specs are slower than 500ms // enable / disable watching file and executing tests whenever any file changes
// CLI --report-slower-than 500 autoWatch: false,
reportSlowerThan = 500;
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
});
};
{ {
"devDependencies": {"karma": "~0.8"}, "devDependencies": {
"scripts": {"test": "./node_modules/.bin/karma start"} "karma": "~0.11",
"karma-jasmine": "0.1.3",
"karma-firefox-launcher": "~0.1.3"
},
"scripts": {
"test": "./node_modules/karma/bin/karma start"
}
} }
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