From: Joseph Lewis Date: Mon, 20 Aug 2012 01:08:58 +0000 (-0600) Subject: Fixed sync loading with dojo 1.8. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5fb7e0a9042b8e46906f8030a48a1ce1ae01dfb0;p=evergreen%2Fjoelewis.git Fixed sync loading with dojo 1.8. Signed-off-by: Joseph Lewis --- diff --git a/Open-ILS/web/js/dojo/openils/BibTemplate.js b/Open-ILS/web/js/dojo/openils/BibTemplate.js index 8c81447c0a..156f74f9db 100644 --- a/Open-ILS/web/js/dojo/openils/BibTemplate.js +++ b/Open-ILS/web/js/dojo/openils/BibTemplate.js @@ -236,6 +236,9 @@ if(!dojo._hasResource["openils.BibTemplate"]) { } }); + + // 2012-07-26 - Joseph Lewis, Is this needed anymore? It isn't referenced + // anywhere that I see. dojo._hasResource["openils.FeedTemplate"] = true; dojo.provide("openils.FeedTemplate"); dojo.declare('openils.FeedTemplate', null, { diff --git a/Open-ILS/web/js/dojo/openils/CGI.js b/Open-ILS/web/js/dojo/openils/CGI.js index d63576e0f2..ca383d1ed1 100644 --- a/Open-ILS/web/js/dojo/openils/CGI.js +++ b/Open-ILS/web/js/dojo/openils/CGI.js @@ -14,6 +14,8 @@ * --------------------------------------------------------------------------- */ +// 2012-07-26 Joseph Lewis -- Can or should this be replaced with dojo's builtin +// functions? dojo.queryToObject? if(!dojo._hasResource["openils.CGI"]) { dojo._hasResource["openils.CGI"] = true; diff --git a/Open-ILS/web/js/dojo/openils/DojoPatch.js b/Open-ILS/web/js/dojo/openils/DojoPatch.js index 54b44131ad..2e3eebe5e7 100644 --- a/Open-ILS/web/js/dojo/openils/DojoPatch.js +++ b/Open-ILS/web/js/dojo/openils/DojoPatch.js @@ -25,4 +25,4 @@ if(!dojo._hasResource["openils.DojoPatch"]) { - \ No newline at end of file + diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/AuthorityControlSet.js b/Open-ILS/web/js/dojo/openils/tests/functions/AuthorityControlSet.js new file mode 100644 index 0000000000..0ef9e0db46 --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/AuthorityControlSet.js @@ -0,0 +1,39 @@ +dojo.provide("openils.tests.functions.AuthorityControlSet"); + +//Import in the code being tested. +dojo.require("openils.AuthorityControlSet"); + +doh.register("openils.tests.functions.AuthorityControlSet", [ + + function test_constructor(doh) { + // summary: + // Simply tests that the Constructor works, and the file has loaded + + var acs = new openils.AuthorityControlSet(); + doh.assertTrue(acs != null); + }, + + function test_alwaysFalse(doh) { + // summary: + // A simple test of the alwaysFalse function + // description: + // A simple test of the alwaysFalse function + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_isTrue(doh) { + // summary: + // A simple test of the isTrue function + // description: + // A simple test of the isTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/AutoSuggestStore.js b/Open-ILS/web/js/dojo/openils/tests/functions/AutoSuggestStore.js new file mode 100644 index 0000000000..4bfd1a962b --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/AutoSuggestStore.js @@ -0,0 +1,39 @@ +dojo.provide("openils.tests.functions.AutoSuggestStore"); + +//Import in the code being tested. +dojo.require("openils.AutoSuggestStore"); + +doh.register("openils.tests.functions.AutoSuggestStore", [ + + function test_constructor(doh) { + // summary: + // Simply tests that the Constructor works, and the file has loaded + + var acs = new openils.AutoSuggestStore(); + doh.assertTrue(acs != null); + }, + + function test_alwaysFalse(doh) { + // summary: + // A simple test of the alwaysFalse function + // description: + // A simple test of the alwaysFalse function + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_isTrue(doh) { + // summary: + // A simple test of the isTrue function + // description: + // A simple test of the isTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/BibTemplate.js b/Open-ILS/web/js/dojo/openils/tests/functions/BibTemplate.js new file mode 100644 index 0000000000..0b4d17ed36 --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/BibTemplate.js @@ -0,0 +1,47 @@ +dojo.provide("openils.tests.functions.BibTemplate"); + +//Import in the code being tested. +dojo.require("openils.BibTemplate"); + +doh.register("openils.tests.functions.BibTemplate", [ + + function test_constructor(doh) { + // summary: + // Simply tests that the Constructor works, and the file has loaded + + var acs = new openils.BibTemplate(); + doh.assertTrue(acs != null); + }, + + function test_default_constructor(doh) { + var acs = new openils.BibTemplate(); + doh.assertTrue(acs != null); + doh.assertTrue(acs.org_unit == '-'); + doh.assertTrue(acs.sync == false); + doh.assertTrue(acs.nodelay == false); + }, + + function test_alwaysFalse(doh) { + // summary: + // A simple test of the alwaysFalse function + // description: + // A simple test of the alwaysFalse function + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_isTrue(doh) { + // summary: + // A simple test of the isTrue function + // description: + // A simple test of the isTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/BibTemplate.js~ b/Open-ILS/web/js/dojo/openils/tests/functions/BibTemplate.js~ new file mode 100644 index 0000000000..300464f964 --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/BibTemplate.js~ @@ -0,0 +1,46 @@ +dojo.provide("openils.tests.functions.BibTemplate"); + +//Import in the code being tested. +dojo.require("openils.BibTemplate"); + +doh.register("openils.tests.functions.BibTemplate", [ + + function test_constructor(doh) { + // summary: + // Simply tests that the Constructor works, and the file has loaded + + var acs = new openils.BibTemplate(); + doh.assertTrue(acs != null); + }, + + function test_default_constructor(doh) { + var acs = new openils.BibTemplate(); + doh.assertTrue(acs != null); + doh.assertTrue(acs.org_unit == '-'); + doh.assertTrue( + }, + + function test_alwaysFalse(doh) { + // summary: + // A simple test of the alwaysFalse function + // description: + // A simple test of the alwaysFalse function + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_isTrue(doh) { + // summary: + // A simple test of the isTrue function + // description: + // A simple test of the isTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/CGI.js b/Open-ILS/web/js/dojo/openils/tests/functions/CGI.js new file mode 100644 index 0000000000..a626d153a0 --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/CGI.js @@ -0,0 +1,89 @@ +dojo.provide("openils.tests.functions.CGI"); + +//Import in the code being tested. +dojo.require("openils.CGI"); + +doh.register("openils.tests.functions.CGI", [ + + function test_constructor(doh) { + // summary: + // Simply tests that the Constructor works, and the file has loaded + // description: + // + + var acs = new openils.CGI(); + doh.assertTrue(acs != null); + }, + + function test_keys(doh) { + // summary: + // Tests the key fetching mechanism of CGI + // description: + // CGI.js will return the key part of the query string: ?key=value& + + var acs = new openils.CGI(); + + // Being we're using dojo's test framework this should be true. + var dojoKeys = dojo.queryToObject(location.search.replace(/^\?/,"")); + + + doh.assertTrue(acs.keys().length == Object.keys(dojoKeys).length); + }, + + function test_params(doh) { + // summary: + // Tests all of the params in the CGI script + // description: + // CGI.js will return the values part of the query string + + var acs = new openils.CGI(); + var keys = acs.keys(); + + var dojoVersion = dojo.queryToObject(location.search.replace(/^\?/,"")); + + for(var i = 0; i < keys.length; i++) + { + doh.assertTrue(acs.param(keys[i]) == dojoVersion[keys[i]]); + } + }, + + function test_toString(doh) { + // summary: + // Tests to make sure the toString actually reports something, + // anything. + // description: + // The tostring method is supposed to only be for debugging, but + // shoudld still pass. + + var acs = new openils.CGI(); + + if(acs.keys().length == 0) + doh.assertTrue(acs.toString() == ""); + else + doh.assertTrue(acs.toString() != ""); + }, + + function test_alwaysFalse(doh) { + // summary: + // A simple test of the doh assertFalse function + // description: + // A simple test of the doh assertFalse function + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_isTrue(doh) { + // summary: + // A simple test of the assertTrue function + // description: + // A simple test of the assertTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/CopyLocation.js b/Open-ILS/web/js/dojo/openils/tests/functions/CopyLocation.js new file mode 100644 index 0000000000..eaca6de660 --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/CopyLocation.js @@ -0,0 +1,42 @@ +dojo.provide("openils.tests.functions.CopyLocation"); + +//Import in the code being tested. +dojo.require("openils.CopyLocation"); + + +doh.register("openils.tests.functions.CopyLocation", [ + + function test_loaded(doh) { + // summary: + // Simplest test, fail on not loading. + // description: + // only checks that the functions are there, not that they work. + + doh.assertTrue(openils.CopyLocation.createStore != null); + doh.assertTrue(openils.CopyLocation.retrieve != null); + }, + + function test_assertFalse(doh) { + // summary: + // A simple test of the doh assertFalse function. + // description: + // A simple test of the doh assertFalse function. + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_assertTrue(doh) { + // summary: + // A simple test of the assertTrue function. + // description: + // A simple test of the assertTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/DojoPatch.js b/Open-ILS/web/js/dojo/openils/tests/functions/DojoPatch.js new file mode 100644 index 0000000000..e852eecdcd --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/DojoPatch.js @@ -0,0 +1,31 @@ +dojo.provide("openils.tests.functions.DojoPatch"); + +//Import in the code being tested. +dojo.require("openils.DojoPatch"); + +doh.register("openils.tests.functions.DojoPatch", [ + + function test_alwaysFalse(doh) { + // summary: + // A simple test of the alwaysFalse function + // description: + // A simple test of the alwaysFalse function + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_isTrue(doh) { + // summary: + // A simple test of the isTrue function + // description: + // A simple test of the isTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/DojoPatch.js~ b/Open-ILS/web/js/dojo/openils/tests/functions/DojoPatch.js~ new file mode 100644 index 0000000000..5bae5f683b --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/DojoPatch.js~ @@ -0,0 +1,47 @@ +dojo.provide("openils.tests.functions.DojoPatch"); + +//Import in the code being tested. +dojo.require("openils.DojoPatch"); + +doh.register("openils.tests.functions.DojoPatch", [ + + function test_constructor(doh) { + // summary: + // Simply tests that the Constructor works, and the file has loaded + + var acs = new openils.BibTemplate(); + doh.assertTrue(acs != null); + }, + + function test_default_constructor(doh) { + var acs = new openils.BibTemplate(); + doh.assertTrue(acs != null); + doh.assertTrue(acs.org_unit == '-'); + doh.assertTrue(acs.sync == false); + doh.assertTrue(acs.nodelay == false); + }, + + function test_alwaysFalse(doh) { + // summary: + // A simple test of the alwaysFalse function + // description: + // A simple test of the alwaysFalse function + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_isTrue(doh) { + // summary: + // A simple test of the isTrue function + // description: + // A simple test of the isTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/Event.js b/Open-ILS/web/js/dojo/openils/tests/functions/Event.js new file mode 100644 index 0000000000..3eeac45c8b --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/Event.js @@ -0,0 +1,75 @@ +dojo.provide("openils.tests.functions.Event"); + +// Import in the code being tested. +dojo.require("openils.Event"); + + +doh.register("openils.tests.functions.Event", [ + + function test_loaded(doh) { + // summary: + // Simplest test, fail on not loading. + // description: + // only checks that the functions are there, not that they work. + + doh.assertTrue(openils.Event != null); + }, + + function test_parse(doh) { + // summary: + // Tests the parse function of the event + // description: + // "parse" - Parses a proposed event object. If this object is an + // event, a new openils.Event is returned. Otherwise, + // null is returned + + // Test a blank object + var obj = {}; + doh.assertTrue(openils.Event.parse(obj) == null); + + // Test nothing + doh.assertTrue(openils.Event.parse() == null); + + // Test something that looks like an event + var evt = { + ilsevent:"Who is John Galt?", + textcode:"I would tell him to shrug." + }; + + doh.assertTrue(openils.Event.parse(evt) != null); + }, + + function test_parse_and_raise(doh) { + // summary: + // Tests the parse and raise function of Event + // description: + // If the provided object is a non-success event, the + // event is thrown as an exception. + + + }, + + function test_assertFalse(doh) { + // summary: + // A simple test of the doh assertFalse function. + // description: + // A simple test of the doh assertFalse function. + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_assertTrue(doh) { + // summary: + // A simple test of the assertTrue function. + // description: + // A simple test of the assertTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/Event.js~ b/Open-ILS/web/js/dojo/openils/tests/functions/Event.js~ new file mode 100644 index 0000000000..f57cb19179 --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/Event.js~ @@ -0,0 +1,75 @@ +dojo.provide("openils.tests.functions.Event"); + +//Import in the code being tested. +dojo.require("openils.Event"); + + +doh.register("openils.tests.functions.Event", [ + + function test_loaded(doh) { + // summary: + // Simplest test, fail on not loading. + // description: + // only checks that the functions are there, not that they work. + + doh.assertTrue(openils.Event != null); + }, + + function test_parse(doh) { + // summary: + // Tests the parse function of the event + // description: + // "parse" - Parses a proposed event object. If this object is an + // event, a new openils.Event is returned. Otherwise, + // null is returned + + // Test a blank object + var obj = {}; + doh.assertTrue(openils.Event.parse(obj) == null); + + // Test nothing + doh.assertTrue(openils.Event.parse() == null); + + // Test something that looks like an event + var evt = { + ilsevent:"Who is John Galt?", + textcode:"I would tell him to shrug." + }; + + doh.assertTrue(openils.Event.parse(evt) != null); + }, + + function test_parse_and_raise(doh) { + // summary: + // Tests the parse and raise function of Event + // description: + // If the provided object is a non-success event, the + // event is thrown as an exception. + + + }, + + function test_assertFalse(doh) { + // summary: + // A simple test of the doh assertFalse function. + // description: + // A simple test of the doh assertFalse function. + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_assertTrue(doh) { + // summary: + // A simple test of the assertTrue function. + // description: + // A simple test of the assertTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/FlattenerStore.js b/Open-ILS/web/js/dojo/openils/tests/functions/FlattenerStore.js new file mode 100644 index 0000000000..2f855fb7c5 --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/FlattenerStore.js @@ -0,0 +1,346 @@ +dojo.provide("openils.tests.functions.FlattenerStore"); + +// Import in the code being tested. +dojo.require("openils.FlattenerStore"); + + +doh.register("openils.tests.functions.FlattenerStore", [ + + function test_loaded(doh) { + // summary: + // Simplest test, fail on not loading. + // description: + // only checks that the functions are there, not that they work. + + doh.assertTrue(openils.FlattenerStore != null); + }, + + function test_FlattenerStoreError(doh){ + // summary: + // Simplest test, fail on not loading. + // description: + // only checks that the functions are there, not that they work. + doh.assertTrue(openils.FlattenerStoreError != null); + }, + + function test_FlattenerStoreError_toString(doh){ + // summary: + // Tests toString of FlattenerStoreError + // description: + // "openils.FlattenerStore: " + this.message + + var msg = "Walden Pond"; + var fse = new FlattenerStoreError(msg); + + doh.assertTrue(fse.toString().indexOf(msg) != -1); + }, + + function test_vars(doh) { + // summary: + // Simplest test, checks all vars have been overwritten on init. + // description: + // + + var testobj = "JUST A TEST"; + + var init = { + "fmClass": testobj, + "mapClause": testobj, + "sloClause": testobj, + "limit": -100, + "offset": -10, + "baseSort": testobj, + "defaultSort": testobj + }; + + var fs = new openils.FlattenerStore(init); + + for(var x in Object.keys(fs)) + doh.assertTrue(fs[x] === init[x]); + }, + + function test_getValue(doh) + { + // summary: + // Performs a getValue against a null + // description: + // + + try { + + } catch(err) { + + } + }, + + + + /* *** Begin dojo.data.api.Read methods *** */ + + "getValue": function( + /* object */ item, + /* string */ attribute, + /* anything */ defaultValue) { + //console.log("getValue(" + lazy(item) + ", " + attribute + ", " + defaultValue + ")") + if (!this.isItem(item)) + throw new FlattenerStoreError("getValue(): bad item " + item); + else if (typeof attribute != "string") + throw new FlattenerStoreError("getValue(): bad attribute"); + + var value = item[attribute]; + return (typeof value == "undefined") ? defaultValue : value; + }, + + "getValues": function(/* object */ item, /* string */ attribute) { + //console.log("getValues(" + item + ", " + attribute + ")"); + if (!this.isItem(item) || typeof attribute != "string") + throw new FlattenerStoreError("bad arguments"); + + var result = this.getValue(item, attribute, []); + return dojo.isArray(result) ? result : [result]; + }, + + "getAttributes": function(/* object */ item) { + //console.log("getAttributes(" + item + ")"); + if (!this.isItem(item)) + throw new FlattenerStoreError("getAttributes(): bad args"); + else + return this._display_attributes(); + }, + + "hasAttribute": function(/* object */ item, /* string */ attribute) { + //console.log("hasAttribute(" + item + ", " + attribute + ")"); + if (!this.isItem(item) || typeof attribute != "string") { + throw new FlattenerStoreError("hasAttribute(): bad args"); + } else { + return dojo.indexOf(this._display_attributes(), attribute) > -1; + } + }, + + "containsValue": function( + /* object */ item, + /* string */ attribute, + /* anything */ value) { + //console.log("containsValue(" + item + ", " + attribute + ", " + value + ")"); + if (!this.isItem(item) || typeof attribute != "string") + throw new FlattenerStoreError("bad data"); + else + return ( + dojo.indexOf(this.getValues(item, attribute), value) >= -1 + ); + }, + + + function test_isItem(doh) + { + // summary: + // Tests to see if the thing is an item or not. + // description: + // + + var testobj = "JUST A TEST"; + + var init = { + "fmClass": testobj, + "mapClause": ["field"], + "sloClause": testobj, + "limit": -100, + "offset": -10, + "baseSort": testobj, + "defaultSort": testobj + }; + + var fs = new openils.FlattenerStore(init); + + doh.assertFalse(fs.isItem()); + doh.assertFalse(fs.isItem(1)); + doh.assertFalse(fs.isItem({})); + doh.assertTrue(fs.isItem({"field":"value"})); + }, + + + + function test_isItemLoaded(doh) + { + // summary: + // Tests to see if the thing is an item or not. + // description: + // + + var testobj = "JUST A TEST"; + + var init = { + "fmClass": testobj, + "mapClause": ["field"], + "sloClause": testobj, + "limit": -100, + "offset": -10, + "baseSort": testobj, + "defaultSort": testobj + }; + + var fs = new openils.FlattenerStore(init); + var obj = {"field":"value"}; + //fs.fmIdentifier = "field"; + console.log("Identifier is: " + fs.fmIdentifier); + + doh.assertFalse(fs.isItemLoaded(null)); + doh.assertFalse(fs.isItemLoaded(obj)); + + fs._current_items = [obj]; + doh.assertTrue(fs.isItemLoaded(obj)); + }, + + + + "loadItem": function(/* object */ keywordArgs) { + if (!keywordArgs.force && this.isItemLoaded(keywordArgs.item)) + return; + + keywordArgs.identity = this.getIdentity(keywordArgs.item); + return this.fetchItemByIdentity(keywordArgs); + }, + + /* *** Begin dojo.data.api.Identity methods *** */ + + "getIdentity": function(/* object */ item) { + if (!this.isItem(item)) + throw new FlattenerStoreError("not an item"); + + return item[this.fmIdentifier]; + }, + + "getIdentityAttributes": function(/* object */ item) { + // console.log("getIdentityAttributes(" + item + ")"); + return [this.fmIdentifier]; + }, + + + + /* dojo.data.api.Write - only very partially implemented, because + * for FlattenerGrid, the intended client of this store, we don't + * need most of the methods. */ + + "deleteItem": function(item) { + //console.log("deleteItem()"); + + var identity = this.getIdentity(item); + delete this._current_items[identity]; /* safe even if missing */ + + this.onDelete(item); + }, + + "setValue": function(item, attribute, value) { + /* Silently do nothing when setValue()'s caller wants to change + * the identifier. They must be confused anyway. */ + if (attribute == this.fmIdentifier) + return; + + var old_value = dojo.clone(item[attribute]); + + item[attribute] = dojo.clone(value); + this.onSet(item, attribute, old_value, value); + }, + + "setValues": function(item, attribute, values) { + console.warn("[unimplemented] setValues()"); /* unneeded */ + }, + + "newItem": function(keywordArgs, parentInfo) { + console.warn("[unimplemented] newItem()"); /* unneeded */ + }, + + "unsetAttribute": function() { + console.warn("[unimplemented] unsetAttribute()"); /* unneeded */ + }, + + "save": function() { + console.warn("[unimplemented] save()"); /* unneeded */ + }, + + "revert": function() { + console.warn("[unimplemented] revert()"); /* unneeded */ + }, + + "isDirty": function() { /* I /think/ this will be ok for our purposes */ + console.info("[stub] isDirty() will always return false"); + + return false; + }, + + /* dojo.data.api.Notification - Keep these no-op methods because + * clients will dojo.connect() to them. */ + + "onNew" : function(item) { /* no-op */ }, + "onDelete" : function(item) { /* no-op */ }, + "onSet": function(item, attr, oldval, newval) { /* no-op */ }, + + /* *** Classes implementing any Dojo APIs do this to list which + * APIs they're implementing. *** */ + + "getFeatures": function() { + return { + "dojo.data.api.Read": true, + "dojo.data.api.Identity": true, + "dojo.data.api.Notification": true, + "dojo.data.api.Write": true /* well, only partly */ + }; + } + }); +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + function test_assertFalse(doh) { + // summary: + // A simple test of the doh assertFalse function. + // description: + // A simple test of the doh assertFalse function. + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_assertTrue(doh) { + // summary: + // A simple test of the assertTrue function. + // description: + // A simple test of the assertTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/FlattenerStore.js~ b/Open-ILS/web/js/dojo/openils/tests/functions/FlattenerStore.js~ new file mode 100644 index 0000000000..2b3fe39894 --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/FlattenerStore.js~ @@ -0,0 +1,412 @@ +dojo.provide("openils.tests.functions.FlattenerStore"); + +// Import in the code being tested. +dojo.require("openils.FlattenerStore"); + + +doh.register("openils.tests.functions.FlattenerStore", [ + + function test_loaded(doh) { + // summary: + // Simplest test, fail on not loading. + // description: + // only checks that the functions are there, not that they work. + + doh.assertTrue(openils.FlattenerStore != null); + }, + + function test_FlattenerStoreError(doh){ + // summary: + // Simplest test, fail on not loading. + // description: + // only checks that the functions are there, not that they work. + doh.assertTrue(openils.FlattenerStoreError != null); + }, + + function test_FlattenerStoreError_toString(doh){ + // summary: + // Tests toString of FlattenerStoreError + // description: + // "openils.FlattenerStore: " + this.message + + var msg = "Walden Pond"; + var fse = new FlattenerStoreError(msg); + + doh.assertTrue(fse.toString().indexOf(msg) != -1); + }, + + function test_vars(doh) { + // summary: + // Simplest test, checks all vars have been overwritten on init. + // description: + // + + var testobj = "JUST A TEST"; + + var init = { + "fmClass": testobj, + "mapClause": testobj, + "sloClause": testobj, + "limit": -100, + "offset": -10, + "baseSort": testobj, + "defaultSort": testobj + }; + + var fs = new openils.FlattenerStore(init); + + for(var x in Object.keys(fs)) + doh.assertTrue(fs[x] === init[x]); + }, + + function test_getValue(doh) + { + // summary: + // Performs a getValue against a null + // description: + // + + try { + + } catch(err) { + + } + }, + + + + /* *** Begin dojo.data.api.Read methods *** */ + + "getValue": function( + /* object */ item, + /* string */ attribute, + /* anything */ defaultValue) { + //console.log("getValue(" + lazy(item) + ", " + attribute + ", " + defaultValue + ")") + if (!this.isItem(item)) + throw new FlattenerStoreError("getValue(): bad item " + item); + else if (typeof attribute != "string") + throw new FlattenerStoreError("getValue(): bad attribute"); + + var value = item[attribute]; + return (typeof value == "undefined") ? defaultValue : value; + }, + + "getValues": function(/* object */ item, /* string */ attribute) { + //console.log("getValues(" + item + ", " + attribute + ")"); + if (!this.isItem(item) || typeof attribute != "string") + throw new FlattenerStoreError("bad arguments"); + + var result = this.getValue(item, attribute, []); + return dojo.isArray(result) ? result : [result]; + }, + + "getAttributes": function(/* object */ item) { + //console.log("getAttributes(" + item + ")"); + if (!this.isItem(item)) + throw new FlattenerStoreError("getAttributes(): bad args"); + else + return this._display_attributes(); + }, + + "hasAttribute": function(/* object */ item, /* string */ attribute) { + //console.log("hasAttribute(" + item + ", " + attribute + ")"); + if (!this.isItem(item) || typeof attribute != "string") { + throw new FlattenerStoreError("hasAttribute(): bad args"); + } else { + return dojo.indexOf(this._display_attributes(), attribute) > -1; + } + }, + + "containsValue": function( + /* object */ item, + /* string */ attribute, + /* anything */ value) { + //console.log("containsValue(" + item + ", " + attribute + ", " + value + ")"); + if (!this.isItem(item) || typeof attribute != "string") + throw new FlattenerStoreError("bad data"); + else + return ( + dojo.indexOf(this.getValues(item, attribute), value) >= -1 + ); + }, + + + function test_isItem(doh) + { + // summary: + // Tests to see if the thing is an item or not. + // description: + // + + var testobj = "JUST A TEST"; + + var init = { + "fmClass": testobj, + "mapClause": ["field"], + "sloClause": testobj, + "limit": -100, + "offset": -10, + "baseSort": testobj, + "defaultSort": testobj + }; + + var fs = new openils.FlattenerStore(init); + + doh.assertFalse(fs.isItem()); + doh.assertFalse(fs.isItem(1)); + doh.assertFalse(fs.isItem({})); + doh.assertTrue(fs.isItem({"field":"value"})); + }, + + + + function test_isItemLoaded(doh) + { + // summary: + // Tests to see if the thing is an item or not. + // description: + // + + var testobj = "JUST A TEST"; + + var init = { + "fmClass": testobj, + "mapClause": ["field"], + "sloClause": testobj, + "limit": -100, + "offset": -10, + "baseSort": testobj, + "defaultSort": testobj + }; + + var fs = new openils.FlattenerStore(init); + var obj = {"field":"value"}; + //fs.fmIdentifier = "field"; + console.log(fs.fmIdentifier); + + doh.assertFalse(fs.isItemLoaded(null)); + doh.assertFalse(fs.isItemLoaded(obj)); + + fs._current_items = [obj]; + doh.assertTrue(fs.isItemLoaded(obj)); + }, + + + + "loadItem": function(/* object */ keywordArgs) { + if (!keywordArgs.force && this.isItemLoaded(keywordArgs.item)) + return; + + keywordArgs.identity = this.getIdentity(keywordArgs.item); + return this.fetchItemByIdentity(keywordArgs); + }, + + /* *** Begin dojo.data.api.Identity methods *** */ + + "getIdentity": function(/* object */ item) { + if (!this.isItem(item)) + throw new FlattenerStoreError("not an item"); + + return item[this.fmIdentifier]; + }, + + "getIdentityAttributes": function(/* object */ item) { + // console.log("getIdentityAttributes(" + item + ")"); + return [this.fmIdentifier]; + }, + + "fetchItemByIdentity": function(/* object */ keywordArgs) { + var callback_scope = keywordArgs.scope || dojo.global; + var identity = keywordArgs.identity; + + if (typeof identity == "undefined") + throw new FlattenerStoreError( + "fetchItemByIdentity() needs identity in keywordArgs" + ); + + /* First of force's two implications: + * fetch even if already loaded. */ + if (this._current_items[identity] && !keywordArgs.force) { + keywordArgs.onItem.call( + callback_scope, this._current_items[identity] + ); + + return; + } + + var post_params = this._prepare_flattener_params(keywordArgs); + + var process_fetch_one = dojo.hitch( + this, function(obj, when) { + if (when < this._last_fetch) /* Stale response. Discard. */ + return; + + if (dojo.isArray(obj)) { + if (obj.length <= 1) { + obj = obj.pop() || null; /* safe enough */ + /* Second of force's two implications: call setValue + * ourselves. Makes a DataGrid update. */ + if (keywordArgs.force && obj && + (origitem = this._current_items[identity])) { + for (var prop in origitem) + this.setValue(origitem, prop, obj[prop]); + } + if (keywordArgs.onItem) + keywordArgs.onItem.call(callback_scope, obj); + } else { + var e = new FlattenerStoreError("Too many results"); + if (keywordArgs.onError) + keywordArgs.onError.call(callback_scope, e); + else + throw e; + } + } else { + var e = new FlattenerStoreError("Bad response"); + if (keywordArgs.onError) + keywordArgs.onError.call(callback_scope, e); + else + throw e; + } + } + ); + + var fetch_time = this._last_fetch = (new Date().getTime()); + + dojo.xhrPost({ + "url": this._flattener_url, + "content": post_params, + "handleAs": "json", + "sync": false, + "preventCache": true, + "headers": {"Accept": "application/json"}, + "load": function(obj){ process_fetch_one(obj, fetch_time); } + }); + }, + + /* dojo.data.api.Write - only very partially implemented, because + * for FlattenerGrid, the intended client of this store, we don't + * need most of the methods. */ + + "deleteItem": function(item) { + //console.log("deleteItem()"); + + var identity = this.getIdentity(item); + delete this._current_items[identity]; /* safe even if missing */ + + this.onDelete(item); + }, + + "setValue": function(item, attribute, value) { + /* Silently do nothing when setValue()'s caller wants to change + * the identifier. They must be confused anyway. */ + if (attribute == this.fmIdentifier) + return; + + var old_value = dojo.clone(item[attribute]); + + item[attribute] = dojo.clone(value); + this.onSet(item, attribute, old_value, value); + }, + + "setValues": function(item, attribute, values) { + console.warn("[unimplemented] setValues()"); /* unneeded */ + }, + + "newItem": function(keywordArgs, parentInfo) { + console.warn("[unimplemented] newItem()"); /* unneeded */ + }, + + "unsetAttribute": function() { + console.warn("[unimplemented] unsetAttribute()"); /* unneeded */ + }, + + "save": function() { + console.warn("[unimplemented] save()"); /* unneeded */ + }, + + "revert": function() { + console.warn("[unimplemented] revert()"); /* unneeded */ + }, + + "isDirty": function() { /* I /think/ this will be ok for our purposes */ + console.info("[stub] isDirty() will always return false"); + + return false; + }, + + /* dojo.data.api.Notification - Keep these no-op methods because + * clients will dojo.connect() to them. */ + + "onNew" : function(item) { /* no-op */ }, + "onDelete" : function(item) { /* no-op */ }, + "onSet": function(item, attr, oldval, newval) { /* no-op */ }, + + /* *** Classes implementing any Dojo APIs do this to list which + * APIs they're implementing. *** */ + + "getFeatures": function() { + return { + "dojo.data.api.Read": true, + "dojo.data.api.Identity": true, + "dojo.data.api.Notification": true, + "dojo.data.api.Write": true /* well, only partly */ + }; + } + }); +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + function test_assertFalse(doh) { + // summary: + // A simple test of the doh assertFalse function. + // description: + // A simple test of the doh assertFalse function. + doh.assertFalse(false); + doh.assertFalse(!true); + doh.assertFalse(null); + doh.assertFalse(0); + }, + + function test_assertTrue(doh) { + // summary: + // A simple test of the assertTrue function. + // description: + // A simple test of the assertTrue function with multiple permutations of + // calling it. + doh.assertTrue(true); + doh.assertTrue(!false); + doh.assertTrue({}); + doh.assertTrue(!null); + doh.assertTrue(!0); + } +]); diff --git a/Open-ILS/web/js/dojo/openils/tests/functions/Util.js b/Open-ILS/web/js/dojo/openils/tests/functions/Util.js new file mode 100644 index 0000000000..f7eda6b2fa --- /dev/null +++ b/Open-ILS/web/js/dojo/openils/tests/functions/Util.js @@ -0,0 +1,482 @@ +dojo.provide("openils.tests.functions.Util"); + +//Import in the code being tested. +dojo.require("openils.Util"); + +doh.register("openils.tests.functions.Util", [ + +function test_timestampAsDateObj(doh) { + // summary: + // Tests the ability to convert timestamps to date objects. + // description: + // This functions + var res = openils.Util.timeStampAsDateObj("2012-06-04T12:01:02-0700"); + var res2 = openils.Util.timeStampAsDateObj("2012-06-04T12:01:02-0800"); + + doh.assertTrue(res.getFullYear() == 2012); + doh.assertTrue(res.getMonth() == 5); + doh.assertTrue(res.getDate() == 4); + //Will fail depending on where you are, as JS translates to local + //time. + //doh.assertTrue(res.getHours() == 13); + doh.assertTrue(res.getMinutes() == 1); + doh.assertTrue(res.getSeconds() == 2); + doh.assertTrue(res.getHours() - res2.getHours() == -1); +}, + +function test_userFullName(doh) { + /** The full name fields + + openils.Util._userFullNameFields = [ + "prefix", "first_given_name", "second_given_name", + "family_name", "suffix", "alias", "usrname" + ];**/ + + var test_user = { + prefix: function(){return "Mr.";}, + first_given_name: function(){return "DENT";}, + second_given_name: function(){return "Arthur";}, + family_name: function(){return "dent";}, + suffix: function(){return "jr";}, + alias: function(){return "The Sandwich Maker";}, + usrname: function(){return "dentarthurdent";} + }; + + var names = openils.Util.userFullName(test_user); + + console.log(names); + + doh.assertTrue(names.indexOf(test_user.prefix()) != -1); + doh.assertTrue(names.indexOf(test_user.first_given_name()) != -1); + doh.assertTrue(names.indexOf(test_user.second_given_name()) != -1); + doh.assertTrue(names.indexOf(test_user.family_name()) != -1); + doh.assertTrue(names.indexOf(test_user.suffix()) != -1); + doh.assertTrue(names.indexOf(test_user.alias()) != -1); + doh.assertTrue(names.indexOf(test_user.usrname()) != -1); + + doh.assertTrue(names.length == Object.keys(test_user).length); + +}, + + +function test_userFullNameHash(doh) { + + var test_user = { + prefix: function(){return "Mr.";}, + first_given_name: function(){return "DENT";}, + second_given_name: function(){return "Arthur";}, + family_name: function(){return "dent";}, + suffix: function(){return "jr";}, + alias: function(){return "The Sandwich Maker";}, + usrname: function(){return "dentarthurdent";} + }; + + var names = openils.Util.userFullNameHash(test_user); + + console.log(names); + + doh.assertTrue(names.prefix == test_user.prefix()); + doh.assertTrue(names.first_given_name == test_user.first_given_name()); + doh.assertTrue(names.second_given_name == test_user.second_given_name()); + doh.assertTrue(names.family_name == test_user.family_name()); + doh.assertTrue(names.suffix == test_user.suffix()); + doh.assertTrue(names.alias == test_user.alias()); + doh.assertTrue(names.usrname == test_user.usrname()); + + + doh.assertTrue(Object.keys(names).length == Object.keys(test_user).length); + +}, + + +function test_addOnLoad(doh) { + //TODO IMPLEMENT ME + //doh.assertTrue(false); +}, + + +function test_arrayContains(doh) { + array = ["hello", 1, 1.0, false, 'a', [], {key: 'value'}, ['nonemptyset']]; + + doh.assertTrue(openils.Util.arrayContains(array, "hello")); + doh.assertTrue(openils.Util.arrayContains(array, 1)); + doh.assertTrue(openils.Util.arrayContains(array, 1.0)); + doh.assertTrue(openils.Util.arrayContains(array, false)); + doh.assertTrue(openils.Util.arrayContains(array, 'a')); + doh.assertTrue(openils.Util.arrayContains(array, [])); + //doh.assertTrue(openils.Util.arrayContains(array, {key: 'value'})); + //doh.assertTrue(openils.Util.arrayContains(array, ['nonemptyset'])); + + doh.assertFalse(openils.Util.arrayContains(array, "world")); +}, + +function test_selectorValue(doh) { + //TODO IMPLEMENT ME + //doh.assertTrue(false); +}, + + +function test_getKeyCode(doh) { + var evt1 = {charCode:'a'}; + var evt2 = {which:'a'}; + var evt3 = {keyCode:'a'}; + + doh.assertTrue(openils.Util.getCharCode(null) == -1); + doh.assertTrue(openils.Util.getCharCode(evt1) == 'a'); + doh.assertTrue(openils.Util.getCharCode(evt2) == 'a'); + doh.assertTrue(openils.Util.getCharCode(evt3) == 'a'); +}, + + +function test_registerEnterHandler(doh) { + //TODO IMPLEMENT ME + //doh.assertTrue(false); +}, + + +function test_readResponse(doh) { + //TODO IMPLEMENT ME + //doh.assertTrue(false); +}, + + +function test_addCSSClass(doh) { + //TODO IMPLEMENT ME + //doh.assertTrue(false); +}, + +function test_removeCSSClass(doh) { + //TODO IMPLEMENT ME + //doh.assertTrue(false); +}, + + +function test_objectSort(doh) { + var obj_list = [{ + id: function(){return 2;}, + name: function(){return "y";} + }, { + id: function(){return 1;}, + name: function(){return "z";} + }, { + id: function(){return 3;}, + name: function(){return "x";} + }]; + + var i_sorted = openils.Util.objectSort(obj_list, "id"); + var n_sorted = openils.Util.objectSort(obj_list, "name"); + var i_sorted_default = openils.Util.objectSort(obj_list); + var non_sortable = openils.Util.objectSort("Ian Malcolm with the candlestck on Isla Nubar!"); + + doh.assertTrue(i_sorted.length == obj_list.length); + doh.assertTrue(n_sorted.length == obj_list.length); + doh.assertTrue(i_sorted_default.length == obj_list.length); + doh.assertTrue(non_sortable.length == 0); + doh.assertTrue(non_sortable == []); + + doh.assertTrue(i_sorted[1]['id']() > i_sorted[2]['id']()); + doh.assertTrue(i_sorted[2]['id']() > i_sorted[3]['id']()); + + doh.assertTrue(n_sorted[1]['name']() > n_sorted[2]['name']()); + doh.assertTrue(n_sorted[2]['name']() > n_sorted[3]['name']()); + + doh.assertTrue(i_sorted_default[1]['id']() > i_sorted_default[2]['id']()); + doh.assertTrue(i_sorted_default[2]['id']() > i_sorted_default[3]['id']()); + +}, + +function test_isTrue(doh) { + //return (val && val != '0' && !(val+'').match(/^f$/i)); + doh.assertFalse(null); + doh.assertFalse('0'); + doh.assertFalse('f'); + doh.assertTrue('false'); + doh.assertTrue('true'); + doh.assertTrue('t'); + doh.assertTrue(1); + doh.assertTrue('T'); + doh.assertTrue('F'); + doh.assertFalse([]); +}, + + +function test_mapList(doh) { + var obj_list = [{ + id: '2', + name: "y" + }, { + id: '1', + name: "z" + }, { + id: '3', + name: "x" + }]; + var obj_func_list = [{ + id: function () { + return '2'; + }, + name: "y" + }, { + id: function () { + return '1'; + }, + name: "z" + }, { + id: function () { + return '3'; + }, + name: "x" + }]; + + + var id_mapping = openils.Util.mapList(obj_list, 'id', false); + var id_func_mapping = openils.Util.mapList(obj_func_list, 'id', true); + console.log(id_mapping); + console.log(id_func_mapping); + + doh.assertTrue(Object.keys(id_mapping).length == obj_list.length); + doh.assertTrue(Object.keys(id_func_mapping).length == obj_list.length); + + /**doh.assertTrue(id_mapping['1'][name] == "z"); + doh.assertTrue(id_mapping['2'][name] == "y"); + doh.assertTrue(id_mapping['3'][name] == "x"); + + + doh.assertTrue(id_func_mapping['1'][name] == "z"); + doh.assertTrue(id_func_mapping['2'][name] == "y"); + doh.assertTrue(id_func_mapping['3'][name] == "x"); + + **/ +}, + + function test_trimString(doh) { + doh.assertTrue(openils.Util.trimString(" Hello world ") == "Hello world"); + doh.assertTrue(openils.Util.trimString("\t\tHello world ") == "Hello world"); + doh.assertTrue(openils.Util.trimString("\f\n\r\t\vHello world") == "Hello world"); + }, + + function test_intervalToSeconds(doh) { + doh.assertTrue(openils.Util.intervalToSeconds("3 days 6 hours") == 280800); + doh.assertTrue(openils.Util.intervalToSeconds("1 year 2 days") == 31708800); + }, + + function test_hide(doh) { + //doh.assertTrue(false); + //TODO fixme + //openils.Util.hide = function(node) { + }, + + + + function test_show(doh) { + /**openils.Util.show = function(node, displayType) { + if(typeof node == 'string') + node = dojo.byId(node); + displayType = displayType || 'block'; + dojo.style(node, 'display', displayType); + dojo.style(node, 'visibility', 'visible'); + };**/ + //doh.assertTrue(false); + }, + + + function test_toggle(doh) { + /** + openils.Util.toggle = function(node, displayType) { + if(typeof node == 'string') + node = dojo.byId(node); + if(dojo.style(node, 'display') == 'none') + openils.Util.show(node, displayType); + else + openils.Util.hide(node); + };**/ + //doh.assertTrue(false); + }, + + + function test_appendClear(doh) { + /** + + openils.Util.appendClear = function(node, child) { + if(typeof node == 'string') + node = dojo.byId(node); + while(node.childNodes[0]) + node.removeChild(node.childNodes[0]); + node.appendChild(child); + };**/ + //doh.assertTrue(false); + }, + + function test_playAudioUrl(doh) { + /** + * Plays a sound file via URL. Only works with browsers + * that support HTML 5