From c639fc2143bea9fbd0627cf9be2c4ea75317ecce Mon Sep 17 00:00:00 2001 From: Tim Otten <totten@civicrm.org> Date: Sat, 21 Dec 2013 21:07:48 -0600 Subject: [PATCH] HR-226 - CRM.Backbone.extendCollection - Unit test for "crmCriteriaModel" --- tests/qunit/crm-backbone/test.js | 51 +++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/tests/qunit/crm-backbone/test.js b/tests/qunit/crm-backbone/test.js index b9c47917b4..cdf242f763 100644 --- a/tests/qunit/crm-backbone/test.js +++ b/tests/qunit/crm-backbone/test.js @@ -195,7 +195,7 @@ asyncTest("update (error)", function() { module('collection - read'); -asyncTest("fetch by contact_type (1+ results)", function() { +asyncTest("fetch by contact_type (passive criteria, 1+ results)", function() { var c = new ContactCollection([], { crmCriteria: { contact_type: 'Organization' @@ -214,6 +214,55 @@ asyncTest("fetch by contact_type (1+ results)", function() { }); }); +asyncTest("fetch by contact_type (active criteria, 1+ results)", function() { + var criteria = new Backbone.Model({ + contact_type: 'Organization' + }); + var c = new ContactCollection([], { + crmCriteriaModel: criteria + }); + c.fetch({ + error: onUnexpectedError, + success: function() { + ok(c.models.length > 0, "Expected at least one contact"); + c.each(function(model) { + equal(model.get('contact_type'), 'Organization', 'Expected contact with type organization'); + ok(model.get('display_name') != '', 'Expected contact with valid name'); + }); + start(); + } + }); +}); + +asyncTest("fetch by contact_type (active criteria revision, 1+ results)", function() { + var criteria = new Backbone.Model({ + contact_type: 'Household' + }); + var c = new ContactCollection([], { + crmCriteriaModel: criteria + }); + c.fetch({ + error: onUnexpectedError, + success: function() { + ok(c.models.length > 0, "Expected at least one contact"); + c.each(function(model) { + equal(model.get('contact_type'), 'Household', 'Expected contact with type household'); + ok(model.get('display_name') != '', 'Expected contact with valid name'); + }); + + criteria.set('contact_type', 'Organization'); + _.delay(function() { + ok(c.models.length > 0, "Expected at least one contact"); + c.each(function(model) { + equal(model.get('contact_type'), 'Organization', 'Expected contact with type organization'); + ok(model.get('display_name') != '', 'Expected contact with valid name'); + }); + start(); + }, 1000); + } + }); +}); + asyncTest("fetch by crazy name (0 results)", function() { var c = new ContactCollection([], { crmCriteria: { -- GitLab