3 describe('crmUtil', function() {
5 beforeEach(function() {
9 describe('crmMetadata', function() {
10 var crmMetadata
, $q
, $rootScope
, crmApi
;
12 beforeEach(inject(function(_crmMetadata_
, _
$rootScope_
, _
$q_
, _crmApi_
) {
13 crmMetadata
= _crmMetadata_
;
14 $rootScope
= _
$rootScope_
;
19 it('returns a failed promise on error', function(done
) {
20 var apiSpy
= jasmine
.createSpy('crmApi');
21 crmApi
.backend
= apiSpy
.and
.returnValue(crmApi
.val({
24 expect(apiSpy
.calls
.count()).toBe(0);
25 $q
.when(crmMetadata
.getFields('MyEntity')).then(
27 expect(false).toEqual(true);
31 expect(apiSpy
.calls
.count()).toBe(1);
39 it('only calls the API once', function(done
) {
40 var apiSpy
= jasmine
.createSpy('crmApi');
41 crmApi
.backend
= apiSpy
.and
.returnValue(crmApi
.val({
52 expect(apiSpy
.calls
.count()).toBe(0);
53 $q
.when(crmMetadata
.getFields('MyEntity')).then(
55 expect(fields
.id
.title
).toBe('My entity ID');
56 expect(apiSpy
.calls
.count()).toBe(1);
58 // call a second time, but now the data is cached
59 $q
.when(crmMetadata
.getFields('MyEntity')).then(
61 expect(fields
.id
.title
).toBe('My entity ID');
62 expect(apiSpy
.calls
.count()).toBe(1);
64 // call a third time using a diff interface; data is still cached!
65 $q
.when(crmMetadata
.getField('MyEntity', 'id')).then(
67 expect(field
.title
).toBe('My entity ID');
68 expect(apiSpy
.calls
.count()).toBe(1);
80 it('returns individual fields', function(done
) {
81 var apiSpy
= jasmine
.createSpy('crmApi');
82 crmApi
.backend
= apiSpy
.and
.returnValue(crmApi
.val({
93 expect(apiSpy
.calls
.count()).toBe(0);
94 $q
.when(crmMetadata
.getField('MyEntity', 'id')).then(
96 expect(field
.title
).toBe('My entity ID');
97 expect(apiSpy
.calls
.count()).toBe(1);