Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
386edd12
Commit
386edd12
authored
Sep 14, 2016
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for reducer utility functions
parent
2c70aeba
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
0 deletions
+87
-0
util-test.js
h/static/scripts/reducers/test/util-test.js
+87
-0
No files found.
h/static/scripts/reducers/test/util-test.js
0 → 100644
View file @
386edd12
'use strict'
;
var
util
=
require
(
'../util'
);
var
fixtures
=
{
update
:
{
ADD_ANNOTATIONS
:
function
(
state
,
action
)
{
if
(
!
state
.
annotations
)
{
return
{
annotations
:
action
.
annotations
};
}
return
{
annotations
:
state
.
annotations
.
concat
(
action
.
annotations
)};
},
SELECT_TAB
:
function
(
state
,
action
)
{
return
{
tab
:
action
.
tab
};
},
},
countAnnotations
:
function
(
state
)
{
return
state
.
annotations
.
length
;
},
};
describe
(
'reducer utils'
,
function
()
{
describe
(
'#actionTypes'
,
function
()
{
it
(
'returns an object with values equal to keys'
,
function
()
{
assert
.
deepEqual
(
util
.
actionTypes
({
SOME_ACTION
:
sinon
.
stub
(),
ANOTHER_ACTION
:
sinon
.
stub
(),
}),
{
SOME_ACTION
:
'SOME_ACTION'
,
ANOTHER_ACTION
:
'ANOTHER_ACTION'
,
});
});
});
describe
(
'#createReducer'
,
function
()
{
it
(
'returns a reducer that combines each update function from the input object'
,
function
()
{
var
reducer
=
util
.
createReducer
(
fixtures
.
update
);
var
newState
=
reducer
({},
{
type
:
'ADD_ANNOTATIONS'
,
annotations
:
[{
id
:
1
}],
});
assert
.
deepEqual
(
newState
,
{
annotations
:
[{
id
:
1
}],
});
});
it
(
'returns a new object if the action was handled'
,
function
()
{
var
reducer
=
util
.
createReducer
(
fixtures
.
update
);
var
originalState
=
{
someFlag
:
false
};
assert
.
notEqual
(
reducer
(
originalState
,
{
type
:
'SELECT_TAB'
,
tab
:
'notes'
}),
originalState
);
});
it
(
'returns the original object if the action was not handled'
,
function
()
{
var
reducer
=
util
.
createReducer
(
fixtures
.
update
);
var
originalState
=
{
someFlag
:
false
};
assert
.
equal
(
reducer
(
originalState
,
{
type
:
'UNKNOWN_ACTION'
}),
originalState
);
});
it
(
'preserves state not modified by the update function'
,
function
()
{
var
reducer
=
util
.
createReducer
(
fixtures
.
update
);
var
newState
=
reducer
({
otherFlag
:
false
},
{
type
:
'ADD_ANNOTATIONS'
,
annotations
:
[{
id
:
1
}],
});
assert
.
deepEqual
(
newState
,
{
otherFlag
:
false
,
annotations
:
[{
id
:
1
}],
});
});
});
describe
(
'#bindSelectors'
,
function
()
{
it
(
'bound functions call original functions with current value of getState()'
,
function
()
{
var
annotations
=
[{
id
:
1
}];
var
getState
=
sinon
.
stub
().
returns
({
annotations
:
annotations
});
var
bound
=
util
.
bindSelectors
({
countAnnotations
:
fixtures
.
countAnnotations
,
},
getState
);
assert
.
equal
(
bound
.
countAnnotations
(),
1
);
getState
.
returns
({
annotations
:
annotations
.
concat
([{
id
:
2
}])});
assert
.
equal
(
bound
.
countAnnotations
(),
2
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment