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
815ea8cb
Commit
815ea8cb
authored
Apr 03, 2020
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify test by using a mock rather than real store
parent
df9219fb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
16 deletions
+10
-16
annotation-mapper-test.js
src/sidebar/services/test/annotation-mapper-test.js
+10
-16
No files found.
src/sidebar/services/test/annotation-mapper-test.js
View file @
815ea8cb
import
{
Injector
}
from
'../../../shared/injector'
;
import
events
from
'../../events'
;
import
storeFactory
from
'../../store'
;
import
annotationMapperFactory
from
'../annotation-mapper'
;
import
immutable
from
'../../util/immutable'
;
describe
(
'annotationMapper'
,
function
()
{
let
$rootScope
;
let
store
;
let
fakeApi
;
let
fakeStore
;
let
annotationMapper
;
beforeEach
(
function
()
{
...
...
@@ -19,31 +17,31 @@ describe('annotationMapper', function () {
};
$rootScope
=
{
// nb. `$applyAsync` is needed because this test uses the real `store`
// service.
$applyAsync
:
sinon
.
stub
().
yields
(),
$broadcast
:
sinon
.
stub
(),
};
fakeStore
=
{
addAnnotations
:
sinon
.
stub
(),
removeAnnotations
:
sinon
.
stub
(),
};
const
injector
=
new
Injector
()
.
register
(
'$rootScope'
,
{
value
:
$rootScope
})
.
register
(
'api'
,
{
value
:
fakeApi
})
.
register
(
'settings'
,
{
value
:
{}
})
.
register
(
'store'
,
storeFactory
)
.
register
(
'store'
,
{
value
:
fakeStore
}
)
.
register
(
'annotationMapper'
,
annotationMapperFactory
);
store
=
injector
.
get
(
'store'
);
annotationMapper
=
injector
.
get
(
'annotationMapper'
);
});
describe
(
'#loadAnnotations'
,
function
()
{
it
(
'adds annotations and replies to the store'
,
()
=>
{
store
.
addAnnotations
=
sinon
.
stub
();
const
annotations
=
[{
id
:
1
},
{
id
:
2
},
{
id
:
3
}];
const
replies
=
[{
id
:
4
}];
annotationMapper
.
loadAnnotations
(
annotations
,
replies
);
assert
.
calledWith
(
s
tore
.
addAnnotations
,
[...
annotations
,
...
replies
]);
assert
.
calledWith
(
fakeS
tore
.
addAnnotations
,
[...
annotations
,
...
replies
]);
});
});
...
...
@@ -75,10 +73,6 @@ describe('annotationMapper', function () {
});
describe
(
'#deleteAnnotation'
,
function
()
{
beforeEach
(()
=>
{
store
.
removeAnnotations
=
sinon
.
stub
();
});
it
(
'deletes the annotation on the server'
,
function
()
{
const
ann
=
{
id
:
'test-id'
};
annotationMapper
.
deleteAnnotation
(
ann
);
...
...
@@ -88,14 +82,14 @@ describe('annotationMapper', function () {
it
(
'removes the annotation from the store on success'
,
async
()
=>
{
const
ann
=
{};
await
annotationMapper
.
deleteAnnotation
(
ann
);
assert
.
calledWith
(
s
tore
.
removeAnnotations
,
[
ann
]);
assert
.
calledWith
(
fakeS
tore
.
removeAnnotations
,
[
ann
]);
});
it
(
'does not remove the annotation from the store on error'
,
()
=>
{
fakeApi
.
annotation
.
delete
.
returns
(
Promise
.
reject
());
const
ann
=
{
id
:
'test-id'
};
return
annotationMapper
.
deleteAnnotation
(
ann
).
catch
(
function
()
{
assert
.
notCalled
(
s
tore
.
removeAnnotations
);
assert
.
notCalled
(
fakeS
tore
.
removeAnnotations
);
});
});
});
...
...
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