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
cbb1d56d
Commit
cbb1d56d
authored
Dec 03, 2015
by
Sean Hammond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove global variable from tests
Remove gloval `controller` variable from AnnotationController tests.
parent
f7faa1c2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
40 deletions
+69
-40
annotation-test.js
h/static/scripts/directive/test/annotation-test.js
+69
-40
No files found.
h/static/scripts/directive/test/annotation-test.js
View file @
cbb1d56d
...
@@ -289,7 +289,6 @@ describe('annotation.js', function() {
...
@@ -289,7 +289,6 @@ describe('annotation.js', function() {
var
$timeout
;
var
$timeout
;
var
$window
;
var
$window
;
var
annotation
;
var
annotation
;
var
controller
;
var
createDirective
;
var
createDirective
;
var
fakeAnnotationMapper
;
var
fakeAnnotationMapper
;
var
fakeAnnotationUI
;
var
fakeAnnotationUI
;
...
@@ -314,8 +313,9 @@ describe('annotation.js', function() {
...
@@ -314,8 +313,9 @@ describe('annotation.js', function() {
$element
=
angular
.
element
(
'<div annotation="annotation">'
);
$element
=
angular
.
element
(
'<div annotation="annotation">'
);
$compile
(
$element
)(
$scope
);
$compile
(
$element
)(
$scope
);
$scope
.
$digest
();
$scope
.
$digest
();
controller
=
$element
.
controller
(
'annotation'
);
var
controller
=
$element
.
controller
(
'annotation'
);
isolateScope
=
$element
.
isolateScope
();
isolateScope
=
$element
.
isolateScope
();
return
controller
;
};
};
before
(
function
()
{
before
(
function
()
{
...
@@ -459,16 +459,19 @@ describe('annotation.js', function() {
...
@@ -459,16 +459,19 @@ describe('annotation.js', function() {
describe
(
'AnnotationController.editing()'
,
function
()
{
describe
(
'AnnotationController.editing()'
,
function
()
{
it
(
'returns true if action is "create"'
,
function
()
{
it
(
'returns true if action is "create"'
,
function
()
{
var
controller
=
createDirective
();
controller
.
action
=
'create'
;
controller
.
action
=
'create'
;
assert
(
controller
.
editing
());
assert
(
controller
.
editing
());
});
});
it
(
'returns true if action is "edit"'
,
function
()
{
it
(
'returns true if action is "edit"'
,
function
()
{
var
controller
=
createDirective
();
controller
.
action
=
'edit'
;
controller
.
action
=
'edit'
;
assert
(
controller
.
editing
());
assert
(
controller
.
editing
());
});
});
it
(
'returns false if action is "view"'
,
function
()
{
it
(
'returns false if action is "view"'
,
function
()
{
var
controller
=
createDirective
();
controller
.
action
=
'view'
;
controller
.
action
=
'view'
;
assert
(
!
controller
.
editing
());
assert
(
!
controller
.
editing
());
});
});
...
@@ -509,7 +512,6 @@ describe('annotation.js', function() {
...
@@ -509,7 +512,6 @@ describe('annotation.js', function() {
describe
(
'#reply'
,
function
()
{
describe
(
'#reply'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
createDirective
();
annotation
.
permissions
=
{
annotation
.
permissions
=
{
read
:
[
'acct:joe@localhost'
],
read
:
[
'acct:joe@localhost'
],
update
:
[
'acct:joe@localhost'
],
update
:
[
'acct:joe@localhost'
],
...
@@ -519,6 +521,7 @@ describe('annotation.js', function() {
...
@@ -519,6 +521,7 @@ describe('annotation.js', function() {
});
});
it
(
'creates a new reply with the proper uri and references'
,
function
()
{
it
(
'creates a new reply with the proper uri and references'
,
function
()
{
var
controller
=
createDirective
();
controller
.
reply
();
controller
.
reply
();
var
match
=
sinon
.
match
({
var
match
=
sinon
.
match
({
references
:
[
annotation
.
id
],
references
:
[
annotation
.
id
],
...
@@ -528,6 +531,7 @@ describe('annotation.js', function() {
...
@@ -528,6 +531,7 @@ describe('annotation.js', function() {
});
});
it
(
'makes the annotation shared if the parent is shared'
,
function
()
{
it
(
'makes the annotation shared if the parent is shared'
,
function
()
{
var
controller
=
createDirective
();
var
reply
=
{};
var
reply
=
{};
fakeAnnotationMapper
.
createAnnotation
.
returns
(
reply
);
fakeAnnotationMapper
.
createAnnotation
.
returns
(
reply
);
fakePermissions
.
isShared
.
returns
(
true
);
fakePermissions
.
isShared
.
returns
(
true
);
...
@@ -538,6 +542,7 @@ describe('annotation.js', function() {
...
@@ -538,6 +542,7 @@ describe('annotation.js', function() {
});
});
it
(
'makes the annotation shared if the parent is shared'
,
function
()
{
it
(
'makes the annotation shared if the parent is shared'
,
function
()
{
var
controller
=
createDirective
();
$scope
.
annotation
.
group
=
'my group'
;
$scope
.
annotation
.
group
=
'my group'
;
$scope
.
annotation
.
permissions
=
{
$scope
.
annotation
.
permissions
=
{
read
:
[
'my group'
]
read
:
[
'my group'
]
...
@@ -559,6 +564,7 @@ describe('annotation.js', function() {
...
@@ -559,6 +564,7 @@ describe('annotation.js', function() {
it
(
it
(
'does not add the world readable principal if the parent is private'
,
'does not add the world readable principal if the parent is private'
,
function
()
{
function
()
{
var
controller
=
createDirective
();
var
reply
=
{};
var
reply
=
{};
fakeAnnotationMapper
.
createAnnotation
.
returns
(
reply
);
fakeAnnotationMapper
.
createAnnotation
.
returns
(
reply
);
fakePermissions
.
isShared
.
returns
(
false
);
fakePermissions
.
isShared
.
returns
(
false
);
...
@@ -570,6 +576,7 @@ describe('annotation.js', function() {
...
@@ -570,6 +576,7 @@ describe('annotation.js', function() {
);
);
it
(
'sets the reply
\'
s group to be the same as its parent
\'
s'
,
function
()
{
it
(
'sets the reply
\'
s group to be the same as its parent
\'
s'
,
function
()
{
var
controller
=
createDirective
();
$scope
.
annotation
.
group
=
'my group'
;
$scope
.
annotation
.
group
=
'my group'
;
var
reply
=
{};
var
reply
=
{};
fakeAnnotationMapper
.
createAnnotation
.
returns
(
reply
);
fakeAnnotationMapper
.
createAnnotation
.
returns
(
reply
);
...
@@ -579,11 +586,8 @@ describe('annotation.js', function() {
...
@@ -579,11 +586,8 @@ describe('annotation.js', function() {
});
});
describe
(
'#setPrivacy'
,
function
()
{
describe
(
'#setPrivacy'
,
function
()
{
beforeEach
(
function
()
{
createDirective
();
});
it
(
'makes the annotation private when level is "private"'
,
function
()
{
it
(
'makes the annotation private when level is "private"'
,
function
()
{
var
controller
=
createDirective
();
annotation
.
$update
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
annotation
.
$update
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
controller
.
edit
();
controller
.
edit
();
controller
.
setPrivacy
(
'private'
);
controller
.
setPrivacy
(
'private'
);
...
@@ -597,6 +601,7 @@ describe('annotation.js', function() {
...
@@ -597,6 +601,7 @@ describe('annotation.js', function() {
});
});
it
(
'makes the annotation shared when level is "shared"'
,
function
()
{
it
(
'makes the annotation shared when level is "shared"'
,
function
()
{
var
controller
=
createDirective
();
annotation
.
$update
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
annotation
.
$update
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
controller
.
edit
();
controller
.
edit
();
controller
.
setPrivacy
(
'shared'
);
controller
.
setPrivacy
(
'shared'
);
...
@@ -608,6 +613,7 @@ describe('annotation.js', function() {
...
@@ -608,6 +613,7 @@ describe('annotation.js', function() {
});
});
it
(
'saves the "shared" visibility level to localStorage'
,
function
()
{
it
(
'saves the "shared" visibility level to localStorage'
,
function
()
{
var
controller
=
createDirective
();
annotation
.
$update
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
annotation
.
$update
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
controller
.
edit
();
controller
.
edit
();
controller
.
setPrivacy
(
'shared'
);
controller
.
setPrivacy
(
'shared'
);
...
@@ -617,6 +623,7 @@ describe('annotation.js', function() {
...
@@ -617,6 +623,7 @@ describe('annotation.js', function() {
});
});
it
(
'saves the "private" visibility level to localStorage'
,
function
()
{
it
(
'saves the "private" visibility level to localStorage'
,
function
()
{
var
controller
=
createDirective
();
annotation
.
$update
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
annotation
.
$update
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
controller
.
edit
();
controller
.
edit
();
controller
.
setPrivacy
(
'private'
);
controller
.
setPrivacy
(
'private'
);
...
@@ -626,6 +633,7 @@ describe('annotation.js', function() {
...
@@ -626,6 +633,7 @@ describe('annotation.js', function() {
});
});
it
(
'doesn
\'
t save the visibility if the annotation is a reply'
,
function
()
{
it
(
'doesn
\'
t save the visibility if the annotation is a reply'
,
function
()
{
var
controller
=
createDirective
();
annotation
.
$update
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
annotation
.
$update
=
sinon
.
stub
().
returns
(
Promise
.
resolve
());
annotation
.
references
=
[
'parent id'
];
annotation
.
references
=
[
'parent id'
];
controller
.
edit
();
controller
.
edit
();
...
@@ -637,17 +645,15 @@ describe('annotation.js', function() {
...
@@ -637,17 +645,15 @@ describe('annotation.js', function() {
});
});
describe
(
'#hasContent'
,
function
()
{
describe
(
'#hasContent'
,
function
()
{
beforeEach
(
function
()
{
createDirective
();
});
it
(
'returns false if the annotation has no tags or text'
,
function
()
{
it
(
'returns false if the annotation has no tags or text'
,
function
()
{
var
controller
=
createDirective
();
controller
.
annotation
.
text
=
''
;
controller
.
annotation
.
text
=
''
;
controller
.
annotation
.
tags
=
[];
controller
.
annotation
.
tags
=
[];
assert
.
ok
(
!
controller
.
hasContent
());
assert
.
ok
(
!
controller
.
hasContent
());
});
});
it
(
'returns true if the annotation has tags or text'
,
function
()
{
it
(
'returns true if the annotation has tags or text'
,
function
()
{
var
controller
=
createDirective
();
controller
.
annotation
.
text
=
'bar'
;
controller
.
annotation
.
text
=
'bar'
;
assert
.
ok
(
controller
.
hasContent
());
assert
.
ok
(
controller
.
hasContent
());
controller
.
annotation
.
text
=
''
;
controller
.
annotation
.
text
=
''
;
...
@@ -661,16 +667,14 @@ describe('annotation.js', function() {
...
@@ -661,16 +667,14 @@ describe('annotation.js', function() {
});
});
describe
(
'#hasQuotes'
,
function
()
{
describe
(
'#hasQuotes'
,
function
()
{
beforeEach
(
function
()
{
createDirective
();
});
it
(
'returns false if the annotation has no quotes'
,
function
()
{
it
(
'returns false if the annotation has no quotes'
,
function
()
{
var
controller
=
createDirective
();
controller
.
annotation
.
target
=
[{}];
controller
.
annotation
.
target
=
[{}];
assert
.
isFalse
(
controller
.
hasQuotes
());
assert
.
isFalse
(
controller
.
hasQuotes
());
});
});
it
(
'returns true if the annotation has quotes'
,
function
()
{
it
(
'returns true if the annotation has quotes'
,
function
()
{
var
controller
=
createDirective
();
controller
.
annotation
.
target
=
[
controller
.
annotation
.
target
=
[
{
{
selector
:
[
selector
:
[
...
@@ -685,16 +689,13 @@ describe('annotation.js', function() {
...
@@ -685,16 +689,13 @@ describe('annotation.js', function() {
});
});
describe
(
'#render'
,
function
()
{
describe
(
'#render'
,
function
()
{
beforeEach
(
function
()
{
createDirective
();
sandbox
.
spy
(
controller
,
'render'
);
});
afterEach
(
function
()
{
afterEach
(
function
()
{
sandbox
.
restore
();
sandbox
.
restore
();
});
});
it
(
'is called exactly once on model changes'
,
function
()
{
it
(
'is called exactly once on model changes'
,
function
()
{
var
controller
=
createDirective
();
sandbox
.
spy
(
controller
,
'render'
);
assert
.
notCalled
(
controller
.
render
);
assert
.
notCalled
(
controller
.
render
);
annotation
[
'delete'
]
=
true
;
annotation
[
'delete'
]
=
true
;
$scope
.
$digest
();
$scope
.
$digest
();
...
@@ -705,17 +706,20 @@ describe('annotation.js', function() {
...
@@ -705,17 +706,20 @@ describe('annotation.js', function() {
});
});
it
(
'provides a document title'
,
function
()
{
it
(
'provides a document title'
,
function
()
{
var
controller
=
createDirective
();
controller
.
render
();
controller
.
render
();
assert
.
equal
(
controller
.
document
.
title
,
'A special document'
);
assert
.
equal
(
controller
.
document
.
title
,
'A special document'
);
});
});
it
(
'uses the first title when there are more than one'
,
function
()
{
it
(
'uses the first title when there are more than one'
,
function
()
{
var
controller
=
createDirective
();
annotation
.
document
.
title
=
[
'first title'
,
'second title'
];
annotation
.
document
.
title
=
[
'first title'
,
'second title'
];
controller
.
render
();
controller
.
render
();
assert
.
equal
(
controller
.
document
.
title
,
'first title'
);
assert
.
equal
(
controller
.
document
.
title
,
'first title'
);
});
});
it
(
'truncates long titles'
,
function
()
{
it
(
'truncates long titles'
,
function
()
{
var
controller
=
createDirective
();
annotation
.
document
.
title
=
'A very very very long title that really
\
nshouldn
\'
t be found on a page on the internet.'
;
annotation
.
document
.
title
=
'A very very very long title that really
\
nshouldn
\'
t be found on a page on the internet.'
;
controller
.
render
();
controller
.
render
();
assert
.
equal
(
assert
.
equal
(
...
@@ -723,16 +727,19 @@ describe('annotation.js', function() {
...
@@ -723,16 +727,19 @@ describe('annotation.js', function() {
});
});
it
(
'provides a document uri'
,
function
()
{
it
(
'provides a document uri'
,
function
()
{
var
controller
=
createDirective
();
controller
.
render
();
controller
.
render
();
assert
.
equal
(
controller
.
document
.
uri
,
'http://example.com'
);
assert
.
equal
(
controller
.
document
.
uri
,
'http://example.com'
);
});
});
it
(
'provides an extracted domain from the uri'
,
function
()
{
it
(
'provides an extracted domain from the uri'
,
function
()
{
var
controller
=
createDirective
();
controller
.
render
();
controller
.
render
();
assert
.
equal
(
controller
.
document
.
domain
,
'example.com'
);
assert
.
equal
(
controller
.
document
.
domain
,
'example.com'
);
});
});
it
(
'uses the domain for the title if the title is not present'
,
function
()
{
it
(
'uses the domain for the title if the title is not present'
,
function
()
{
var
controller
=
createDirective
();
delete
annotation
.
document
.
title
;
delete
annotation
.
document
.
title
;
controller
.
render
();
controller
.
render
();
assert
.
equal
(
controller
.
document
.
title
,
'example.com'
);
assert
.
equal
(
controller
.
document
.
title
,
'example.com'
);
...
@@ -741,6 +748,7 @@ describe('annotation.js', function() {
...
@@ -741,6 +748,7 @@ describe('annotation.js', function() {
it
(
it
(
'still sets the uri correctly if the annotation has no document'
,
'still sets the uri correctly if the annotation has no document'
,
function
()
{
function
()
{
var
controller
=
createDirective
();
delete
annotation
.
document
;
delete
annotation
.
document
;
controller
.
render
();
controller
.
render
();
assert
(
controller
.
document
.
uri
===
$scope
.
annotation
.
uri
);
assert
(
controller
.
document
.
uri
===
$scope
.
annotation
.
uri
);
...
@@ -750,6 +758,7 @@ describe('annotation.js', function() {
...
@@ -750,6 +758,7 @@ describe('annotation.js', function() {
it
(
it
(
'still sets the domain correctly if the annotation has no document'
,
'still sets the domain correctly if the annotation has no document'
,
function
()
{
function
()
{
var
controller
=
createDirective
();
delete
annotation
.
document
;
delete
annotation
.
document
;
controller
.
render
();
controller
.
render
();
assert
(
controller
.
document
.
domain
===
'example.com'
);
assert
(
controller
.
document
.
domain
===
'example.com'
);
...
@@ -759,6 +768,7 @@ describe('annotation.js', function() {
...
@@ -759,6 +768,7 @@ describe('annotation.js', function() {
it
(
it
(
'uses the domain for the title when the annotation has no document'
,
'uses the domain for the title when the annotation has no document'
,
function
()
{
function
()
{
var
controller
=
createDirective
();
delete
annotation
.
document
;
delete
annotation
.
document
;
controller
.
render
();
controller
.
render
();
assert
(
controller
.
document
.
title
===
'example.com'
);
assert
(
controller
.
document
.
title
===
'example.com'
);
...
@@ -779,19 +789,22 @@ describe('annotation.js', function() {
...
@@ -779,19 +789,22 @@ describe('annotation.js', function() {
});
});
it
(
'is not updated for unsaved annotations'
,
function
()
{
it
(
'is not updated for unsaved annotations'
,
function
()
{
annotation
.
updated
=
null
;
var
controller
=
createDirective
();
// Unsaved annotations don't have an updated time yet so a timestamp
// Unsaved annotations don't have an updated time yet so a timestamp
// string can't be computed for them.
// string can't be computed for them.
annotation
.
updated
=
null
;
$scope
.
$digest
();
$scope
.
$digest
();
assert
.
equal
(
controller
.
timestamp
,
null
);
assert
.
equal
(
controller
.
timestamp
,
null
);
});
});
it
(
'is updated on first digest'
,
function
()
{
it
(
'is updated on first digest'
,
function
()
{
var
controller
=
createDirective
();
$scope
.
$digest
();
$scope
.
$digest
();
assert
.
equal
(
controller
.
timestamp
,
'a while ago'
);
assert
.
equal
(
controller
.
timestamp
,
'a while ago'
);
});
});
it
(
'is updated after a timeout'
,
function
()
{
it
(
'is updated after a timeout'
,
function
()
{
var
controller
=
createDirective
();
fakeTime
.
nextFuzzyUpdate
.
returns
(
10
);
fakeTime
.
nextFuzzyUpdate
.
returns
(
10
);
fakeTime
.
toFuzzyString
.
returns
(
'ages ago'
);
fakeTime
.
toFuzzyString
.
returns
(
'ages ago'
);
$scope
.
$digest
();
$scope
.
$digest
();
...
@@ -801,6 +814,7 @@ describe('annotation.js', function() {
...
@@ -801,6 +814,7 @@ describe('annotation.js', function() {
});
});
it
(
'is no longer updated after the scope is destroyed'
,
function
()
{
it
(
'is no longer updated after the scope is destroyed'
,
function
()
{
var
controller
=
createDirective
();
$scope
.
$digest
();
$scope
.
$digest
();
$scope
.
$destroy
();
$scope
.
$destroy
();
$timeout
.
flush
();
$timeout
.
flush
();
...
@@ -809,13 +823,9 @@ describe('annotation.js', function() {
...
@@ -809,13 +823,9 @@ describe('annotation.js', function() {
});
});
describe
(
'share'
,
function
()
{
describe
(
'share'
,
function
()
{
var
dialog
;
beforeEach
(
function
()
{
dialog
=
$element
.
find
(
'.share-dialog-wrapper'
);
});
it
(
'sets and unsets the open class on the share wrapper'
,
function
()
{
it
(
'sets and unsets the open class on the share wrapper'
,
function
()
{
var
controller
=
createDirective
();
var
dialog
=
$element
.
find
(
'.share-dialog-wrapper'
);
dialog
.
find
(
'button'
).
click
();
dialog
.
find
(
'button'
).
click
();
isolateScope
.
$digest
();
isolateScope
.
$digest
();
assert
.
ok
(
dialog
.
hasClass
(
'open'
));
assert
.
ok
(
dialog
.
hasClass
(
'open'
));
...
@@ -827,7 +837,6 @@ describe('annotation.js', function() {
...
@@ -827,7 +837,6 @@ describe('annotation.js', function() {
describe
(
'deleteAnnotation() method'
,
function
()
{
describe
(
'deleteAnnotation() method'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
createDirective
();
fakeAnnotationMapper
.
deleteAnnotation
=
sandbox
.
stub
();
fakeAnnotationMapper
.
deleteAnnotation
=
sandbox
.
stub
();
fakeFlash
.
error
=
sandbox
.
stub
();
fakeFlash
.
error
=
sandbox
.
stub
();
});
});
...
@@ -835,6 +844,7 @@ describe('annotation.js', function() {
...
@@ -835,6 +844,7 @@ describe('annotation.js', function() {
it
(
it
(
'calls annotationMapper.delete() if the delete is confirmed'
,
'calls annotationMapper.delete() if the delete is confirmed'
,
function
(
done
)
{
function
(
done
)
{
var
controller
=
createDirective
();
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
true
);
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
true
);
fakeAnnotationMapper
.
deleteAnnotation
.
returns
(
$q
.
resolve
());
fakeAnnotationMapper
.
deleteAnnotation
.
returns
(
$q
.
resolve
());
controller
[
'delete'
]().
then
(
function
()
{
controller
[
'delete'
]().
then
(
function
()
{
...
@@ -848,6 +858,7 @@ describe('annotation.js', function() {
...
@@ -848,6 +858,7 @@ describe('annotation.js', function() {
it
(
it
(
'doesn
\'
t call annotationMapper.delete() if the delete is cancelled'
,
'doesn
\'
t call annotationMapper.delete() if the delete is cancelled'
,
function
()
{
function
()
{
var
controller
=
createDirective
();
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
false
);
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
false
);
assert
(
fakeAnnotationMapper
.
deleteAnnotation
.
notCalled
);
assert
(
fakeAnnotationMapper
.
deleteAnnotation
.
notCalled
);
}
}
...
@@ -856,6 +867,7 @@ describe('annotation.js', function() {
...
@@ -856,6 +867,7 @@ describe('annotation.js', function() {
it
(
it
(
'flashes a generic error if the server cannot be reached'
,
'flashes a generic error if the server cannot be reached'
,
function
(
done
)
{
function
(
done
)
{
var
controller
=
createDirective
();
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
true
);
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
true
);
fakeAnnotationMapper
.
deleteAnnotation
.
returns
(
$q
.
reject
({
fakeAnnotationMapper
.
deleteAnnotation
.
returns
(
$q
.
reject
({
status
:
0
status
:
0
...
@@ -870,6 +882,7 @@ describe('annotation.js', function() {
...
@@ -870,6 +882,7 @@ describe('annotation.js', function() {
);
);
it
(
'flashes an error if the delete fails on the server'
,
function
(
done
)
{
it
(
'flashes an error if the delete fails on the server'
,
function
(
done
)
{
var
controller
=
createDirective
();
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
true
);
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
true
);
fakeAnnotationMapper
.
deleteAnnotation
.
returns
(
$q
.
reject
({
fakeAnnotationMapper
.
deleteAnnotation
.
returns
(
$q
.
reject
({
status
:
500
,
status
:
500
,
...
@@ -885,6 +898,7 @@ describe('annotation.js', function() {
...
@@ -885,6 +898,7 @@ describe('annotation.js', function() {
});
});
it
(
'doesn
\'
t flash an error if the delete succeeds'
,
function
(
done
)
{
it
(
'doesn
\'
t flash an error if the delete succeeds'
,
function
(
done
)
{
var
controller
=
createDirective
();
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
true
);
sandbox
.
stub
(
$window
,
'confirm'
).
returns
(
true
);
fakeAnnotationMapper
.
deleteAnnotation
.
returns
(
$q
.
resolve
());
fakeAnnotationMapper
.
deleteAnnotation
.
returns
(
$q
.
resolve
());
controller
[
'delete'
]().
then
(
function
()
{
controller
[
'delete'
]().
then
(
function
()
{
...
@@ -897,15 +911,20 @@ describe('annotation.js', function() {
...
@@ -897,15 +911,20 @@ describe('annotation.js', function() {
describe
(
'saving a new annotation'
,
function
()
{
describe
(
'saving a new annotation'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
createDirective
();
fakeFlash
.
error
=
sandbox
.
stub
();
fakeFlash
.
error
=
sandbox
.
stub
();
controller
.
action
=
'create'
;
annotation
.
$create
=
sandbox
.
stub
();
annotation
.
$create
=
sandbox
.
stub
();
});
});
function
controllerWithActionCreate
()
{
var
controller
=
createDirective
();
controller
.
action
=
'create'
;
return
controller
;
}
it
(
it
(
'emits annotationCreated when saving an annotation succeeds'
,
'emits annotationCreated when saving an annotation succeeds'
,
function
(
done
)
{
function
(
done
)
{
var
controller
=
controllerWithActionCreate
();
sandbox
.
spy
(
$rootScope
,
'$emit'
);
sandbox
.
spy
(
$rootScope
,
'$emit'
);
annotation
.
$create
.
returns
(
Promise
.
resolve
());
annotation
.
$create
.
returns
(
Promise
.
resolve
());
controller
.
save
().
then
(
function
()
{
controller
.
save
().
then
(
function
()
{
...
@@ -918,6 +937,7 @@ describe('annotation.js', function() {
...
@@ -918,6 +937,7 @@ describe('annotation.js', function() {
it
(
it
(
'flashes a generic error if the server can
\'
t be reached'
,
'flashes a generic error if the server can
\'
t be reached'
,
function
(
done
)
{
function
(
done
)
{
var
controller
=
controllerWithActionCreate
();
annotation
.
$create
.
returns
(
Promise
.
reject
({
annotation
.
$create
.
returns
(
Promise
.
reject
({
status
:
0
status
:
0
}));
}));
...
@@ -932,6 +952,7 @@ describe('annotation.js', function() {
...
@@ -932,6 +952,7 @@ describe('annotation.js', function() {
it
(
it
(
'flashes an error if saving the annotation fails on the server'
,
'flashes an error if saving the annotation fails on the server'
,
function
(
done
)
{
function
(
done
)
{
var
controller
=
controllerWithActionCreate
();
annotation
.
$create
.
returns
(
Promise
.
reject
({
annotation
.
$create
.
returns
(
Promise
.
reject
({
status
:
500
,
status
:
500
,
statusText
:
'Server Error'
,
statusText
:
'Server Error'
,
...
@@ -948,6 +969,7 @@ describe('annotation.js', function() {
...
@@ -948,6 +969,7 @@ describe('annotation.js', function() {
it
(
it
(
'doesn
\'
t flash an error when saving an annotation succeeds'
,
'doesn
\'
t flash an error when saving an annotation succeeds'
,
function
()
{
function
()
{
var
controller
=
controllerWithActionCreate
();
annotation
.
$create
.
returns
(
Promise
.
resolve
());
annotation
.
$create
.
returns
(
Promise
.
resolve
());
controller
.
save
();
controller
.
save
();
assert
(
fakeFlash
.
error
.
notCalled
);
assert
(
fakeFlash
.
error
.
notCalled
);
...
@@ -957,15 +979,20 @@ describe('annotation.js', function() {
...
@@ -957,15 +979,20 @@ describe('annotation.js', function() {
describe
(
'saving an edited an annotation'
,
function
()
{
describe
(
'saving an edited an annotation'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
createDirective
();
fakeFlash
.
error
=
sandbox
.
stub
();
fakeFlash
.
error
=
sandbox
.
stub
();
controller
.
action
=
'edit'
;
annotation
.
$update
=
sandbox
.
stub
();
annotation
.
$update
=
sandbox
.
stub
();
});
});
function
controllerWithActionEdit
()
{
var
controller
=
createDirective
();
controller
.
action
=
'edit'
;
return
controller
;
}
it
(
it
(
'flashes a generic error if the server cannot be reached'
,
'flashes a generic error if the server cannot be reached'
,
function
(
done
)
{
function
(
done
)
{
var
controller
=
controllerWithActionEdit
();
annotation
.
$update
.
returns
(
Promise
.
reject
({
annotation
.
$update
.
returns
(
Promise
.
reject
({
status
:
0
status
:
0
}));
}));
...
@@ -980,6 +1007,7 @@ describe('annotation.js', function() {
...
@@ -980,6 +1007,7 @@ describe('annotation.js', function() {
it
(
it
(
'flashes an error if saving the annotation fails on the server'
,
'flashes an error if saving the annotation fails on the server'
,
function
(
done
)
{
function
(
done
)
{
var
controller
=
controllerWithActionEdit
();
annotation
.
$update
.
returns
(
Promise
.
reject
({
annotation
.
$update
.
returns
(
Promise
.
reject
({
status
:
500
,
status
:
500
,
statusText
:
'Server Error'
,
statusText
:
'Server Error'
,
...
@@ -996,6 +1024,7 @@ describe('annotation.js', function() {
...
@@ -996,6 +1024,7 @@ describe('annotation.js', function() {
it
(
it
(
'doesn
\'
t flash an error if saving the annotation succeeds'
,
'doesn
\'
t flash an error if saving the annotation succeeds'
,
function
()
{
function
()
{
var
controller
=
controllerWithActionEdit
();
annotation
.
$update
.
returns
(
Promise
.
resolve
());
annotation
.
$update
.
returns
(
Promise
.
resolve
());
controller
.
save
();
controller
.
save
();
assert
(
fakeFlash
.
error
.
notCalled
);
assert
(
fakeFlash
.
error
.
notCalled
);
...
@@ -1005,7 +1034,7 @@ describe('annotation.js', function() {
...
@@ -1005,7 +1034,7 @@ describe('annotation.js', function() {
describe
(
'drafts'
,
function
()
{
describe
(
'drafts'
,
function
()
{
it
(
'creates a draft when editing an annotation'
,
function
()
{
it
(
'creates a draft when editing an annotation'
,
function
()
{
createDirective
();
var
controller
=
createDirective
();
controller
.
edit
();
controller
.
edit
();
assert
.
calledWith
(
fakeDrafts
.
update
,
annotation
);
assert
.
calledWith
(
fakeDrafts
.
update
,
annotation
);
});
});
...
@@ -1017,7 +1046,7 @@ describe('annotation.js', function() {
...
@@ -1017,7 +1046,7 @@ describe('annotation.js', function() {
// "changes" object that aren't actually set on the annotation. In this
// "changes" object that aren't actually set on the annotation. In this
// case, both permissions and tags are null so shouldn't be saved in
// case, both permissions and tags are null so shouldn't be saved in
// the draft.
// the draft.
createDirective
();
var
controller
=
createDirective
();
annotation
.
permissions
=
null
;
annotation
.
permissions
=
null
;
annotation
.
text
=
'Hello!'
;
annotation
.
text
=
'Hello!'
;
annotation
.
tags
=
null
;
annotation
.
tags
=
null
;
...
@@ -1037,7 +1066,7 @@ describe('annotation.js', function() {
...
@@ -1037,7 +1066,7 @@ describe('annotation.js', function() {
],
],
text
:
'unsaved-text'
text
:
'unsaved-text'
});
});
createDirective
();
var
controller
=
createDirective
();
assert
.
isTrue
(
controller
.
editing
());
assert
.
isTrue
(
controller
.
editing
());
});
});
...
@@ -1046,7 +1075,7 @@ describe('annotation.js', function() {
...
@@ -1046,7 +1075,7 @@ describe('annotation.js', function() {
tags
:
[
'unsaved-tag'
],
tags
:
[
'unsaved-tag'
],
text
:
'unsaved-text'
text
:
'unsaved-text'
});
});
createDirective
();
var
controller
=
createDirective
();
assert
.
deepEqual
(
controller
.
annotation
.
tags
,
[
assert
.
deepEqual
(
controller
.
annotation
.
tags
,
[
{
{
text
:
'unsaved-tag'
text
:
'unsaved-tag'
...
@@ -1056,7 +1085,7 @@ describe('annotation.js', function() {
...
@@ -1056,7 +1085,7 @@ describe('annotation.js', function() {
});
});
it
(
'removes the draft when changes are discarded'
,
function
()
{
it
(
'removes the draft when changes are discarded'
,
function
()
{
createDirective
();
var
controller
=
createDirective
();
controller
.
edit
();
controller
.
edit
();
controller
.
revert
();
controller
.
revert
();
assert
.
calledWith
(
fakeDrafts
.
remove
,
annotation
);
assert
.
calledWith
(
fakeDrafts
.
remove
,
annotation
);
...
@@ -1064,7 +1093,7 @@ describe('annotation.js', function() {
...
@@ -1064,7 +1093,7 @@ describe('annotation.js', function() {
it
(
'removes the draft when changes are saved'
,
function
()
{
it
(
'removes the draft when changes are saved'
,
function
()
{
annotation
.
$update
=
sandbox
.
stub
().
returns
(
Promise
.
resolve
());
annotation
.
$update
=
sandbox
.
stub
().
returns
(
Promise
.
resolve
());
createDirective
();
var
controller
=
createDirective
();
controller
.
edit
();
controller
.
edit
();
controller
.
save
();
controller
.
save
();
...
@@ -1080,7 +1109,7 @@ describe('annotation.js', function() {
...
@@ -1080,7 +1109,7 @@ describe('annotation.js', function() {
describe
(
'when the focused group changes'
,
function
()
{
describe
(
'when the focused group changes'
,
function
()
{
it
(
'updates the current draft'
,
function
()
{
it
(
'updates the current draft'
,
function
()
{
createDirective
();
var
controller
=
createDirective
();
controller
.
edit
();
controller
.
edit
();
controller
.
annotation
.
text
=
'unsaved-text'
;
controller
.
annotation
.
text
=
'unsaved-text'
;
controller
.
annotation
.
tags
=
[];
controller
.
annotation
.
tags
=
[];
...
@@ -1098,7 +1127,7 @@ describe('annotation.js', function() {
...
@@ -1098,7 +1127,7 @@ describe('annotation.js', function() {
});
});
it
(
'should not create a new draft'
,
function
()
{
it
(
'should not create a new draft'
,
function
()
{
createDirective
();
var
controller
=
createDirective
();
controller
.
edit
();
controller
.
edit
();
fakeDrafts
.
update
=
sinon
.
stub
();
fakeDrafts
.
update
=
sinon
.
stub
();
fakeDrafts
.
get
=
sinon
.
stub
().
returns
(
null
);
fakeDrafts
.
get
=
sinon
.
stub
().
returns
(
null
);
...
...
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