Add CasperJS utility functions, and tests for code and

Markdown cell execution.

Code cell test is based on https://gist.github.com/ellisonbg/3329929.
This commit is contained in:
David Wyde 2013-04-02 17:27:02 -05:00 committed by Paul Ivanov
parent 7570c8b00f
commit f5000f416e
3 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,29 @@
//
// Test code cell execution.
//
casper.openNewNotebook();
casper.then(function () {
this.evaluate(function () {
var cell = IPython.notebook.get_selected_cell();
cell.set_text('a=10; print a');
cell.execute();
});
});
casper.wait(2000);
casper.then(function () {
var result = this.evaluate(function () {
var cell = IPython.notebook.get_cell(0);
var output = cell.element.find('.output_area').find('pre').html();
return output;
})
this.test.assertEquals(result, '10\n', 'stdout output matches')
});
casper.deleteCurrentNotebook();
casper.run(function() {
this.test.done();
});

View File

@ -0,0 +1,30 @@
//
// Test that a Markdown cell is rendered to HTML.
//
casper.openNewNotebook();
casper.then(function () {
var output = this.evaluate(function() {
// Does it make more sense to test the UI or the JS API here?
//
// $('#cell_type').val('markdown');
// $('#cell_type').change();
// $('#run_b').click();
//
// $('#to_markdown').click(); // fails via jQuery UI menubar
// $('#run_cell').click(); // fails via jQuery UI menubar
IPython.notebook.to_markdown();
var cell = IPython.notebook.get_selected_cell();
cell.set_text('# Foo');
cell.render();
return cell.get_rendered();
});
casper.test.assertEquals(output, '<h1>Foo</h1>', 'Markdown converted to HTML.');
});
casper.deleteCurrentNotebook();
// Run the browser automation.
casper.run(function() {
this.test.done();
});

View File

@ -0,0 +1,45 @@
//
// Utility functions for the HTML notebook's CasperJS tests.
//
// Get the URL of a notebook server on which to run tests.
casper.getNotebookServer = function () {
return 'http://127.0.0.1:8888';
};
// Create and open a new notebook.
casper.openNewNotebook = function () {
var baseUrl = this.getNotebookServer();
this.start(baseUrl + '/new');
};
// Shut down the current notebook's kernel.
casper._shutdownCurrentKernel = function () {
this.thenEvaluate(function() {
var baseUrl = $('body').data('baseProjectUrl');
var kernelId = IPython.notebook.kernel.kernel_id;
var url = baseUrl + 'kernels/' + kernelId;
$.ajax(url, {
type: 'DELETE',
});
});
};
// Delete created notebook.
casper.deleteCurrentNotebook = function () {
this._shutdownCurrentKernel();
this.thenEvaluate(function() {
var nbData = $('body').data();
var url = nbData.baseProjectUrl + 'notebooks/' + nbData.notebookId;
$.ajax(url, {
type: 'DELETE',
});
});
};
// Pass `console.log` calls from page JS to casper.
casper.printLog = function () {
this.on('remote.message', function(msg) {
this.echo('Remote message caught: ' + msg);
});
};