📄 readonlyitemfiletesttemplates.js
字号:
store.fetch({ query: {abbr: "ec"}, onComplete: onComplete, onError: onError }); return d; } }, { name: "Read API: getLabelAttributes()", runTest: function(datastore, t){ // summary: // Simple test of the getLabelAttributes function against a store set that has a label defined. // description: // Simple test of the getLabelAttributes function against a store set that has a label defined. var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); var d = new doh.Deferred(); function onComplete(items, request){ t.assertEqual(items.length, 1); var labelList = store.getLabelAttributes(items[0]); t.assertTrue(dojo.isArray(labelList)); t.assertEqual("name", labelList[0]); d.callback(true); } function onError(errData, request){ t.assertTrue(false); d.errback(errData); } store.fetch({ query: {abbr: "ec"}, onComplete: onComplete, onError: onError }); return d; } }, { name: "Read API: getValue()", runTest: function(datastore, t){ // summary: // Simple test of the getValue function of the store. // description: // Simple test of the getValue function of the store. var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); var d = new doh.Deferred(); function onItem(item){ t.assertTrue(item !== null); var name = store.getValue(item,"name"); t.assertTrue(name === "El Salvador"); d.callback(true); } function onError(errData){ t.assertTrue(false); d.errback(errData); } store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); return d; // Deferred } }, { name: "Read API: getValues()", runTest: function(datastore, t){ // summary: // Simple test of the getValues function of the store. // description: // Simple test of the getValues function of the store. var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); var d = new doh.Deferred(); function onItem(item){ t.assertTrue(item !== null); var names = store.getValues(item,"name"); t.assertTrue(dojo.isArray(names)); t.assertEqual(names.length, 1); t.assertEqual(names[0], "El Salvador"); d.callback(true); } function onError(errData){ t.assertTrue(false); d.errback(errData); } store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); return d; // Deferred } }, { name: "Read API: isItem()", runTest: function(datastore, t){ // summary: // Simple test of the isItem function of the store // description: // Simple test of the isItem function of the store var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); var d = new doh.Deferred(); function onItem(item){ t.assertTrue(item !== null); t.assertTrue(store.isItem(item)); t.assertTrue(!store.isItem({})); d.callback(true); } function onError(errData){ t.assertTrue(false); d.errback(errData); } store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); return d; // Deferred } }, { name: "Read API: isItem() multistore", runTest: function(datastore, t){ // summary: // Simple test of the isItem function of the store // to verify two different store instances do not accept // items from each other. // description: // Simple test of the isItem function of the store // to verify two different store instances do not accept // items from each other. // Two different instances, even if they read from the same URL // should not accept items between each other! var store1 = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); var store2 = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); var d = new doh.Deferred(); function onItem1(item1){ t.assertTrue(item1 !== null); function onItem2(item2){ t.assertTrue(item1 !== null); t.assertTrue(item2 !== null); t.assertTrue(store1.isItem(item1)); t.assertTrue(store2.isItem(item2)); t.assertTrue(!store1.isItem(item2)); t.assertTrue(!store2.isItem(item1)); d.callback(true); } store2.fetchItemByIdentity({identity: "sv", onItem: onItem2, onError: onError}); } function onError(errData){ t.assertTrue(false); d.errback(errData); } store1.fetchItemByIdentity({identity: "sv", onItem: onItem1, onError: onError}); return d; // Deferred } }, { name: "Read API: hasAttribute()", runTest: function(datastore, t){ // summary: // Simple test of the hasAttribute function of the store // description: // Simple test of the hasAttribute function of the store var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); var d = new doh.Deferred(); function onItem(item){ t.assertTrue(item !== null); t.assertTrue(store.hasAttribute(item, "abbr")); t.assertTrue(!store.hasAttribute(item, "abbr_not")); //Test that null attributes throw an exception var passed = false; try{ store.hasAttribute(item, null); }catch (e){ passed = true; } t.assertTrue(passed); d.callback(true); } function onError(errData){ t.assertTrue(false); d.errback(errData); } store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); return d; // Deferred } }, { name: "Read API: containsValue()", runTest: function(datastore, t){ // summary: // Simple test of the containsValue function of the store // description: // Simple test of the containsValue function of the store var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); var d = new doh.Deferred(); function onItem(item){ t.assertTrue(item !== null); t.assertTrue(store.containsValue(item, "abbr", "sv")); t.assertTrue(!store.containsValue(item, "abbr", "sv1")); t.assertTrue(!store.containsValue(item, "abbr", null)); //Test that null attributes throw an exception var passed = false; try{ store.containsValue(item, null, "foo"); }catch (e){ passed = true; } t.assertTrue(passed); d.callback(true); } function onError(errData){ t.assertTrue(false); d.errback(errData); } store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); return d; // Deferred } }, { name: "Read API: getAttributes()", runTest: function(datastore, t){ // summary: // Simple test of the getAttributes function of the store // description: // Simple test of the getAttributes function of the store var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); var d = new doh.Deferred(); function onItem(item){ t.assertTrue(item !== null); t.assertTrue(store.isItem(item)); var attributes = store.getAttributes(item); t.assertEqual(attributes.length, 3); for(var i = 0; i < attributes.length; i++){ t.assertTrue((attributes[i] === "name" || attributes[i] === "abbr" || attributes[i] === "capital")); } d.callback(true); } function onError(errData){ t.assertTrue(false); d.errback(errData); } store.fetchItemByIdentity({identity: "sv", onItem: onItem, onError: onError}); return d; // Deferred } }, { name: "Read API: getFeatures()", runTest: function(datastore, t){ // summary: // Simple test of the getFeatures function of the store // description: // Simple test of the getFeatures function of the store var store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); var features = store.getFeatures(); t.assertTrue(features["dojo.data.api.Read"] != null); t.assertTrue(features["dojo.data.api.Identity"] != null); } }, { name: "Read API: fetch() patternMatch0", runTest: function(datastore, 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 store = new datastore(tests.data.readOnlyItemFileTestTemplates.getTestData("countries")); var d = new doh.Deferred(); function completed(items, request) { t.assertEqual(items.length, 5); var passed = true; for(var i = 0; i < items.length; i++){ var value = store.getValue(items[i], "abbr"); if(!(value === "ec" || value === "eg" || value === "er" || value === "ee" || value === "et")){ passed=false; break; } } t.assertTrue(passed); if (passed){ d.callback(true); }else{ d.errback(new Error("Unexpected abbreviation found, match failure.")); } } function error(error, request) { t.assertTrue(false); d.errback(error); } store.fetch({query: {abbr: "e*"}, onComplete: completed, onError: error}); return d; } }, { name: "Read API: fetch() patternMatch1", runTest: function(datastore, t){ // summary: // Function to test pattern matching of everything with $ in it. // description: // Function to test pattern matching of everything with $ in it. var store = new datastore({data: { identifier: "uniqueId", items: [ {uniqueId: 1, value:"foo*bar"}, {uniqueId: 2, value:"bar*foo"}, {uniqueId: 3, value:"boomBam"}, {uniqueId: 4, value:"bit$Bite"}, {uniqueId: 5, value:"ouagadogou"}, {uniqueId: 6, value:"BaBaMaSaRa***Foo"}, {uniqueId: 7, value:"squawl"}, {uniqueId: 8, value:"seaweed"}, {uniqueId: 9, value:"jfq4@#!$!@Rf14r14i5u"} ] } }); var d = new doh.Deferred(); function completed(items, request){ t.assertEqual(items.length, 2); var passed = true; for(var i = 0; i < items.length; i++){ var value = store.getValue(items[i], "value"); if(!(value === "bit$Bite" || value === "jfq4@#!$!@Rf14r14i5u")){ passed=false; break; } } t.assertTrue(passed); if (passed){ d.callback(true); }else{ d.errback(new Error("Unexpected pattern matched. Filter failure.")); } } function error(error, request){ t.assertTrue(false); d.errback(error); } store.fetch({query: {value: "*$*"}, onComplete: completed, onError: error}); return d; } }, { name: "Read API: fetch() patternMatch2", runTest: function(datastore, t){ // summary: // Function to test exact pattern match // description: // Function to test exact pattern match var store = new datastore({data: { identifier: "uniqueId", items: [ {uniqueId: 1, value:"foo*bar"}, {uniqueId: 2, value:"bar*foo"}, {uniqueId: 3, value:"boomBam"}, {uniqueId: 4, value:"bit$Bite"}, {uniqueId: 5, value:"ouagadogou"}, {uniqueId: 6, value:"BaBaMaSaRa***Foo"}, {uniqueId: 7, value:"squawl"}, {uniqueId: 8, value:"seaweed"}, {uniqueId: 9, value:"jfq4@#!$!@Rf14r14i5u"} ] } }); var d = new doh.Deferred(); function completed(items, request){ t.assertEqual(items.length, 1); var passed = true; for(var i = 0; i < items.length; i++){ var value = store.getValue(items[i], "value"); if(!(value === "bar*foo")){ passed=false; break; } } t.assertTrue(passed); if (passed){ d.callback(true); }else{ d.errback(new Error("Unexpected abbreviation found, match failure.")); } } function error(error, request){ t.assertTrue(false); d.errback(error); } store.fetch({query: {value: "bar\*foo"}, onComplete: completed, onError: error}); return d; } }, { name: "Read API: fetch() patternMatch_caseSensitive", runTest: function(datastore, t){ // summary: // Function to test pattern matching of a pattern case-sensitively // description: // Function to test pattern matching of a pattern case-sensitively var store = new datastore({data: { identifier: "uniqueId", items: [ {uniqueId: 1, value:"foo*bar"}, {uniqueId: 2, value:"bar*foo"}, {uniqueId: 3, value:"BAR*foo"}, {uniqueId: 4, value:"BARBananafoo"} ] } }); var d = new doh.Deferred(); function completed(items, request){ t.assertEqual(1, items.length); var passed = true; for(var i = 0; i < items.length; i++){ var value = store.getValue(items[i], "value"); if(!(value === "bar*foo")){ passed=false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -