Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
solr-frontend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
49158a45
authored
2016-02-09 12:07:11 -0600
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Util now has a spec.
1 parent
b3e51cf0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
1 deletions
src/scripts/solr/model/Util.js
src/scripts/solr/model/Util.spec.js
src/scripts/solr/model/Util.js
View file @
49158a4
...
...
@@ -5,7 +5,7 @@ define(function(require) {
var
result
=
filterFunc
(
obj
);
var
ptr
=
startPtr
;
while
(
true
)
{
result
=
_
.
extend
(
result
,
filterFunc
(
_
.
result
(
ptr
,
fieldName
)));
result
=
_
.
defaults
(
result
,
filterFunc
(
_
.
result
(
ptr
,
fieldName
)));
if
(
ptr
===
endPtr
)
{
break
;
}
...
...
src/scripts/solr/model/Util.spec.js
0 → 100644
View file @
49158a4
define
(
function
(
require
)
{
'use strict'
;
var
_
=
require
(
'underscore'
);
var
Backbone
=
require
(
'backbone'
);
var
Util
=
require
(
'solr/model/Util'
);
var
BaseModel
=
Backbone
.
Model
.
extend
({},
{
staticProps
:
function
()
{
return
{
hardCoded
:
74
,
override
:
75
,
};
},
staticSets
:
[
'hardCoded'
,
'override'
],
});
var
SubModel
=
BaseModel
.
extend
({},
{
staticProps
:
{
override
:
76
,
newConstant
:
77
,
},
staticSets
:
function
()
{
return
[
'override'
,
'newConstant'
];
},
});
describe
(
'Util'
,
function
()
{
it
(
'loads'
,
function
()
{
expect
(
Util
).
toBeDefined
();
});
it
(
'exported items'
,
function
()
{
var
keys
=
{};
_
.
each
(
Util
,
function
(
value
,
key
)
{
keys
[
key
]
=
true
;
});
expect
(
keys
).
toEqual
({
getField
:
true
,
setField
:
true
,
getItemKeyAccessor
:
true
,
mergeStaticProps
:
true
,
mergeStaticSets
:
true
,
});
});
describe
(
'methods'
,
function
()
{
var
pojo
,
bb
,
emptyBB
;
beforeEach
(
function
()
{
pojo
=
{
a
:
1
,
b
:
2
,
key
:
'TheKey'
};
bb
=
new
BaseModel
(
pojo
);
emptyBB
=
new
SubModel
();
});
it
(
'setField only modifies given'
,
function
()
{
var
r
=
Util
.
setField
(
pojo
,
'a'
,
100
);
expect
(
pojo
).
toEqual
({
a
:
100
,
b
:
2
,
key
:
'TheKey'
});
expect
(
r
).
toBe
(
100
);
});
it
(
'setField adds new'
,
function
()
{
var
r
=
Util
.
setField
(
pojo
,
'c'
,
42
);
expect
(
pojo
).
toEqual
({
a
:
1
,
b
:
2
,
c
:
42
,
key
:
'TheKey'
});
expect
(
r
).
toBe
(
42
);
});
it
(
'getField returns value'
,
function
()
{
var
r
=
Util
.
getField
(
pojo
,
'b'
);
expect
(
pojo
).
toEqual
({
a
:
1
,
b
:
2
,
key
:
'TheKey'
});
expect
(
r
).
toBe
(
2
);
});
it
(
'getField returns undefined'
,
function
()
{
var
r
=
Util
.
getField
(
pojo
,
'c'
);
expect
(
pojo
).
toEqual
({
a
:
1
,
b
:
2
,
key
:
'TheKey'
});
expect
(
r
).
toBe
(
undefined
);
});
it
(
'itemKeyAccessor returns value'
,
function
()
{
var
r
=
Util
.
getItemKeyAccessor
(
bb
);
expect
(
r
).
toBe
(
'TheKey'
);
});
it
(
'itemKeyAccessor returns undefined'
,
function
()
{
var
r
=
Util
.
getItemKeyAccessor
(
emptyBB
);
expect
(
r
).
toBe
(
undefined
);
});
it
(
'mergeStaticProps'
,
function
()
{
var
r
=
Util
.
mergeStaticProps
(
SubModel
,
Backbone
.
Model
,
{
'default'
:
1
},
'staticProps'
);
expect
(
r
).
toEqual
({
default
:
1
,
hardCoded
:
74
,
override
:
76
,
newConstant
:
77
});
});
it
(
'mergeStaticSets'
,
function
()
{
var
r
=
Util
.
mergeStaticSets
(
SubModel
,
Backbone
.
Model
,
[
'default'
],
'staticSets'
);
var
keys
=
{};
_
.
each
(
r
,
function
(
value
)
{
keys
[
value
]
=
true
;
});
expect
(
keys
).
toEqual
({
default
:
true
,
hardCoded
:
true
,
override
:
true
,
newConstant
:
true
});
});
});
});
});
Please
register
or
sign in
to post a comment