Commit 7d4952d9 by Will Daly

Added some JS testing infrastructure

parent c880c21c
......@@ -15,7 +15,6 @@ var
sdist
develop-eggs
.installed.cfg
lib
lib64
__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 */
function OpenAssessmentBlock(runtime, element) {
function OpenAssessmentEditor(runtime, element) {
function displayError(errorMsg) {
runtime.notify('error', {msg: errorMsg});
......
......@@ -39,7 +39,7 @@ class StudioMixin(object):
rendered_template = get_template('openassessmentblock/oa_edit.html').render(Context({}))
frag = Fragment(rendered_template)
frag.add_javascript(pkg_resources.resource_string(__name__, "static/js/src/oa_edit.js"))
frag.initialize_js('OpenAssessmentBlock')
frag.initialize_js('OpenAssessmentEditor')
return frag
@XBlock.json_handler
......
// base path, that will be used to resolve files and exclude
basePath = '.';
// list of files / patterns to load in the browser
files = [
JASMINE,
JASMINE_ADAPTER,
'./**/src/*.js',
'./**/spec/*.js'
];
// list of files to exclude
exclude = [
"karma.conf.js"
];
// use dots reporter, as travis terminal does not support escaping sequences
// possible values: 'dots', 'progress', 'junit', 'teamcity'
// CLI --reporters progress
reporters = ['progress'];
// web server port
// CLI --port 9876
port = 9876;
// cli runner port
// CLI --runner-port 9100
runnerPort = 9100;
// enable / disable colors in the output (reporters and logs)
// CLI --colors --no-colors
colors = true;
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
// CLI --log-level debug
logLevel = LOG_INFO;
// enable / disable watching file and executing tests whenever any file changes
// CLI --auto-watch --no-auto-watch
autoWatch = true;
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
// CLI --browsers Chrome,Firefox,Safari
browsers = ["Firefox"];
// If browser does not capture in given timeout [ms], kill it
// CLI --capture-timeout 5000
captureTimeout = 5000;
// Auto run tests on start (when browsers are captured) and exit
// CLI --single-run --no-single-run
singleRun = true;
// report which specs are slower than 500ms
// CLI --report-slower-than 500
reportSlowerThan = 500;
// Karma configuration
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: 'apps/openassessment/xblock/static/js',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'lib/jquery.min.js',
'lib/*.js',
'src/*.js',
'spec/*.js',
// fixtures
{
pattern: 'fixtures/*.html',
served: true, included: false
},
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// 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"},
"scripts": {"test": "./node_modules/.bin/karma start"}
"devDependencies": {
"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