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
46ba01cf
Commit
46ba01cf
authored
May 04, 2017
by
Robert Knight
Committed by
GitHub
May 04, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #374 from hypothesis/improve-error-when-flagging-when-logged-out
Improve error when flagging when logged out
parents
9998e0ad
cd22ae61
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
28 deletions
+57
-28
annotation.js
src/sidebar/components/annotation.js
+8
-0
annotation-test.js
src/sidebar/components/test/annotation-test.js
+49
-28
No files found.
src/sidebar/components/annotation.js
View file @
46ba01cf
...
...
@@ -182,6 +182,14 @@ function AnnotationController(
* @description Flag the annotation.
*/
this
.
flag
=
function
()
{
if
(
!
session
.
state
.
userid
)
{
flash
.
error
(
'You must be logged in to report an annotation to the moderators.'
,
'Login to flag annotations'
);
return
;
}
var
onRejected
=
function
(
err
)
{
flash
.
error
(
err
.
message
,
'Flagging annotation failed'
);
};
...
...
src/sidebar/components/test/annotation-test.js
View file @
46ba01cf
...
...
@@ -730,37 +730,58 @@ describe('annotation', function() {
fakeAnnotationMapper
.
flagAnnotation
=
sandbox
.
stub
();
});
it
(
'calls annotationMapper.flag() when an annotation is flagged'
,
function
(
done
)
{
var
parts
=
createDirective
();
fakeAnnotationMapper
.
flagAnnotation
.
returns
(
$q
.
resolve
());
parts
.
controller
.
flag
();
assert
.
calledWith
(
fakeAnnotationMapper
.
flagAnnotation
,
parts
.
annotation
);
done
();
}
);
context
(
'when the user is not logged in'
,
function
()
{
beforeEach
(
function
()
{
delete
fakeSession
.
state
.
userid
;
});
it
(
'flashes an error if the flag fails'
,
function
(
done
)
{
var
controller
=
createDirective
().
controller
;
var
err
=
new
Error
(
'500 Server error'
);
fakeAnnotationMapper
.
flagAnnotation
.
returns
(
Promise
.
reject
(
err
));
controller
.
flag
();
setTimeout
(
function
()
{
assert
.
calledWith
(
fakeFlash
.
error
,
'500 Server error'
,
'Flagging annotation failed'
);
done
();
},
0
);
it
(
'flashes an error'
,
function
()
{
createDirective
().
controller
.
flag
();
assert
.
isTrue
(
fakeFlash
.
error
.
calledOnce
);
assert
.
equal
(
'Login to flag annotations'
,
fakeFlash
.
error
.
args
[
0
][
1
]);
});
it
(
'doesn
\'
t try to flag the annotation'
,
function
()
{
createDirective
().
controller
.
flag
();
assert
.
isFalse
(
fakeAnnotationMapper
.
flagAnnotation
.
called
);
});
});
it
(
'doesn
\'
t flash an error if the flag succeeds'
,
function
(
done
)
{
var
controller
=
createDirective
().
controller
;
fakeAnnotationMapper
.
flagAnnotation
.
returns
(
$q
.
resolve
());
controller
.
flag
();
setTimeout
(
function
()
{
assert
.
notCalled
(
fakeFlash
.
error
);
done
();
},
0
);
context
(
'when the user is logged in'
,
function
()
{
it
(
'calls annotationMapper.flag() when an annotation is flagged'
,
function
(
done
)
{
var
parts
=
createDirective
();
fakeAnnotationMapper
.
flagAnnotation
.
returns
(
$q
.
resolve
());
parts
.
controller
.
flag
();
assert
.
calledWith
(
fakeAnnotationMapper
.
flagAnnotation
,
parts
.
annotation
);
done
();
}
);
it
(
'flashes an error if the flag fails'
,
function
(
done
)
{
var
controller
=
createDirective
().
controller
;
var
err
=
new
Error
(
'500 Server error'
);
fakeAnnotationMapper
.
flagAnnotation
.
returns
(
Promise
.
reject
(
err
));
controller
.
flag
();
setTimeout
(
function
()
{
assert
.
calledWith
(
fakeFlash
.
error
,
'500 Server error'
,
'Flagging annotation failed'
);
done
();
},
0
);
});
it
(
'doesn
\'
t flash an error if the flag succeeds'
,
function
(
done
)
{
var
controller
=
createDirective
().
controller
;
fakeAnnotationMapper
.
flagAnnotation
.
returns
(
$q
.
resolve
());
controller
.
flag
();
setTimeout
(
function
()
{
assert
.
notCalled
(
fakeFlash
.
error
);
done
();
},
0
);
});
});
});
...
...
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