📄 keyvaluestore.js
字号:
return d; }, function testReadAPI_getAttributes_onlyTwo(t){ // summary: // Simple test of the getAttributes function of the store // description: // Simple test of the getAttributes function of the store var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv"); var keyStore = new dojox.data.KeyValueStore(args); var d = new doh.Deferred(); function onItem(item){ // Test an item that does not have all of the attributes t.assertTrue(item !== null); t.assertTrue(keyStore.isItem(item)); var attributes = keyStore.getAttributes(item); t.assertTrue(attributes.length === 3); t.assertTrue(attributes[0] === "key"); t.assertTrue(attributes[1] === "value"); t.assertTrue(attributes[2] === "nmonth"); d.callback(true); } keyStore.fetchItemByIdentity({identity: "nmonth", onItem: onItem, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)}); return d; }, function testReadAPI_getFeatures(t){ // summary: // Simple test of the getFeatures function of the store // description: // Simple test of the getFeatures function of the store var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv"); var keyStore = new dojox.data.KeyValueStore(args); var features = keyStore.getFeatures(); var count = 0; for(i in features){ t.assertTrue((i === "dojo.data.api.Read" || i === "dojo.data.api.Identity")); count++; } t.assertTrue(count === 2); }, function testReadAPI_fetch_patternMatch0(t){ // summary: // Function to test pattern matching of everything starting with lowercase e // description: // Function to test pattern matching of everything starting with lowercase e var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv"); var keyStore = new dojox.data.KeyValueStore(args); var d = new doh.Deferred(); function completed(items, request){ t.is(2, items.length); var valueArray = [ "nmonth", "month"]; t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "key", valueArray)); d.callback(true); } keyStore.fetch({query: {key: "*month"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)}); return d; //Object }, function testReadAPI_fetch_patternMatch1(t){ // summary: // Function to test pattern matching of everything with $ in it. // description: // Function to test pattern matching of everything with $ in it. var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv"); var keyStore = new dojox.data.KeyValueStore(args); var d = new doh.Deferred(); function completed(items, request){ t.assertTrue(items.length === 2); var valueArray = [ "1", "Saturday"]; t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "value", valueArray)); d.callback(true); } keyStore.fetch({query: {key: "*day"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)}); return d; //Object }, function testReadAPI_fetch_patternMatch2(t){ // summary: // Function to test exact pattern match // description: // Function to test exact pattern match var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv"); var keyStore = new dojox.data.KeyValueStore(args); var d = new doh.Deferred(); function completed(items, request){ t.is(2, items.length); t.assertTrue(keyStore.getValue(items[0], "value") === "12"); t.assertTrue(keyStore.getValue(items[0], "key") === "nmonth"); t.assertTrue(keyStore.getValue(items[1], "value") === "1"); t.assertTrue(keyStore.getValue(items[1], "key") === "nday"); d.callback(true); } keyStore.fetch({query: {value: "1*"}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)}); return d; //Object }, function testReadAPI_fetch_patternMatch_caseInsensitive(t){ // summary: // Function to test exact pattern match with case insensitivity set. // description: // Function to test exact pattern match with case insensitivity set. var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv"); var keyStore = new dojox.data.KeyValueStore(args); var d = new doh.Deferred(); function completed(items, request){ t.is(1, items.length); t.assertTrue(keyStore.getValue(items[0], "value") === "December"); d.callback(true); } keyStore.fetch({query: {key: "MONth"}, queryOptions: {ignoreCase: true}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)}); return d; //Object }, function testReadAPI_fetch_patternMatch_caseSensitive(t){ // summary: // Function to test exact pattern match with case insensitivity set. // description: // Function to test exact pattern match with case insensitivity set. var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv"); var keyStore = new dojox.data.KeyValueStore(args); var d = new doh.Deferred(); function completed(items, request){ t.is(0, items.length); d.callback(true); } keyStore.fetch({query: {value: "DECEMberO"}, queryOptions: {ignoreCase: false}, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)}); return d; //Object }, function testReadAPI_fetch_sortAlphabetic(t){ // summary: // Function to test sorting alphabetic ordering. // description: // Function to test sorting alphabetic ordering. var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv"); var keyStore = new dojox.data.KeyValueStore(args); var d = new doh.Deferred(); function completed(items, request){ //Output should be in this order... var orderedArray = [ "day", "dayOfYear", "month", "nday", "nmonth", "weekOfYear", "year" ]; t.is(7, items.length); t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "key", orderedArray)); d.callback(true); } var sortAttributes = [{attribute: "key"}]; keyStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)}); return d; //Object }, function testReadAPI_fetch_sortAlphabeticDescending(t){ // summary: // Function to test sorting alphabetic ordering in descending mode. // description: // Function to test sorting alphabetic ordering in descending mode. var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv"); var keyStore = new dojox.data.KeyValueStore(args); var d = new doh.Deferred(); function completed(items, request){ //Output should be in this order... var orderedArray = [ "year", "weekOfYear", "nmonth", "nday", "month", "dayOfYear", "day" ]; t.is(7, items.length); t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "key", orderedArray)); d.callback(true); } var sortAttributes = [{attribute: "key", descending: true}]; keyStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)}); return d; //Object }, function testReadAPI_fetch_sortMultiple(t){ // summary: // Function to test sorting on multiple attributes. // description: // Function to test sorting on multiple attributes. var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/patterns.csv"); var keyStore = new dojox.data.KeyValueStore(args); var d = new doh.Deferred(); function completed(items, request){ var orderedArray1 = [ "123abc", "123abc", "123abc", "123abcdefg", "BaBaMaSaRa***Foo", "bar*foo", "bit$Bite", "foo*bar", "jfq4@#!$!@Rf14r14i5u", undefined ]; var orderedArray0 = [ "day", "dayOfYear", "month", "nday", "nmonth", "weekOfYear", "year" ]; var orderedArray1 = [ "Saturday", "335", "December", "1", "12", "48", "2007" ]; t.is(7, items.length); t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "key", orderedArray0)); t.assertTrue(dojox.data.tests.stores.KeyValueStore.verifyItems(keyStore, items, "value", orderedArray1)); d.callback(true); } var sortAttributes = [{ attribute: "key"}, { attribute: "value", descending: true}]; keyStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)}); return d; //Object }, function testReadAPI_fetch_sortMultipleSpecialComparator(t){ // summary: // Function to test sorting on multiple attributes with a custom comparator. // description: // Function to test sorting on multiple attributes with a custom comparator. var args = dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv"); var keyStore = new dojox.data.KeyValueStore(args); keyStore.comparatorMap = {}; keyStore.comparatorMap["key"] = function(a,b){ var ret = 0; // We want to sort keys alphabetical by the last character in the string function lastChar(name){ if(typeof name === "undefined"){ return undefined; } return name.slice(name.length-1); // Grab the last character in the string. } var lastCharA = lastChar(a); var lastCharB = lastChar(b); if(lastCharA > lastCharB || typeof lastCharA === "undefined"){ ret = 1; }else if(lastCharA < lastCharB || typeof lastCharB === "undefined"){ ret = -1; } return ret; }; var sortAttributes = [{attribute: "key", descending: true}, { attribute: "value", descending: true}]; var d = new doh.Deferred(); function completed(items, findResult){ var orderedArray = [5,4,0,3,2,1,6]; var orderedArray = [ "day", "nday", "weekOfYear", "dayOfYear", "year", "month", "nmonth" ]; t.assertTrue(items.length === 7); var passed = true; for(var i = 0; i < items.length; i++){ if(!(keyStore.getIdentity(items[i]) === orderedArray[i])){ passed=false; break; } } t.assertTrue(passed); d.callback(true); } keyStore.fetch({sort: sortAttributes, onComplete: completed, onError: dojo.partial(dojox.data.tests.stores.KeyValueStore.error, t, d)}); return d; //Object }, function testReadAPI_functionConformance(t){ // summary: // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances. // description: // Simple test read API conformance. Checks to see all declared functions are actual functions on the instances. var testStore = new dojox.data.KeyValueStore(dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv")); var readApi = new dojo.data.api.Read(); var passed = true; for(i in readApi){ if(i.toString().charAt(0) !== '_') { var member = readApi[i]; //Check that all the 'Read' defined functions exist on the test store. if(typeof member === "function"){ console.log("Looking at function: [" + i + "]"); var testStoreMember = testStore[i]; if(!(typeof testStoreMember === "function")){ console.log("Problem with function: [" + i + "]. Got value: " + testStoreMember); passed = false; break; } } } } t.assertTrue(passed); }, function testIdentityAPI_functionConformance(t){ // summary: // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances. // description: // Simple test identity API conformance. Checks to see all declared functions are actual functions on the instances. var testStore = new dojox.data.KeyValueStore(dojox.data.tests.stores.KeyValueStore.getDatasource("stores/movies.csv")); var identityApi = new dojo.data.api.Identity(); var passed = true; for(i in identityApi){ if(i.toString().charAt(0) !== '_') { var member = identityApi[i]; //Check that all the 'Read' defined functions exist on the test store. if(typeof member === "function"){ console.log("Looking at function: [" + i + "]"); var testStoreMember = testStore[i]; if(!(typeof testStoreMember === "function")){ passed = false; break; } } } } t.assertTrue(passed); } ]);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -