1 // ========================================================================== 2 // Project: SproutCore - JavaScript Application Framework 3 // Copyright: ©2006-2011 Apple Inc. and contributors. 4 // License: Licensed under MIT license (see license.js) 5 // ========================================================================== 6 /*globals module ok equals same test json0_9 json10_19 json20_29 json30_39 json40_49 */ 7 8 var MyApp; 9 10 /* Define a standard test setup for use in most integration and unit tests. */ 11 var StandardTestSetup = { 12 setup: function() { 13 14 // define namespace 15 MyApp = SC.Object.create({ 16 store: SC.Store.create() 17 }); 18 19 // define basic record 20 MyApp.Author = SC.Record.extend({ 21 isCylon: function() { 22 switch(this.get('fullName')) { 23 case "Saul Tigh": 24 case "Galen Tyrol": 25 return YES; 26 default: 27 return NO; 28 } 29 }.property('fullName').cacheable() 30 }); 31 32 // define fixture server. 33 // MyApp.fixtureServer = SC.FixtureServer.create({ 34 // simulateResponseFromServer: function(guid, storeKey) { 35 // var json = []; 36 // if(guid === '123') { 37 // json = [ {"type": "Author", "guid": "123","fullName": "Galen Tyrol", "bookTitle": "The Fear of the Spiders", "address":" London University, 142 Castro St, London, UK"}]; 38 // } 39 // if(guid === 'john locke') { 40 // this.get('childStore').didCreateRecords([storeKey], ['abcdefg'], [{guid: 'abcdefg', fullName: "John Locke", bookTitle: "A Letter Concerning Toleration"}]); 41 // 42 // return; 43 // } 44 // if(guid === 'jim locke') { 45 // console.log('LOADING JIM LOCKE %@'.fmt(storeKey)); 46 // this.get('childStore').didCreateRecords([storeKey], ['abc'], [{guid: 'abc', fullName: "Jim Locke", bookTitle: "A Letter Concerning Toleration Part Deux"}]); 47 // 48 // return; 49 // } 50 // 51 // this.get('childStore').loadRecords(json, MyApp.Author); 52 // 53 // } 54 // }); 55 // 56 // MyApp.fixtureServer.addStore(MyApp.store); 57 58 59 // verify initial state 60 // ok(MyApp, "MyApp is defined") ; 61 // ok(MyApp.store, "MyApp.store is defined") ; 62 // ok(MyApp.fixtureServer, "MyApp.fixtureServer is defined") ; 63 // ok(MyApp.Author, "MyApp.Author is defined") ; 64 // ok(json0_9, "json0_9 is defined") ; 65 // ok(json10_19, "json10_19 is defined") ; 66 // ok(json20_29, "json20_29 is defined") ; 67 // ok(json30_39, "json30_39 is defined") ; 68 // ok(json40_49, "json40_49 is defined") ; 69 70 return this ; 71 }, 72 73 loadRecords: function() { 74 75 // load in some records -- dup json first so that edits to the data will 76 // not impact other tests 77 function dup(array) { 78 var ret = [], len = array.length, idx; 79 for(idx=0;idx<len;idx++) ret[idx] = SC.clone(array[idx]); 80 return ret ; 81 } 82 83 MyApp.store.loadRecords(dup(json0_9), MyApp.Author); 84 MyApp.store.loadRecords(dup(json10_19), MyApp.Author, 'guid'); 85 86 var recordTypes = [MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author]; 87 MyApp.store.loadRecords(dup(json20_29), recordTypes); 88 89 recordTypes = [MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author, MyApp.Author]; 90 MyApp.store.loadRecords(dup(json30_39), recordTypes, 'guid'); 91 92 MyApp.store.loadRecords(dup(json40_49)); 93 return this ; 94 } 95 }; 96 97