iteratorCounter; --r) {
- this.children.pop().element.remove();
- }
- // Special case for option in select
- if (child && child.element[0].nodeName === "OPTION") {
- var select = jQuery(child.element[0].parentNode);
- var cntl = select.data('controller');
- if (cntl) {
- cntl.lastValue = undefined;
- cntl.updateView(scope);
- }
- }
- });
- }
-};
-
-//////////////////////////////////
-// PopUp
-//////////////////////////////////
-
-function PopUp(doc) {
- this.doc = doc;
-};
-
-PopUp.OUT_EVENT = "mouseleave mouseout click dblclick keypress keyup";
-
-PopUp.onOver = function(e) {
- PopUp.onOut();
- var jNode = jQuery(this);
- jNode.bind(PopUp.OUT_EVENT, PopUp.onOut);
- var position = jNode.position();
- var de = document.documentElement;
- var w = self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
- var hasArea = w - position.left;
- var width = 300;
- var title = jNode.hasClass("ng-exception") ? "EXCEPTION:" : "Validation error...";
- var msg = jNode.attr("ng-error");
-
- var x;
- var arrowPos = hasArea>(width+75) ? "left" : "right";
- var tip = jQuery(
- "" +
- "
" +
- "
"+title+"
" +
- "
"+msg+"
" +
- "
");
- jQuery("body").append(tip);
- if(arrowPos === 'left'){
- x = position.left + this.offsetWidth + 11;
- }else{
- x = position.left - (width + 15);
- tip.find('.ng-arrow-right').css({left:width+1});
- }
-
- tip.css({left: x+"px", top: (position.top - 3)+"px"});
- return true;
-};
-
-PopUp.onOut = function() {
- jQuery('#ng-callout').
- unbind(PopUp.OUT_EVENT, PopUp.onOut).
- remove();
- return true;
-};
-
-PopUp.prototype = {
- bind: function () {
- var self = this;
- this.doc.find('.ng-validation-error,.ng-exception').
- live("mouseover", PopUp.onOver);
- }
-};
-
-//////////////////////////////////
-// Status
-//////////////////////////////////
-
-function NullStatus(body) {
-};
-
-NullStatus.prototype = {
- beginRequest:function(){},
- endRequest:function(){}
-};
-
-function Status(body) {
- this.requestCount = 0;
- this.body = body;
-};
-
-Status.DOM ='loading....
';
-
-Status.prototype = {
- beginRequest: function () {
- if (this.requestCount === 0) {
- (this.loader = this.loader || this.body.append(Status.DOM).find("#ng-loading")).show();
- }
- this.requestCount++;
- },
-
- endRequest: function () {
- this.requestCount--;
- if (this.requestCount === 0) {
- this.loader.hide("fold");
- }
- }
-};
diff --git a/src/moveToAngularCom/ControlBar.js b/src/moveToAngularCom/ControlBar.js
deleted file mode 100644
index b9a2de8a..00000000
--- a/src/moveToAngularCom/ControlBar.js
+++ /dev/null
@@ -1,72 +0,0 @@
-function ControlBar(document, serverUrl, database) {
- this._document = document;
- this.serverUrl = serverUrl;
- this.database = database;
- this._window = window;
- this.callbacks = [];
-};
-
-ControlBar.HTML =
- '';
-
-
-ControlBar.FORBIDEN =
- '' +
- 'Sorry, you do not have permission for this!'+
- '
';
-
-ControlBar.prototype = {
- bind: function () {
- },
-
- login: function (loginSubmitFn) {
- this.callbacks.push(loginSubmitFn);
- if (this.callbacks.length == 1) {
- this.doTemplate("/user_session/new.mini?database="+encodeURIComponent(this.database)+"&return_url=" + encodeURIComponent(this.urlWithoutAnchor()));
- }
- },
-
- logout: function (loginSubmitFn) {
- this.callbacks.push(loginSubmitFn);
- if (this.callbacks.length == 1) {
- this.doTemplate("/user_session/do_destroy.mini");
- }
- },
-
- urlWithoutAnchor: function (path) {
- return this._window['location']['href'].split("#")[0];
- },
-
- doTemplate: function (path) {
- var self = this;
- var id = new Date().getTime();
- var url = this.urlWithoutAnchor() + "#$iframe_notify=" + id;
- var iframeHeight = 330;
- var loginView = jQuery('');
- this._document.append(loginView);
- loginView['dialog']({
- 'height':iframeHeight + 33, 'width':500,
- 'resizable': false, 'modal':true,
- 'title': 'Authentication: <angular/>'
- });
- angularCallbacks["_iframe_notify_" + id] = function() {
- loginView['dialog']("destroy");
- loginView['remove']();
- foreach(self.callbacks, function(callback){
- callback();
- });
- self.callbacks = [];
- };
- },
-
- notAuthorized: function () {
- if (this.forbidenView) return;
- this.forbidenView = jQuery(ControlBar.FORBIDEN);
- this.forbidenView.dialog({bgiframe:true, height:70, modal:true});
- }
-};
\ No newline at end of file
diff --git a/src/moveToAngularCom/DataStore.js b/src/moveToAngularCom/DataStore.js
deleted file mode 100644
index 70bcc623..00000000
--- a/src/moveToAngularCom/DataStore.js
+++ /dev/null
@@ -1,330 +0,0 @@
-function DataStore(post, users, anchor) {
- this.post = post;
- this.users = users;
- this._cache_collections = [];
- this._cache = {'$collections':this._cache_collections};
- this.anchor = anchor;
- this.bulkRequest = [];
-};
-
-DataStore.NullEntity = extend(function(){}, {
- 'all': function(){return [];},
- 'query': function(){return [];},
- 'load': function(){return {};},
- 'title': undefined
-});
-
-DataStore.prototype = {
- cache: function(document) {
- if (! document.datastore === this) {
- throw "Parameter must be an instance of Entity! " + toJson(document);
- }
- var key = document['$entity'] + '/' + document['$id'];
- var cachedDocument = this._cache[key];
- if (cachedDocument) {
- Model.copyDirectFields(document, cachedDocument);
- } else {
- this._cache[key] = document;
- cachedDocument = document;
- }
- return cachedDocument;
- },
-
- load: function(instance, id, callback, failure) {
- if (id && id !== '*') {
- var self = this;
- this._jsonRequest(["GET", instance['$entity'] + "/" + id], function(response) {
- instance['$loadFrom'](response);
- instance['$migrate']();
- var clone = instance['$$entity'](instance);
- self.cache(clone);
- (callback||noop)(instance);
- }, failure);
- }
- return instance;
- },
-
- loadMany: function(entity, ids, callback) {
- var self=this;
- var list = [];
- var callbackCount = 0;
- foreach(ids, function(id){
- list.push(self.load(entity(), id, function(){
- callbackCount++;
- if (callbackCount == ids.length) {
- (callback||noop)(list);
- }
- }));
- });
- return list;
- },
-
- loadOrCreate: function(instance, id, callback) {
- var self=this;
- return this.load(instance, id, callback, function(response){
- if (response['$status_code'] == 404) {
- instance['$id'] = id;
- (callback||noop)(instance);
- } else {
- throw response;
- }
- });
- },
-
- loadAll: function(entity, callback) {
- var self = this;
- var list = [];
- list['$$accept'] = function(doc){
- return doc['$entity'] == entity['title'];
- };
- this._cache_collections.push(list);
- this._jsonRequest(["GET", entity['title']], function(response) {
- var rows = response;
- for ( var i = 0; i < rows.length; i++) {
- var document = entity();
- document['$loadFrom'](rows[i]);
- list.push(self.cache(document));
- }
- (callback||noop)(list);
- });
- return list;
- },
-
- save: function(document, callback) {
- var self = this;
- var data = {};
- document['$saveTo'](data);
- this._jsonRequest(["POST", "", data], function(response) {
- document['$loadFrom'](response);
- var cachedDoc = self.cache(document);
- _.each(self._cache_collections, function(collection){
- if (collection['$$accept'](document)) {
- angularArray['includeIf'](collection, cachedDoc, true);
- }
- });
- if (document['$$anchor']) {
- self.anchor[document['$$anchor']] = document['$id'];
- }
- if (callback)
- callback(document);
- });
- },
-
- remove: function(document, callback) {
- var self = this;
- var data = {};
- document['$saveTo'](data);
- this._jsonRequest(["DELETE", "", data], function(response) {
- delete self._cache[document['$entity'] + '/' + document['$id']];
- _.each(self._cache_collections, function(collection){
- for ( var i = 0; i < collection.length; i++) {
- var item = collection[i];
- if (item['$id'] == document['$id']) {
- collection.splice(i, 1);
- }
- }
- });
- (callback||noop)(response);
- });
- },
-
- _jsonRequest: function(request, callback, failure) {
- request['$$callback'] = callback;
- request['$$failure'] = failure||function(response){
- throw response;
- };
- this.bulkRequest.push(request);
- },
-
- flush: function() {
- if (this.bulkRequest.length === 0) return;
- var self = this;
- var bulkRequest = this.bulkRequest;
- this.bulkRequest = [];
- log('REQUEST:', bulkRequest);
- function callback(code, bulkResponse){
- log('RESPONSE[' + code + ']: ', bulkResponse);
- if(bulkResponse['$status_code'] == 401) {
- self.users['login'](function(){
- self.post(bulkRequest, callback);
- });
- } else if(bulkResponse['$status_code']) {
- alert(toJson(bulkResponse));
- } else {
- for ( var i = 0; i < bulkResponse.length; i++) {
- var response = bulkResponse[i];
- var request = bulkRequest[i];
- var responseCode = response['$status_code'];
- if(responseCode) {
- if(responseCode == 403) {
- self.users['notAuthorized']();
- } else {
- request['$$failure'](response);
- }
- } else {
- request['$$callback'](response);
- }
- }
- }
- }
- this.post(bulkRequest, callback);
- },
-
- saveScope: function(scope, callback) {
- var saveCounter = 1;
- function onSaveDone() {
- saveCounter--;
- if (saveCounter === 0 && callback)
- callback();
- }
- for(var key in scope) {
- var item = scope[key];
- if (item && item['$save'] == Model.prototype['$save']) {
- saveCounter++;
- item['$save'](onSaveDone);
- }
- }
- onSaveDone();
- },
-
- query: function(type, query, arg, callback){
- var self = this;
- var queryList = [];
- queryList['$$accept'] = function(doc){
- return false;
- };
- this._cache_collections.push(queryList);
- var request = type['title'] + '/' + query + '=' + arg;
- this._jsonRequest(["GET", request], function(response){
- var list = response;
- foreach(list, function(item){
- var document = type()['$loadFrom'](item);
- queryList.push(self.cache(document));
- });
- (callback||noop)(queryList);
- });
- return queryList;
- },
-
- entities: function(callback) {
- var entities = [];
- var self = this;
- this._jsonRequest(["GET", "$entities"], function(response) {
- foreach(response, function(value, entityName){
- entities.push(self.entity(entityName));
- });
- entities.sort(function(a,b){return a.title > b.title ? 1 : -1;});
- (callback||noop)(entities);
- });
- return entities;
- },
-
- documentCountsByUser: function(){
- var counts = {};
- var self = this;
- self.post([["GET", "$users"]], function(code, response){
- extend(counts, response[0]);
- });
- return counts;
- },
-
- userDocumentIdsByEntity: function(user){
- var ids = {};
- var self = this;
- self.post([["GET", "$users/" + user]], function(code, response){
- extend(ids, response[0]);
- });
- return ids;
- },
-
- entity: function(name, defaults){
- if (!name) {
- return DataStore.NullEntity;
- }
- var self = this;
- var entity = extend(function(initialState){
- return new Model(entity, initialState);
- }, {
- // entity.name does not work as name seems to be reserved for functions
- 'title': name,
- '$$factory': true,
- datastore: this, //private, obfuscate
- 'defaults': defaults || {},
- 'load': function(id, callback){
- return self.load(entity(), id, callback);
- },
- 'loadMany': function(ids, callback){
- return self.loadMany(entity, ids, callback);
- },
- 'loadOrCreate': function(id, callback){
- return self.loadOrCreate(entity(), id, callback);
- },
- 'all': function(callback){
- return self.loadAll(entity, callback);
- },
- 'query': function(query, queryArgs, callback){
- return self.query(entity, query, queryArgs, callback);
- },
- 'properties': function(callback) {
- self._jsonRequest(["GET", name + "/$properties"], callback);
- }
- });
- return entity;
- },
-
- join: function(join){
- function fn(){
- throw "Joined entities can not be instantiated into a document.";
- };
- function base(name){return name ? name.substring(0, name.indexOf('.')) : undefined;}
- function next(name){return name.substring(name.indexOf('.') + 1);}
- var joinOrder = _(join).chain().
- map(function($, name){
- return name;}).
- sortBy(function(name){
- var path = [];
- do {
- if (_(path).include(name)) throw "Infinite loop in join: " + path.join(" -> ");
- path.push(name);
- if (!join[name]) throw _("Named entity '<%=name%>' is undefined.").template({name:name});
- name = base(join[name].on);
- } while(name);
- return path.length;
- }).
- value();
- if (_(joinOrder).select(function($){return join[$].on;}).length != joinOrder.length - 1)
- throw "Exactly one entity needs to be primary.";
- fn['query'] = function(exp, value) {
- var joinedResult = [];
- var baseName = base(exp);
- if (baseName != joinOrder[0]) throw _("Named entity '<%=name%>' is not a primary entity.").template({name:baseName});
- var Entity = join[baseName].join;
- var joinIndex = 1;
- Entity['query'](next(exp), value, function(result){
- var nextJoinName = joinOrder[joinIndex++];
- var nextJoin = join[nextJoinName];
- var nextJoinOn = nextJoin.on;
- var joinIds = {};
- _(result).each(function(doc){
- var row = {};
- joinedResult.push(row);
- row[baseName] = doc;
- var id = Scope.getter(row, nextJoinOn);
- joinIds[id] = id;
- });
- nextJoin.join.loadMany(_.toArray(joinIds), function(result){
- var byId = {};
- _(result).each(function(doc){
- byId[doc.$id] = doc;
- });
- _(joinedResult).each(function(row){
- var id = Scope.getter(row, nextJoinOn);
- row[nextJoinName] = byId[id];
- });
- });
- });
- return joinedResult;
- };
- return fn;
- }
-};
diff --git a/src/moveToAngularCom/Server.js b/src/moveToAngularCom/Server.js
deleted file mode 100644
index 5c4ec3c6..00000000
--- a/src/moveToAngularCom/Server.js
+++ /dev/null
@@ -1,68 +0,0 @@
-function Server(url, getScript) {
- this.url = url;
- this.nextId = 0;
- this.getScript = getScript;
- this.uuid = "_" + ("" + Math.random()).substr(2) + "_";
- this.maxSize = 1800;
-};
-
-Server.prototype = {
- base64url: function(txt) {
- return Base64.encode(txt);
- },
-
- request: function(method, url, request, callback) {
- var requestId = this.uuid + (this.nextId++);
- var payload = this.base64url(toJson({'u':url, 'm':method, 'p':request}));
- var totalPockets = Math.ceil(payload.length / this.maxSize);
- var baseUrl = this.url + "/$/" + requestId + "/" + totalPockets + "/";
- angularCallbacks[requestId] = function(response) {
- delete angularCallbacks[requestId];
- callback(200, response);
- };
- for ( var pocketNo = 0; pocketNo < totalPockets; pocketNo++) {
- var pocket = payload.substr(pocketNo * this.maxSize, this.maxSize);
- this.getScript(baseUrl + (pocketNo+1) + "?h=" + pocket, noop);
- }
- }
-};
-
-function FrameServer(frame) {
- this.frame = frame;
-};
-FrameServer.PREFIX = "$DATASET:";
-
-FrameServer.prototype = {
- read:function(){
- this.data = fromJson(this.frame.name.substr(FrameServer.PREFIX.length));
- },
- write:function(){
- this.frame.name = FrameServer.PREFIX + toJson(this.data);
- },
- request: function(method, url, request, callback) {
- //alert(method + " " + url + " " + toJson(request) + " " + toJson(callback));
- }
-};
-
-
-function VisualServer(delegate, status, update) {
- this.delegate = delegate;
- this.update = update;
- this.status = status;
-};
-
-VisualServer.prototype = {
- request:function(method, url, request, callback) {
- var self = this;
- this.status.beginRequest(request);
- this.delegate.request(method, url, request, function() {
- self.status.endRequest();
- try {
- callback.apply(this, arguments);
- } catch (e) {
- alert(toJson(e));
- }
- self.update();
- });
- }
-};
diff --git a/src/moveToAngularCom/Users.js b/src/moveToAngularCom/Users.js
deleted file mode 100644
index fb5845d3..00000000
--- a/src/moveToAngularCom/Users.js
+++ /dev/null
@@ -1,35 +0,0 @@
-function Users(server, controlBar) {
- this.server = server;
- this.controlBar = controlBar;
-};
-
-extend(Users.prototype, {
- 'fetchCurrentUser':function(callback) {
- var self = this;
- this.server.request("GET", "/account.json", {}, function(code, response){
- self['current'] = response['user'];
- callback(response['user']);
- });
- },
-
- 'logout': function(callback) {
- var self = this;
- this.controlBar.logout(function(){
- delete self['current'];
- (callback||noop)();
- });
- },
-
- 'login': function(callback) {
- var self = this;
- this.controlBar.login(function(){
- self['fetchCurrentUser'](function(){
- (callback||noop)();
- });
- });
- },
-
- 'notAuthorized': function(){
- this.controlBar.notAuthorized();
- }
-});
diff --git a/src/moveToAngularCom/directivesAngularCom.js b/src/moveToAngularCom/directivesAngularCom.js
deleted file mode 100644
index 84032bdd..00000000
--- a/src/moveToAngularCom/directivesAngularCom.js
+++ /dev/null
@@ -1,29 +0,0 @@
-
-angular.directive("auth", function(expression, element){
- return function(){
- if(expression == "eager") {
- this.$users.fetchCurrent();
- }
- };
-});
-
-
-//expression = "book=Book:{year=2000}"
-angular.directive("entity", function(expression, element){
- //parse expression, ignore element
- var entityName; // "Book";
- var instanceName; // "book";
- var defaults; // {year: 2000};
-
- parse(expression);
-
- return function(){
- this[entityName] = this.$datastore.entity(entityName, defaults);
- this[instanceName] = this[entityName]();
- this.$watch("$anchor."+instanceName, function(newAnchor){
- this[instanceName] = this[entityName].get(this.$anchor[instanceName]);
- });
- };
-});
-
-
diff --git a/test/delete/ScopeTest.js b/test/delete/ScopeTest.js
deleted file mode 100644
index 24febf19..00000000
--- a/test/delete/ScopeTest.js
+++ /dev/null
@@ -1,145 +0,0 @@
-ScopeTest = TestCase('ScopeTest');
-
-ScopeTest.prototype.testGetScopeRetrieval = function(){
- var scope = {};
- var form = jQuery("");
- form.data('scope', scope);
- var c = form.find('c');
- assertTrue(scope === c.scope());
-};
-
-ScopeTest.prototype.testGetScopeRetrievalIntermediateNode = function(){
- var scope = {};
- var form = jQuery("");
- form.find("b").data('scope', scope);
- var b = form.find('b');
- assertTrue(scope === b.scope());
-};
-
-ScopeTest.prototype.testNoScopeDoesNotCauseInfiniteRecursion = function(){
- var form = jQuery("");
- var c = form.find('c');
- assertTrue(!c.scope());
-};
-
-ScopeTest.prototype.testScopeEval = function(){
- var scope = new Scope({b:345});
- assertEquals(scope.eval('b = 123'), 123);
- assertEquals(scope.get('b'), 123);
-};
-
-ScopeTest.prototype.testScopeFromPrototype = function(){
- var scope = new Scope({b:123});
- scope.eval('a = b');
- scope.eval('b = 456');
- assertEquals(scope.get('a'), 123);
- assertEquals(scope.get('b'), 456);
-};
-
-ScopeTest.prototype.testSetScopeGet = function(){
- var scope = new Scope();
- assertEquals(987, scope.set('a', 987));
- assertEquals(scope.get('a'), 987);
- assertEquals(scope.eval('a'), 987);
-};
-
-ScopeTest.prototype.testGetChain = function(){
- var scope = new Scope({a:{b:987}});
- assertEquals(scope.get('a.b'), 987);
- assertEquals(scope.eval('a.b'), 987);
-};
-
-ScopeTest.prototype.testGetUndefinedChain = function(){
- var scope = new Scope();
- assertEquals(typeof scope.get('a.b'), 'undefined');
-};
-
-ScopeTest.prototype.testSetChain = function(){
- var scope = new Scope({a:{}});
- scope.set('a.b', 987);
- assertEquals(scope.get('a.b'), 987);
- assertEquals(scope.eval('a.b'), 987);
-};
-
-ScopeTest.prototype.testSetGetOnChain = function(){
- var scope = new Scope();
- scope.set('a.b', 987);
- assertEquals(scope.get('a.b'), 987);
- assertEquals(scope.eval('a.b'), 987);
-};
-
-ScopeTest.prototype.testGlobalFunctionAccess =function(){
- window['scopeAddTest'] = function (a, b) {return a+b;};
- var scope = new Scope({window:window});
- assertEquals(scope.eval('window.scopeAddTest(1,2)'), 3);
-
- scope.set('add', function (a, b) {return a+b;});
- assertEquals(scope.eval('add(1,2)'), 3);
-
- scope.set('math.add', function (a, b) {return a+b;});
- assertEquals(scope.eval('math.add(1,2)'), 3);
-};
-
-ScopeTest.prototype.testValidationEval = function(){
- expectAsserts(4);
- var scope = new Scope();
- scope.set("name", "misko");
- angular.validator.testValidator = function(value, expect){
- assertEquals("misko", this.name);
- return value == expect ? null : "Error text";
- };
-
- assertEquals("Error text", scope.validate("testValidator:'abc'", 'x'));
- assertEquals(null, scope.validate("testValidator:'abc'", 'abc'));
-
- delete angular.validator['testValidator'];
-};
-
-ScopeTest.prototype.testCallingNonExistantMethodShouldProduceFriendlyException = function() {
- expectAsserts(1);
- var scope = new Scope({obj:{}});
- try {
- scope.eval("obj.iDontExist()");
- fail();
- } catch (e) {
- assertEquals("Expression 'obj.iDontExist' is not a function.", e);
- }
-};
-
-ScopeTest.prototype.testAccessingWithInvalidPathShouldThrowError = function() {
- var scope = new Scope();
- try {
- scope.get('a.{{b}}');
- fail();
- } catch (e) {
- assertEquals("Expression 'a.{{b}}' is not a valid expression for accesing variables.", e);
- }
-};
-
-ScopeTest.prototype.testItShouldHave$parent = function() {
- var parent = new Scope({}, "ROOT");
- var child = new Scope(parent.state);
- assertSame("parent", child.state.$parent, parent.state);
- assertSame("root", child.state.$root, parent.state);
-};
-
-ScopeTest.prototype.testItShouldHave$root = function() {
- var scope = new Scope({}, "ROOT");
- assertSame(scope.state.$root, scope.state);
-};
-
-ScopeTest.prototype.testItShouldBuildPathOnUndefined = function(){
- var scope = new Scope({}, "ROOT");
- scope.setEval("a.$b.c", 1);
- assertJsonEquals({$b:{c:1}}, scope.get("a"));
-};
-
-ScopeTest.prototype.testItShouldMapUnderscoreFunctions = function(){
- var scope = new Scope({}, "ROOT");
- scope.set("a", [1,2,3]);
- assertEquals('function', typeof scope.get("a.$size"));
- scope.eval("a.$includeIf(4,true)");
- assertEquals(4, scope.get("a.$size")());
- assertEquals(4, scope.eval("a.$size()"));
- assertEquals('undefined', typeof scope.get("a.dontExist"));
-};
diff --git a/test/delete/WidgetsTest.js b/test/delete/WidgetsTest.js
deleted file mode 100644
index ccc87afd..00000000
--- a/test/delete/WidgetsTest.js
+++ /dev/null
@@ -1,268 +0,0 @@
-WidgetTest = TestCase('WidgetTest');
-
-WidgetTest.prototype.testRequired = function () {
- var view = $('');
- var scope = new Scope({$invalidWidgets:[]});
- var cntl = new TextController(view[0], 'a', angularFormatter.noop);
- cntl.updateView(scope);
- assertTrue(view.hasClass('ng-validation-error'));
- assertEquals("Required Value", view.attr('ng-error'));
- scope.set('a', 'A');
- cntl.updateView(scope);
- assertFalse(view.hasClass('ng-validation-error'));
- assertEquals("undefined", typeof view.attr('ng-error'));
-};
-
-WidgetTest.prototype.testValidator = function () {
- var view = $('');
- var scope = new Scope({$invalidWidgets:[]});
- var cntl = new TextController(view[0], 'a', angularFormatter.noop);
- angular.validator.testValidator = function(value, expect){
- return value == expect ? false : "Error text";
- };
-
- scope.set('a', '');
- cntl.updateView(scope);
- assertEquals(view.hasClass('ng-validation-error'), false);
- assertEquals(null, view.attr('ng-error'));
-
- scope.set('a', 'X');
- cntl.updateView(scope);
- assertEquals(view.hasClass('ng-validation-error'), true);
- assertEquals(view.attr('ng-error'), "Error text");
- assertEquals("Error text", view.attr('ng-error'));
-
- scope.set('a', 'ABC');
- cntl.updateView(scope);
- assertEquals(view.hasClass('ng-validation-error'), false);
- assertEquals(view.attr('ng-error'), null);
- assertEquals(null, view.attr('ng-error'));
-
- delete angular.validator['testValidator'];
-};
-
-WidgetTest.prototype.testRequiredValidator = function () {
- var view = $('');
- var scope = new Scope({$invalidWidgets:[]});
- var cntl = new TextController(view[0], 'a', angularFormatter.noop);
- angular.validator.testValidator = function(value, expect){
- return value == expect ? null : "Error text";
- };
-
- scope.set('a', '');
- cntl.updateView(scope);
- assertEquals(view.hasClass('ng-validation-error'), true);
- assertEquals("Required Value", view.attr('ng-error'));
-
- scope.set('a', 'X');
- cntl.updateView(scope);
- assertEquals(view.hasClass('ng-validation-error'), true);
- assertEquals("Error text", view.attr('ng-error'));
-
- scope.set('a', 'ABC');
- cntl.updateView(scope);
- assertEquals(view.hasClass('ng-validation-error'), false);
- assertEquals(null, view.attr('ng-error'));
-
- delete angular.validator['testValidator'];
-};
-
-TextControllerTest = TestCase("TextControllerTest");
-
-TextControllerTest.prototype.testDatePicker = function() {
- var input = $('');
- input.data('scope', new Scope());
- var body = $(document.body);
- body.append(input);
- var binder = new Binder(input[0], new WidgetFactory());
- assertTrue('before', input.data('datepicker') === undefined);
- binder.compile();
- assertTrue('after', input.data('datepicker') !== null);
- assertTrue(body.html(), input.hasClass('hasDatepicker'));
-};
-
-RepeaterUpdaterTest = TestCase("RepeaterUpdaterTest");
-
-RepeaterUpdaterTest.prototype.testRemoveThenAdd = function() {
- var view = $("
");
- var template = function () {
- return $("");
- };
- var repeater = new RepeaterUpdater(view.find("span"), "a in b", template, "");
- var scope = new Scope();
- scope.set('b', [1,2]);
-
- repeater.updateView(scope);
-
- scope.set('b', []);
- repeater.updateView(scope);
-
- scope.set('b', [1]);
- repeater.updateView(scope);
- assertEquals(1, view.find("li").size());
-};
-
-RepeaterUpdaterTest.prototype.testShouldBindWidgetOnRepeaterClone = function(){
- //fail();
-};
-
-RepeaterUpdaterTest.prototype.testShouldThrowInformativeSyntaxError= function(){
- expectAsserts(1);
- try {
- var repeater = new RepeaterUpdater(null, "a=b");
- } catch (e) {
- assertEquals("Expected ng:repeat in form of 'item in collection' but got 'a=b'.", e);
- }
-};
-
-SelectControllerTest = TestCase("SelectControllerTest");
-
-SelectControllerTest.prototype.testShouldUpdateModelNullOnNothingSelected = function(){
- var scope = new Scope();
- var view = {selectedIndex:-1, options:[]};
- var cntl = new SelectController(view, 'abc');
- cntl.updateModel(scope);
- assertNull(scope.get('abc'));
-};
-
-SelectControllerTest.prototype.testShouldUpdateModelWhenNothingSelected = function(){
- var scope = new Scope();
- var view = {value:'123'};
- var cntl = new SelectController(view, 'abc');
- cntl.updateView(scope);
- assertEquals("123", scope.get('abc'));
-};
-
-BindUpdaterTest = TestCase("BindUpdaterTest");
-
-BindUpdaterTest.prototype.testShouldDisplayNothingForUndefined = function () {
- var view = $('');
- var controller = new BindUpdater(view[0], "{{a}}");
- var scope = new Scope();
-
- scope.set('a', undefined);
- controller.updateView(scope);
- assertEquals("", view.text());
-
- scope.set('a', null);
- controller.updateView(scope);
- assertEquals("", view.text());
-};
-
-BindUpdaterTest.prototype.testShouldDisplayJsonForNonStrings = function () {
- var view = $('');
- var controller = new BindUpdater(view[0], "{{obj}}");
-
- controller.updateView(new Scope({obj:[]}));
- assertEquals("[]", view.text());
-
- controller.updateView(new Scope({obj:{text:'abc'}}));
- assertEquals('abc', fromJson(view.text()).text);
-};
-
-
-BindUpdaterTest.prototype.testShouldInsertHtmlNode = function () {
- var view = $('');
- var controller = new BindUpdater(view[0], "&{{obj}}");
- var scope = new Scope();
-
- scope.set("obj", $('myDiv
')[0]);
- controller.updateView(scope);
- assertEquals("&myDiv", view.text());
-};
-
-
-BindUpdaterTest.prototype.testShouldDisplayTextMethod = function () {
- var view = $('');
- var controller = new BindUpdater(view[0], "{{obj}}");
- var scope = new Scope();
-
- scope.set("obj", new angular.filter.Meta({text:function(){return "abc";}}));
- controller.updateView(scope);
- assertEquals("abc", view.text());
-
- scope.set("obj", new angular.filter.Meta({text:"123"}));
- controller.updateView(scope);
- assertEquals("123", view.text());
-
- scope.set("obj", {text:"123"});
- controller.updateView(scope);
- assertEquals("123", fromJson(view.text()).text);
-};
-
-BindUpdaterTest.prototype.testShouldDisplayHtmlMethod = function () {
- var view = $('');
- var controller = new BindUpdater(view[0], "{{obj}}");
- var scope = new Scope();
-
- scope.set("obj", new angular.filter.Meta({html:function(){return "ab
c";}}));
- controller.updateView(scope);
- assertEquals("abc", view.text());
-
- scope.set("obj", new angular.filter.Meta({html:"12
3"}));
- controller.updateView(scope);
- assertEquals("123", view.text());
-
- scope.set("obj", {html:"123"});
- controller.updateView(scope);
- assertEquals("123", fromJson(view.text()).html);
-};
-
-BindUpdaterTest.prototype.testUdateBoolean = function() {
- var view = $('');
- var controller = new BindUpdater(view[0], "{{true}}, {{false}}");
- controller.updateView(new Scope());
- assertEquals('true, false', view.text());
-};
-
-BindAttrUpdaterTest = TestCase("BindAttrUpdaterTest");
-
-BindAttrUpdaterTest.prototype.testShouldLoadBlankImageWhenBindingIsUndefined = function () {
- var view = $('
');
- var controller = new BindAttrUpdater(view[0], {src: '{{imageUrl}}'});
-
- var scope = new Scope();
- scope.set('imageUrl', undefined);
- scope.set('$config.blankImage', 'http://server/blank.gif');
-
- controller.updateView(scope);
- assertEquals("http://server/blank.gif", view.attr('src'));
-};
-
-RepeaterUpdaterTest.prototype.testShouldNotDieWhenRepeatExpressionIsNull = function() {
- var rep = new RepeaterUpdater(null, "$item in items", null, null);
- var scope = new Scope();
- scope.set('items', undefined);
- rep.updateView(scope);
-};
-
-RepeaterUpdaterTest.prototype.testShouldIterateOverKeys = function() {
- var rep = new RepeaterUpdater(null, "($k,_v) in items", null, null);
- assertEquals("items", rep.iteratorExp);
- assertEquals("_v", rep.valueExp);
- assertEquals("$k", rep.keyExp);
-};
-
-EvalUpdaterTest = TestCase("EvalUpdaterTest");
-EvalUpdaterTest.prototype.testEvalThrowsException = function(){
- var view = $('');
- var eval = new EvalUpdater(view[0], 'undefined()');
-
- eval.updateView(new Scope());
- assertTrue(!!view.attr('ng-error'));
- assertTrue(view.hasClass('ng-exception'));
-
- eval.exp = "1";
- eval.updateView(new Scope());
- assertFalse(!!view.attr('ng-error'));
- assertFalse(view.hasClass('ng-exception'));
-};
-
-RadioControllerTest = TestCase("RadioController");
-RadioControllerTest.prototype.testItShouldTreatTrueStringAsBoolean = function () {
- var view = $('');
- var radio = new RadioController(view[0], 'select');
- var scope = new Scope({select:true});
- radio.updateView(scope);
- assertTrue(view[0].checked);
-};
diff --git a/test/moveToAngularCom/Base64Test.js b/test/moveToAngularCom/Base64Test.js
deleted file mode 100644
index a9353186..00000000
--- a/test/moveToAngularCom/Base64Test.js
+++ /dev/null
@@ -1,5 +0,0 @@
-Base64Test = TestCase('Base64Test');
-
-Base64Test.prototype.testEncodeDecode = function(){
- assertEquals(Base64.decode(Base64.encode('hello')), 'hello');
-};
diff --git a/test/moveToAngularCom/DataStoreTest.js b/test/moveToAngularCom/DataStoreTest.js
deleted file mode 100644
index 87c5be2e..00000000
--- a/test/moveToAngularCom/DataStoreTest.js
+++ /dev/null
@@ -1,616 +0,0 @@
-DataStoreTest = TestCase('DataStoreTest');
-
-DataStoreTest.prototype.testSavePostsToServer = function(){
- expectAsserts(10);
- var response;
- var post = function(data, callback){
- var method = data[0][0];
- var posted = data[0][2];
- assertEquals("POST", method);
- assertEquals("abc", posted.$entity);
- assertEquals("123", posted.$id);
- assertEquals("1", posted.$version);
- assertFalse('function' == typeof posted.save);
- response = fromJson(toJson(posted));
- response.$entity = "abc";
- response.$id = "123";
- response.$version = "2";
- callback(200, [response]);
- };
- var datastore = new DataStore(post);
- var model = datastore.entity('abc', {name: "value"})();
- model.$id = "123";
- model.$version = "1";
-
- datastore.save(model, function(obj){
- assertTrue(obj === model);
- assertEquals(obj.$entity, "abc");
- assertEquals(obj.$id, "123");
- assertEquals(obj.$version, "2");
- assertEquals(obj.name, "value");
- obj.after = true;
- });
- datastore.flush();
-};
-
-DataStoreTest.prototype.testLoadGetsFromServer = function(){
- expectAsserts(12);
- var post = function(data, callback){
- var method = data[0][0];
- var path = data[0][1];
- assertEquals("GET", method);
- assertEquals("abc/1", path);
- response = [{$entity:'abc', $id:'1', $version:'2', key:"value"}];
- callback(200, response);
- };
- var datastore = new DataStore(post);
-
- var model = datastore.entity("abc", {merge:true})();
- assertEquals(datastore.load(model, '1', function(obj){
- assertEquals(obj.$entity, "abc");
- assertEquals(obj.$id, "1");
- assertEquals(obj.$version, "2");
- assertEquals(obj.key, "value");
- }), model);
- datastore.flush();
- assertEquals(model.$entity, "abc");
- assertEquals(model.$id, "1");
- assertEquals(model.$version, "2");
- assertEquals(model.key, "value");
- assertEquals(model.merge, true);
-};
-
-DataStoreTest.prototype.testRemove = function(){
- expectAsserts(8);
- var response;
- var post = function(data, callback){
- var method = data[0][0];
- var posted = data[0][2];
- assertEquals("DELETE", method);
- assertEquals("abc", posted.$entity);
- assertEquals("123", posted.$id);
- assertEquals("1", posted.$version);
- assertFalse('function' == typeof posted.save);
- response = fromJson(toJson(posted));
- response.$entity = "abc";
- response.$id = "123";
- response.$version = "2";
- callback(200, [response]);
- };
- var model;
- var datastore = new DataStore(post);
- model = datastore.entity('abc', {name: "value"})();
- model.$id = "123";
- model.$version = "1";
-
- datastore.remove(model, function(obj){
- assertEquals(obj.$id, "123");
- assertEquals(obj.$version, "2");
- assertEquals(obj.name, "value");
- obj.after = true;
- });
- datastore.flush();
-
-};
-
-
-DataStoreTest.prototype.test401ResponseDoesNotCallCallback = function(){
- expectAsserts(1);
- var post = function(data, callback) {
- callback(200, {$status_code: 401});
- };
-
- var datastore = new DataStore(post, {login:function(){
- assertTrue(true);
- }});
-
- var onLoadAll = function(){
- assertTrue(false, "onLoadAll should not be called when response is status 401");
- };
- datastore.bulkRequest.push({});
- datastore.flush();
- datastore.loadAll({type: "A"}, onLoadAll);
-};
-
-DataStoreTest.prototype.test403ResponseDoesNotCallCallback = function(){
- expectAsserts(1);
- var post = function(data, callback) {
- callback(200, [{$status_code: 403}]);
- };
-
- var datastore = new DataStore(post, {notAuthorized:function(){
- assertTrue(true);
- }});
-
- var onLoadAll = function(){
- assertTrue(false, "onLoadAll should not be called when response is status 403");
- };
- datastore.bulkRequest.push({});
- datastore.flush();
- datastore.loadAll({type: "A"}, onLoadAll);
-};
-
-DataStoreTest.prototype.testLoadCalledWithoutIdShouldBeNoop = function(){
- expectAsserts(2);
- var post = function(url, callback){
- assertTrue(false);
- };
- var datastore = new DataStore(post);
- var model = datastore.entity("abc")();
- assertEquals(datastore.load(model, undefined), model);
- assertEquals(model.$entity, "abc");
-};
-
-DataStoreTest.prototype.testEntityFactory = function(){
- var ds = new DataStore();
- var Recipe = ds.entity("Recipe", {a:1, b:2});
- assertEquals(Recipe.title, "Recipe");
- assertEquals(Recipe.defaults.a, 1);
- assertEquals(Recipe.defaults.b, 2);
-
- var recipe = Recipe();
- assertEquals(recipe.$entity, "Recipe");
- assertEquals(recipe.a, 1);
- assertEquals(recipe.b, 2);
-
- recipe = new Recipe();
- assertEquals(recipe.$entity, "Recipe");
- assertEquals(recipe.a, 1);
- assertEquals(recipe.b, 2);
-};
-
-DataStoreTest.prototype.testEntityFactoryNoDefaults = function(){
- var ds = new DataStore();
- var Recipe = ds.entity("Recipe");
- assertEquals(Recipe.title, "Recipe");
-
- recipe = new Recipe();
- assertEquals(recipe.$entity, "Recipe");
-};
-
-DataStoreTest.prototype.testEntityFactoryWithInitialValues = function(){
- var ds = new DataStore();
- var Recipe = ds.entity("Recipe");
-
- var recipe = Recipe({name: "name"});
- assertEquals("name", recipe.name);
-};
-
-DataStoreTest.prototype.testEntityLoad = function(){
- var ds = new DataStore();
- var Recipe = ds.entity("Recipe", {a:1, b:2});
- ds.load = function(instance, id, callback){
- callback.apply(instance);
- return instance;
- };
- var instance = null;
- var recipe2 = Recipe.load("ID", function(){
- instance = this;
- });
- assertTrue(recipe2 === instance);
-};
-
-DataStoreTest.prototype.testSaveScope = function(){
- var ds = new DataStore();
- var log = "";
- var Person = ds.entity("Person");
- var person1 = Person({name:"A", $entity:"Person", $id:"1", $version:"1"}, ds);
- person1.$$anchor = "A";
- var person2 = Person({name:"B", $entity:"Person", $id:"2", $version:"2"}, ds);
- person2.$$anchor = "B";
- var anchor = {};
- ds.anchor = anchor;
- ds._jsonRequest = function(request, callback){
- log += "save(" + request[2].$id + ");";
- callback({$id:request[2].$id});
- };
- ds.saveScope({person1:person1, person2:person2,
- ignoreMe:{name: "ignore", save:function(callback){callback();}}}, function(){
- log += "done();";
- });
- assertEquals("save(1);save(2);done();", log);
- assertEquals(1, anchor.A);
- assertEquals(2, anchor.B);
-};
-
-DataStoreTest.prototype.testEntityLoadAllRows = function(){
- var ds = new DataStore();
- var Recipe = ds.entity("Recipe");
- var list = [];
- ds.loadAll = function(entity, callback){
- assertTrue(Recipe === entity);
- callback.apply(list);
- return list;
- };
- var items = Recipe.all(function(){
- assertTrue(list === this);
- });
- assertTrue(items === list);
-};
-
-DataStoreTest.prototype.testLoadAll = function(){
- expectAsserts(8);
- var post = function(data, callback){
- assertEquals("GET", data[0][0]);
- assertEquals("A", data[0][1]);
- callback(200, [[{$entity:'A', $id:'1'},{$entity:'A', $id:'2'}]]);
- };
- var datastore = new DataStore(post);
- var list = datastore.entity("A").all(function(){
- assertTrue(true);
- });
- datastore.flush();
- assertEquals(list.length, 2);
- assertEquals(list[0].$entity, "A");
- assertEquals(list[0].$id, "1");
- assertEquals(list[1].$entity, "A");
- assertEquals(list[1].$id, "2");
-};
-
-DataStoreTest.prototype.testQuery = function(){
- expectAsserts(5);
- var post = function(data, callback) {
- assertEquals("GET", data[0][0]);
- assertEquals("Employee/managerId=123abc", data[0][1]);
- callback(200, [[{$entity:"Employee", $id: "456", managerId: "123ABC"}]]);
-
- };
- var datastore = new DataStore(post);
- var Employee = datastore.entity("Employee");
- var list = Employee.query('managerId', "123abc", function(){
- assertTrue(true);
- });
- datastore.flush();
- assertJsonEquals([[{$entity:"Employee", $id: "456", managerId: "123ABC"}]], datastore._cache.$collections);
- assertEquals(list[0].$id, "456");
-};
-
-DataStoreTest.prototype.testLoadingDocumentRefreshesExistingArrays = function() {
- expectAsserts(12);
- var post;
- var datastore = new DataStore(function(r, c){post(r,c);});
- var Book = datastore.entity('Book');
- post = function(req, callback) {
- callback(200, [[{$id:1, $entity:"Book", name:"Moby"},
- {$id:2, $entity:"Book", name:"Dick"}]]);
- };
- var allBooks = Book.all();
- datastore.flush();
- var queryBooks = Book.query("a", "b");
- datastore.flush();
- assertEquals("Moby", allBooks[0].name);
- assertEquals("Dick", allBooks[1].name);
- assertEquals("Moby", queryBooks[0].name);
- assertEquals("Dick", queryBooks[1].name);
-
- post = function(req, callback) {
- assertEquals('[["GET","Book/1"]]', toJson(req));
- callback(200, [{$id:1, $entity:"Book", name:"Moby Dick"}]);
- };
- var book = Book.load(1);
- datastore.flush();
- assertEquals("Moby Dick", book.name);
- assertEquals("Moby Dick", allBooks[0].name);
- assertEquals("Moby Dick", queryBooks[0].name);
-
- post = function(req, callback) {
- assertEquals('POST', req[0][0]);
- callback(200, [{$id:1, $entity:"Book", name:"The Big Fish"}]);
- };
- book.$save();
- datastore.flush();
- assertEquals("The Big Fish", book.name);
- assertEquals("The Big Fish", allBooks[0].name);
- assertEquals("The Big Fish", queryBooks[0].name);
-};
-
-DataStoreTest.prototype.testEntityProperties = function() {
- expectAsserts(2);
- var datastore = new DataStore();
- var callback = {};
-
- datastore._jsonRequest = function(request, callbackFn) {
- assertJsonEquals(["GET", "Cheese/$properties"], request);
- assertEquals(callback, callbackFn);
- };
-
- var Cheese = datastore.entity("Cheese");
- Cheese.properties(callback);
-
-};
-
-DataStoreTest.prototype.testLoadInstanceIsNotFromCache = function() {
- var post;
- var datastore = new DataStore(function(r, c){post(r,c);});
- var Book = datastore.entity('Book');
-
- post = function(req, callback) {
- assertEquals('[["GET","Book/1"]]', toJson(req));
- callback(200, [{$id:1, $entity:"Book", name:"Moby Dick"}]);
- };
- var book = Book.load(1);
- datastore.flush();
- assertEquals("Moby Dick", book.name);
- assertFalse(book === datastore._cache['Book/1']);
-};
-
-DataStoreTest.prototype.testLoadStarsIsNewDocument = function() {
- var datastore = new DataStore();
- var Book = datastore.entity('Book');
- var book = Book.load('*');
- assertEquals('Book', book.$entity);
-};
-
-DataStoreTest.prototype.testUndefinedEntityReturnsNullValueObject = function() {
- var datastore = new DataStore();
- var Entity = datastore.entity(undefined);
- var all = Entity.all();
- assertEquals(0, all.length);
-};
-
-DataStoreTest.prototype.testFetchEntities = function(){
- expectAsserts(6);
- var post = function(data, callback){
- assertJsonEquals(["GET", "$entities"], data[0]);
- callback(200, [{A:0, B:0}]);
- };
- var datastore = new DataStore(post);
- var entities = datastore.entities(function(){
- assertTrue(true);
- });
- datastore.flush();
- assertJsonEquals([], datastore.bulkRequest);
- assertEquals(2, entities.length);
- assertEquals("A", entities[0].title);
- assertEquals("B", entities[1].title);
-};
-
-DataStoreTest.prototype.testItShouldMigrateSchema = function() {
- var datastore = new DataStore();
- var Entity = datastore.entity("Entity", {a:[], user:{name:"Misko", email:""}});
- var doc = Entity().$loadFrom({b:'abc', user:{email:"misko@hevery.com"}});
- assertFalse(
- toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}) ==
- toJson(doc));
- doc.$migrate();
- assertEquals(
- toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}),
- toJson(doc));
-};
-
-DataStoreTest.prototype.testItShouldCollectRequestsForBulk = function() {
- var ds = new DataStore();
- var Book = ds.entity("Book");
- var Library = ds.entity("Library");
- Book.all();
- Library.load("123");
- assertEquals(2, ds.bulkRequest.length);
- assertJsonEquals(["GET", "Book"], ds.bulkRequest[0]);
- assertJsonEquals(["GET", "Library/123"], ds.bulkRequest[1]);
-};
-
-DataStoreTest.prototype.testEmptyFlushShouldDoNothing = function () {
- var ds = new DataStore(function(){
- fail("expecting noop");
- });
- ds.flush();
-};
-
-DataStoreTest.prototype.testFlushShouldCallAllCallbacks = function() {
- var log = "";
- function post(request, callback){
- log += 'BulkRequest:' + toJson(request) + ';';
- callback(200, [[{$id:'ABC'}], {$id:'XYZ'}]);
- }
- var ds = new DataStore(post);
- var Book = ds.entity("Book");
- var Library = ds.entity("Library");
- Book.all(function(instance){
- log += toJson(instance) + ';';
- });
- Library.load("123", function(instance){
- log += toJson(instance) + ';';
- });
- assertEquals("", log);
- ds.flush();
- assertJsonEquals([], ds.bulkRequest);
- assertEquals('BulkRequest:[["GET","Book"],["GET","Library/123"]];[{"$id":"ABC"}];{"$id":"XYZ"};', log);
-};
-
-DataStoreTest.prototype.testSaveOnNotLoggedInRetriesAfterLoggin = function(){
- var log = "";
- var book;
- var ds = new DataStore(null, {login:function(c){c();}});
- ds.post = function (request, callback){
- assertJsonEquals([["POST", "", book]], request);
- ds.post = function(request, callback){
- assertJsonEquals([["POST", "", book]], request);
- ds.post = function(){fail("too much recursion");};
- callback(200, [{saved:"ok"}]);
- };
- callback(200, {$status_code:401});
- };
- book = ds.entity("Book")({name:"misko"});
- book.$save();
- ds.flush();
- assertJsonEquals({saved:"ok"}, book);
-};
-
-DataStoreTest.prototype.testItShouldRemoveItemFromCollectionWhenDeleted = function() {
- expectAsserts(6);
- var ds = new DataStore();
- ds.post = function(request, callback){
- assertJsonEquals([["GET", "Book"]], request);
- callback(200, [[{name:"Moby Dick", $id:123, $entity:'Book'}]]);
- };
- var Book = ds.entity("Book");
- var books = Book.all();
- ds.flush();
- assertJsonEquals([[{name:"Moby Dick", $id:123, $entity:'Book'}]], ds._cache.$collections);
- assertDefined(ds._cache['Book/123']);
- var book = Book({$id:123});
- ds.post = function(request, callback){
- assertJsonEquals([["DELETE", "", book]], request);
- callback(200, [book]);
- };
- ds.remove(book);
- ds.flush();
- assertUndefined(ds._cache['Book/123']);
- assertJsonEquals([[]],ds._cache.$collections);
-};
-
-DataStoreTest.prototype.testItShouldAddToAll = function() {
- expectAsserts(8);
- var ds = new DataStore();
- ds.post = function(request, callback){
- assertJsonEquals([["GET", "Book"]], request);
- callback(200, [[]]);
- };
- var Book = ds.entity("Book");
- var books = Book.all();
- assertEquals(0, books.length);
- ds.flush();
- var moby = Book({name:'moby'});
- moby.$save();
- ds.post = function(request, callback){
- assertJsonEquals([["POST", "", moby]], request);
- moby.$id = '123';
- callback(200, [moby]);
- };
- ds.flush();
- assertEquals(1, books.length);
- assertEquals(moby, books[0]);
-
- moby.$save();
- ds.flush();
- assertEquals(1, books.length);
- assertEquals(moby, books[0]);
-};
-
-DataStoreTest.prototype.testItShouldReturnCreatedDocumentCountByUser = function(){
- expectAsserts(2);
- var datastore = new DataStore(
- function(request, callback){
- assertJsonEquals([["GET", "$users"]], request);
- callback(200, [{misko:1, adam:1}]);
- });
- var users = datastore.documentCountsByUser();
- assertJsonEquals({misko:1, adam:1}, users);
-};
-
-
-DataStoreTest.prototype.testItShouldReturnDocumentIdsForUeserByEntity = function(){
- expectAsserts(2);
- var datastore = new DataStore(
- function(request, callback){
- assertJsonEquals([["GET", "$users/misko@hevery.com"]], request);
- callback(200, [{Book:["1"], Library:["2"]}]);
- });
- var users = datastore.userDocumentIdsByEntity("misko@hevery.com");
- assertJsonEquals({Book:["1"], Library:["2"]}, users);
-};
-
-DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){
- expectAsserts(7);
- var log = "";
- var datastore = new DataStore(
- function(request, callback){
- assertJsonEquals([["GET", "User/misko"]], request);
- callback(200, [{$status_code:404}]);
- });
- var User = datastore.entity("User", {admin:false});
- var user = User.loadOrCreate('misko', function(i){log+="cb "+i.$id+";";});
- datastore.flush();
- assertEquals("misko", user.$id);
- assertEquals("User", user.$entity);
- assertEquals(false, user.admin);
- assertEquals("undefined", typeof user.$secret);
- assertEquals("undefined", typeof user.$version);
- assertEquals("cb misko;", log);
-};
-
-DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){
- var log = "";
- var datastore = new DataStore(
- function(request, callback){
- assertJsonEquals([["GET", "User/misko"],["GET", "User/adam"]], request);
- callback(200, [{$id:'misko'},{$id:'adam'}]);
- });
- var User = datastore.entity("User");
- var users = User.loadMany(['misko', 'adam'], function(i){log+="cb "+toJson(i)+";";});
- datastore.flush();
- assertEquals("misko", users[0].$id);
- assertEquals("adam", users[1].$id);
- assertEquals('cb [{"$id":"misko"},{"$id":"adam"}];', log);
-};
-
-DataStoreTest.prototype.testItShouldCreateJoinAndQuery = function() {
- var datastore = new DataStore();
- var Invoice = datastore.entity("Invoice");
- var Customer = datastore.entity("Customer");
- var InvoiceWithCustomer = datastore.join({
- invoice:{join:Invoice},
- customer:{join:Customer, on:"invoice.customer"}
- });
- var invoiceWithCustomer = InvoiceWithCustomer.query("invoice.month", 1);
- assertEquals([], invoiceWithCustomer);
- assertJsonEquals([["GET", "Invoice/month=1"]], datastore.bulkRequest);
- var request = datastore.bulkRequest.shift();
- request.$$callback([{$id:1, customer:1},{$id:2, customer:1},{$id:3, customer:3}]);
- assertJsonEquals([["GET","Customer/1"],["GET","Customer/3"]], datastore.bulkRequest);
- datastore.bulkRequest.shift().$$callback({$id:1});
- datastore.bulkRequest.shift().$$callback({$id:3});
- assertJsonEquals([
- {invoice:{$id:1,customer:1},customer:{$id:1}},
- {invoice:{$id:2,customer:1},customer:{$id:1}},
- {invoice:{$id:3,customer:3},customer:{$id:3}}], invoiceWithCustomer);
-};
-
-DataStoreTest.prototype.testItShouldThrowIfMoreThanOneEntityIsPrimary = function() {
- var datastore = new DataStore();
- var Invoice = datastore.entity("Invoice");
- var Customer = datastore.entity("Customer");
- assertThrows("Exactly one entity needs to be primary.", function(){
- datastore.join({
- invoice:{join:Invoice},
- customer:{join:Customer}
- });
- });
-};
-
-DataStoreTest.prototype.testItShouldThrowIfLoopInReferences = function() {
- var datastore = new DataStore();
- var Invoice = datastore.entity("Invoice");
- var Customer = datastore.entity("Customer");
- assertThrows("Infinite loop in join: invoice -> customer", function(){
- datastore.join({
- invoice:{join:Invoice, on:"customer.invoice"},
- customer:{join:Customer, on:"invoice.customer"}
- });
- });
-};
-
-DataStoreTest.prototype.testItShouldThrowIfReferenceToNonExistantJoin = function() {
- var datastore = new DataStore();
- var Invoice = datastore.entity("Invoice");
- var Customer = datastore.entity("Customer");
- assertThrows("Named entity 'x' is undefined.", function(){
- datastore.join({
- invoice:{join:Invoice, on:"x.invoice"},
- customer:{join:Customer, on:"invoice.customer"}
- });
- });
-};
-
-DataStoreTest.prototype.testItShouldThrowIfQueryOnNonPrimary = function() {
- var datastore = new DataStore();
- var Invoice = datastore.entity("Invoice");
- var Customer = datastore.entity("Customer");
- var InvoiceWithCustomer = datastore.join({
- invoice:{join:Invoice},
- customer:{join:Customer, on:"invoice.customer"}
- });
- assertThrows("Named entity 'customer' is not a primary entity.", function(){
- InvoiceWithCustomer.query("customer.month", 1);
- });
-};
diff --git a/test/moveToAngularCom/EntityDeclarationTest.js b/test/moveToAngularCom/EntityDeclarationTest.js
deleted file mode 100644
index 28986ea8..00000000
--- a/test/moveToAngularCom/EntityDeclarationTest.js
+++ /dev/null
@@ -1,50 +0,0 @@
-EntityDeclarationTest = TestCase('EntityDeclarationTest');
-
-EntityDeclarationTest.prototype.testEntityTypeOnly = function(){
- expectAsserts(2);
- var datastore = {entity:function(name){
- assertEquals("Person", name);
- }};
- var scope = new Scope();
- var init = scope.entity("Person", datastore);
- assertEquals("", init);
-};
-
-EntityDeclarationTest.prototype.testWithDefaults = function(){
- expectAsserts(4);
- var datastore = {entity:function(name, init){
- assertEquals("Person", name);
- assertEquals("=a:", init.a);
- assertEquals(0, init.b.length);
- }};
- var scope = new Scope();
- var init = scope.entity('Person:{a:"=a:", b:[]}', datastore);
- assertEquals("", init);
-};
-
-EntityDeclarationTest.prototype.testWithName = function(){
- expectAsserts(2);
- var datastore = {entity:function(name, init){
- assertEquals("Person", name);
- return function (){ return {}; };
- }};
- var scope = new Scope();
- var init = scope.entity('friend=Person', datastore);
- assertEquals("$anchor.friend:{friend=Person.load($anchor.friend);friend.$$anchor=\"friend\";};", init);
-};
-
-EntityDeclarationTest.prototype.testMultipleEntities = function(){
- expectAsserts(3);
- var expect = ['Person', 'Book'];
- var i=0;
- var datastore = {entity:function(name, init){
- assertEquals(expect[i], name);
- i++;
- return function (){ return {}; };
- }};
- var scope = new Scope();
- var init = scope.entity('friend=Person;book=Book;', datastore);
- assertEquals("$anchor.friend:{friend=Person.load($anchor.friend);friend.$$anchor=\"friend\";};" +
- "$anchor.book:{book=Book.load($anchor.book);book.$$anchor=\"book\";};",
- init);
-};
diff --git a/test/moveToAngularCom/FileControllerTest.js b/test/moveToAngularCom/FileControllerTest.js
deleted file mode 100644
index 75c924e6..00000000
--- a/test/moveToAngularCom/FileControllerTest.js
+++ /dev/null
@@ -1,98 +0,0 @@
-FileControllerTest = TestCase('FileControllerTest');
-
-FileControllerTest.prototype.XtestOnSelectUpdateView = function(){
- var view = jQuery('');
- var swf = {};
- var controller = new FileController(view, null, swf);
- swf.uploadFile = function(path){};
- controller.select('A', 9, '9 bytes');
- assertEquals(view.find('a').text(), "A");
- assertEquals(view.find('span').text(), "9 bytes");
-};
-
-FileControllerTest.prototype.XtestUpdateModelView = function(){
- var view = FileController.template('');
- var input = $('');
- var controller;
- var scope = new Scope({value:{}, $binder:{updateView:function(){
- controller.updateView(scope);
- }}});
- view.data('scope', scope);
- controller = new FileController(view, 'value.input', null, "http://server_base");
- var value = '{"text":"A", "size":123, "id":"890"}';
- controller.uploadCompleteData(value);
- controller.updateView(scope);
- assertEquals(scope.get('value.input.text'), 'A');
- assertEquals(scope.get('value.input.size'), 123);
- assertEquals(scope.get('value.input.id'), '890');
- assertEquals(scope.get('value.input.url'), 'http://server_base/_attachments/890/A');
- assertEquals(view.find('a').text(), "A");
- assertEquals(view.find('a').attr('href'), "http://server_base/_attachments/890/A");
- assertEquals(view.find('span').text(), "123 bytes");
-};
-
-FileControllerTest.prototype.XtestFileUpload = function(){
- expectAsserts(1);
- var swf = {};
- var controller = new FileController(null, null, swf, "http://server_base");
- swf.uploadFile = function(path){
- assertEquals("http://server_base/_attachments", path);
- };
- controller.name = "Name";
- controller.upload();
-};
-
-FileControllerTest.prototype.XtestFileUploadNoFileIsNoop = function(){
- expectAsserts(0);
- var swf = {uploadFile:function(path){
- fail();
- }};
- var controller = new FileController(null, swf);
- controller.upload("basePath", null);
-};
-
-FileControllerTest.prototype.XtestRemoveAttachment = function(){
- var doc = FileController.template();
- var input = $('');
- var scope = new Scope();
- input.data('scope', scope);
- var controller = new FileController(doc, 'file', null, null);
- controller.updateView(scope);
- assertEquals(false, doc.find('input').attr('checked'));
-
- scope.set('file', {url:'url', size:123});
- controller.updateView(scope);
- assertEquals(true, doc.find('input').attr('checked'));
-
- doc.find('input').attr('checked', false);
- controller.updateModel(scope);
- assertNull(scope.get('file'));
-
- doc.find('input').attr('checked', true);
- controller.updateModel(scope);
- assertEquals('url', scope.get('file.url'));
- assertEquals(123, scope.get('file.size'));
-};
-
-FileControllerTest.prototype.XtestShouldEmptyOutOnUndefined = function () {
- var view = FileController.template('hello');
- var controller = new FileController(view, 'abc', null, null);
-
- var scope = new Scope();
- scope.set('abc', {text: 'myname', url: 'myurl', size: 1234});
-
- controller.updateView(scope);
- assertEquals("myurl", view.find('a').attr('href'));
- assertEquals("myname", view.find('a').text());
- assertEquals(true, view.find('input').is(':checked'));
- assertEquals("1.2 KB", view.find('span').text());
-
- scope.set('abc', undefined);
- controller.updateView(scope);
- assertEquals("myurl", view.find('a').attr('href'));
- assertEquals("myname", view.find('a').text());
- assertEquals(false, view.find('input').is(':checked'));
- assertEquals("1.2 KB", view.find('span').text());
-};
-
-
diff --git a/test/moveToAngularCom/MiscTest.js b/test/moveToAngularCom/MiscTest.js
deleted file mode 100644
index aa0e1186..00000000
--- a/test/moveToAngularCom/MiscTest.js
+++ /dev/null
@@ -1,35 +0,0 @@
-BinderTest.prototype.testExpandEntityTagWithName = function(){
- var c = this.compile('');
- assertEquals(
- '',
- sortedHtml(c.node));
- assertEquals("Person", c.scope.$get("friend.$entity"));
- assertEquals("friend", c.scope.$get("friend.$$anchor"));
-};
-
-BinderTest.prototype.testExpandSubmitButtonToAction = function(){
- var html = this.compileToHtml('');
- assertTrue(html, html.indexOf('ng-action="$save()"') > 0 );
- assertTrue(html, html.indexOf('ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 );
-};
-
-BinderTest.prototype.testReplaceFileUploadWithSwf = function(){
- expectAsserts(1);
- var form = jQuery("body").append('');
- form.data('scope', new Scope());
- var factory = {};
- var binder = new Binder(form.get(0), factory, new MockLocation());
- factory.createController = function(node){
- assertEquals(node.attr('type'), 'file');
- return {updateModel:function(){}};
- };
- binder.compile();
- jQuery("#testTag").remove();
-};
-
-BinderTest.prototype.testExpandEntityTagWithDefaults = function(){
- assertEquals(
- '',
- this.compileToHtml(''));
-};
-
diff --git a/test/moveToAngularCom/ModelTest.js b/test/moveToAngularCom/ModelTest.js
deleted file mode 100644
index dbd97778..00000000
--- a/test/moveToAngularCom/ModelTest.js
+++ /dev/null
@@ -1,84 +0,0 @@
-ModelTest = TestCase('ModelTest');
-
-ModelTest.prototype.testLoadSaveOperations = function(){
- var m1 = new DataStore().entity('A')();
- m1.a = 1;
-
- var m2 = {b:1};
-
- m1.$loadFrom(m2);
-
- assertTrue(!m1.a);
- assertEquals(m1.b, 1);
-};
-
-ModelTest.prototype.testLoadfromDoesNotClobberFunctions = function(){
- var m1 = new DataStore().entity('A')();
- m1.id = function(){return 'OK';};
- m1.$loadFrom({id:null});
- assertEquals(m1.id(), 'OK');
-
- m1.b = 'OK';
- m1.$loadFrom({b:function(){}});
- assertEquals(m1.b, 'OK');
-};
-
-ModelTest.prototype.testDataStoreDoesNotGetClobbered = function(){
- var ds = new DataStore();
- var m = ds.entity('A')();
- assertTrue(m.$$entity.datastore === ds);
- m.$loadFrom({});
- assertTrue(m.$$entity.datastore === ds);
-};
-
-ModelTest.prototype.testManagedModelDelegatesMethodsToDataStore = function(){
- expectAsserts(7);
- var datastore = new DataStore();
- var model = datastore.entity("A", {a:1})();
- var fn = {};
- datastore.save = function(instance, callback) {
- assertTrue(model === instance);
- assertTrue(callback === fn);
- };
- datastore.remove = function(instance, callback) {
- assertTrue(model === instance);
- assertTrue(callback === fn);
- };
- datastore.load = function(instance, id, callback) {
- assertTrue(model === instance);
- assertTrue(id === "123");
- assertTrue(callback === fn);
- };
- model.$save(fn);
- model.$delete(fn);
- model.$loadById("123", fn);
-};
-
-ModelTest.prototype.testManagedModelCanBeForcedToFlush = function(){
- expectAsserts(6);
- var datastore = new DataStore();
- var model = datastore.entity("A", {a:1})();
-
- datastore.save = function(instance, callback) {
- assertTrue(model === instance);
- assertTrue(callback === undefined);
- };
- datastore.remove = function(instance, callback) {
- assertTrue(model === instance);
- assertTrue(callback === undefined);
- };
- datastore.flush = function(){
- assertTrue(true);
- };
- model.$save(true);
- model.$delete(true);
-};
-
-
-ModelTest.prototype.testItShouldMakeDeepCopyOfInitialValues = function (){
- var initial = {a:[]};
- var entity = new DataStore().entity("A", initial);
- var model = entity();
- model.a.push(1);
- assertEquals(0, entity().a.length);
-};
diff --git a/test/moveToAngularCom/ServerTest.js b/test/moveToAngularCom/ServerTest.js
deleted file mode 100644
index 02fab84c..00000000
--- a/test/moveToAngularCom/ServerTest.js
+++ /dev/null
@@ -1,42 +0,0 @@
-ServerTest = TestCase("ServerTest");
-ServerTest.prototype.testBreakLargeRequestIntoPackets = function() {
- var log = "";
- var server = new Server("http://server", function(url){
- log += "|" + url;
- });
- server.maxSize = 30;
- server.uuid = "uuid";
- server.request("POST", "/data/database", {}, function(code, r){
- assertEquals(200, code);
- assertEquals("response", r);
- });
- angularCallbacks.uuid0("response");
- assertEquals(
- "|http://server/$/uuid0/2/1?h=eyJtIjoiUE9TVCIsInAiOnt9LCJ1Ij" +
- "|http://server/$/uuid0/2/2?h=oiL2RhdGEvZGF0YWJhc2UifQ==",
- log);
-};
-
-ServerTest.prototype.testItShouldEncodeUsingUrlRules = function() {
- var server = new Server("http://server");
- assertEquals("fn5-fn5-", server.base64url("~~~~~~"));
- assertEquals("fn5_fn5_", server.base64url("~~\u007f~~\u007f"));
-};
-
-FrameServerTest = TestCase("FrameServerTest");
-
-FrameServerTest.prototype = {
- testRead:function(){
- var window = {name:'$DATASET:"MyData"'};
- var server = new FrameServer(window);
- server.read();
- assertEquals("MyData", server.data);
- },
- testWrite:function(){
- var window = {};
- var server = new FrameServer(window);
- server.data = "TestData";
- server.write();
- assertEquals('$DATASET:"TestData"', window.name);
- }
-};
diff --git a/test/moveToAngularCom/UsersTest.js b/test/moveToAngularCom/UsersTest.js
deleted file mode 100644
index f0ff545a..00000000
--- a/test/moveToAngularCom/UsersTest.js
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright (C) 2008,2009 BRAT Tech LLC
-
-UsersTest = TestCase("UsersTest");
-
-UsersTest.prototype = {
- setUp:function(){},
-
- tearDown:function(){},
-
- testItShouldFetchCurrentUser:function(){
- expectAsserts(5);
- var user;
- var users = new Users({request:function(method, url, request, callback){
- assertEquals("GET", method);
- assertEquals("/account.json", url);
- assertEquals("{}", toJson(request));
- callback(200, {$status_code:200, user:{name:'misko'}});
- }});
- users.fetchCurrentUser(function(u){
- user = u;
- assertEquals("misko", u.name);
- assertEquals("misko", users.current.name);
- });
- }
-
-};
--
cgit v1.2.3