witten
/
luminotes
Archived
1
0
Fork 0

Wrote stub invoker for testing purposes and made use of it in Test_wiki.html.

This commit is contained in:
Dan Helfman 2007-09-06 21:36:39 +00:00
parent 779769ae79
commit ae347d0e3b
4 changed files with 120 additions and 6 deletions

View File

@ -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 ) {

View File

@ -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();
}

View File

@ -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 );

View File

@ -7,13 +7,59 @@
<title>Luminotes Wiki Tests</title>
<script language="JavaScript" type="text/javascript" src="../../jsunit/app/jsUnitCore.js"></script>
<script language="JavaScript" type="text/javascript" src="../MochiKit.js"></script>
<script language="JavaScript" type="text/javascript" src="../Invoker.js"></script>
<script language="JavaScript" type="text/javascript" src="Stub_invoker.js"></script>
<script language="JavaScript" type="text/javascript" src="../Editor.js"></script>
<script language="JavaScript" type="text/javascript" src="../Wiki.js"></script>
<script language="JavaScript" type="text/javascript">
function setUp() {
wiki = new Wiki();
stub_invoker = new Invoker( function ( url, args ) {
var notebook = {
"name": "fake notebook",
"object_id": "fake_notebook_id",
"revision": "fake_notebook_revision",
"read_write": "true",
"trash": {
"name": "trash",
"object_id": "fake_trash_id",
"revision": "fake_trash_revision",
"read_write": "true",
"trash": null
}
}
if ( url == "/users/current" ) {
return {
"user": {
"username": "case",
"object_id": "fake_user_id",
"revision": "fake_user_revision"
},
"notebook": [ notebook ],
"startup_notes": [],
"http_url": "",
"login_url": ""
}
}
if ( url == "/notebooks/contents" ) {
return {
"notebook": notebook,
"startup_notes": [],
"note": []
};
}
if ( url == "/next_id" ) {
return {
"next_id": "" + Math.random()
}
}
fail( "unknown invoke() url: " + url );
} );
wiki = new Wiki( stub_invoker );
}
function test_Wiki() {
@ -34,7 +80,22 @@ function test_Wiki() {
<input id="search_button" type="button" />
</form>
<div id="status_area"></div>
<div id="user_area"></div>
<div id="notebooks_area"></div>
<div id="notebook_header_area"></div>
<div id="this_notebook_area"></div>
<div id="notes"></div>
<div id="toolbar">
<input id="bold" type="button" />
<input id="italic" type="button" />
<input id="underline" type="button" />
<input id="title" type="button" />
<input id="insertUnorderedList" type="button" />
<input id="insertOrderedList" type="button" />
<input id="createLink" type="button" />
<input id="newNote" type="button" />
</div>
<input type="hidden" name="notebook_id" id="notebook_id" value="fake_notebook_id" />
<input type="hidden" name="note_id" id="note_id" value="" />