diff --git a/static/js/Wiki.js b/static/js/Wiki.js index 62a2361..e9353f1 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -1,4 +1,4 @@ -function Wiki() { +function Wiki( invoker ) { this.next_id = null; this.focused_editor = null; this.blank_editor_id = null; @@ -8,7 +8,7 @@ function Wiki() { this.read_write = false; this.startup_notes = new Array(); // map of startup notes: note id to bool this.open_editors = new Array(); // map of open notes: note title to editor - this.invoker = new Invoker(); + this.invoker = invoker; this.search_titles_only = true; connect( this.invoker, "error_message", this, "display_error" ); @@ -1020,7 +1020,7 @@ Wiki.prototype.toggle_editor_options = function ( event, editor ) { event.stop(); } -connect( window, "onload", function ( event ) { new Wiki(); } ); +connect( window, "onload", function ( event ) { new Wiki( new Invoker() ); } ); function Pulldown( wiki, notebook_id, pulldown_id, anchor, relative_to ) { diff --git a/static/js/test/Stub_invoker.js b/static/js/test/Stub_invoker.js new file mode 100644 index 0000000..8e4853e --- /dev/null +++ b/static/js/test/Stub_invoker.js @@ -0,0 +1,49 @@ +function Invoker( handler ) { + this.handler = handler; +} + +Invoker.prototype.invoke = function ( url, http_type, args, callback, form, fire_and_forget ) { + if ( form ) { + var form = formContents( getElement( form ) ); + var arg_names = form[ 0 ]; + var arg_values = form[ 1 ]; + } else { + var arg_names = []; + var arg_values = []; + } + + extend( arg_names, keys( args ) ); + extend( arg_values, values( args ) ); + + // if there's no handler, simulate an error reaching the server + if ( !this.handler ) { + signal( self, "error_message", "There was a problem reaching the server. Please check your network connectivity." ); + return; + } + + var args = new Array(); + for ( var i in arg_names ) { + var name = arg_names[ i ]; + var value = arg_values[ i ]; + + args[ name ] = value; + } + + // ask the stub handler for a fake response to the invocation request + var result = this.handler( url, args ); + + if ( fire_and_forget ) + return; + + if ( result.error ) + signal( this, "error_message", result.error ); + + if ( callback ) + callback( result ); + + if ( result.redirect ) + window.location = result.redirect; + + if ( result.reload ) + window.location.reload(); +} diff --git a/static/js/test/Test_editor.html b/static/js/test/Test_editor.html index f7dd1b5..c048fe1 100644 --- a/static/js/test/Test_editor.html +++ b/static/js/test/Test_editor.html @@ -24,6 +24,10 @@ function setUp() { editor = new Editor( id, notebook_id, note_text, deleted_from, revisions_list, read_write, startup, highlight, editor_focus ); } +function tearDown() { + editor.shutdown(); +} + function test_Editor() { assertNotUndefined( editor ); assertNotNull( editor ); diff --git a/static/js/test/Test_wiki.html b/static/js/test/Test_wiki.html index 0379703..2afd2b9 100644 --- a/static/js/test/Test_wiki.html +++ b/static/js/test/Test_wiki.html @@ -7,13 +7,59 @@ Luminotes Wiki Tests - +