Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
dbab076b
Commit
dbab076b
authored
May 11, 2017
by
Luke "Jared" Bennett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved mockservicecall and fixed up a settimeout
parent
4a4b586a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
32 deletions
+17
-32
spec/javascripts/lib/utils/poll_spec.js
spec/javascripts/lib/utils/poll_spec.js
+17
-32
No files found.
spec/javascripts/lib/utils/poll_spec.js
View file @
dbab076b
...
...
@@ -14,12 +14,17 @@ const waitForAllCallsToFinish = (service, waitForCount, successCallback) => {
timer
();
};
function
mockServiceCall
(
service
,
mockCall
)
{
function
mockServiceCall
(
service
,
response
,
shouldFail
)
{
const
action
=
shouldFail
?
Promise
.
reject
:
Promise
.
resolve
;
const
responseObject
=
response
;
if
(
!
responseObject
.
headers
)
responseObject
.
headers
=
{};
service
.
fetch
.
calls
.
reset
();
service
.
fetch
.
and
.
callFake
(
mockCall
);
service
.
fetch
.
and
.
callFake
(
()
=>
action
(
responseObject
)
);
}
describe
(
'
Poll
'
,
()
=>
{
f
describe
(
'
Poll
'
,
()
=>
{
const
service
=
jasmine
.
createSpyObj
(
'
service
'
,
[
'
fetch
'
]);
let
callbacks
;
...
...
@@ -33,11 +38,8 @@ describe('Poll', () => {
spyOn
(
callbacks
,
'
error
'
);
});
it
(
'
calls the success callback when no header for interval is provided
'
,
(
done
)
=>
{
mockServiceCall
(
service
,
()
=>
Promise
.
resolve
({
status
:
200
,
headers
:
{}
}),
);
fit
(
'
calls the success callback when no header for interval is provided
'
,
(
done
)
=>
{
mockServiceCall
(
service
,
{
status
:
200
});
new
Poll
({
resource
:
service
,
...
...
@@ -55,10 +57,7 @@ describe('Poll', () => {
});
it
(
'
calls the error callback whe the http request returns an error
'
,
(
done
)
=>
{
mockServiceCall
(
service
,
()
=>
Promise
.
reject
({
status
:
500
,
headers
:
{}
}),
);
mockServiceCall
(
service
,
{
status
:
500
},
true
);
new
Poll
({
resource
:
service
,
...
...
@@ -76,31 +75,23 @@ describe('Poll', () => {
});
it
(
'
should call the success callback when the interval header is -1
'
,
(
done
)
=>
{
mockServiceCall
(
service
,
()
=>
Promise
.
resolve
({
status
:
200
,
headers
:
{
'
poll-interval
'
:
-
1
}
}),
);
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'
poll-interval
'
:
-
1
}
});
new
Poll
({
resource
:
service
,
method
:
'
fetch
'
,
successCallback
:
callbacks
.
success
,
errorCallback
:
callbacks
.
error
,
}).
makeRequest
();
setTimeout
(()
=>
{
}).
makeRequest
().
then
(()
=>
{
expect
(
callbacks
.
success
).
toHaveBeenCalled
();
expect
(
callbacks
.
error
).
not
.
toHaveBeenCalled
();
done
();
}
,
0
);
}
).
catch
(
done
.
fail
);
});
it
(
'
starts polling when http status is 200 and interval header is provided
'
,
(
done
)
=>
{
mockServiceCall
(
service
,
()
=>
Promise
.
resolve
({
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
}),
);
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
});
const
Polling
=
new
Poll
({
resource
:
service
,
...
...
@@ -126,10 +117,7 @@ describe('Poll', () => {
describe
(
'
stop
'
,
()
=>
{
it
(
'
stops polling when method is called
'
,
(
done
)
=>
{
mockServiceCall
(
service
,
()
=>
Promise
.
resolve
({
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
}),
);
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
});
const
Polling
=
new
Poll
({
resource
:
service
,
...
...
@@ -157,10 +145,7 @@ describe('Poll', () => {
describe
(
'
restart
'
,
()
=>
{
it
(
'
should restart polling when its called
'
,
(
done
)
=>
{
mockServiceCall
(
service
,
()
=>
Promise
.
resolve
({
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
}),
);
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
});
const
Polling
=
new
Poll
({
resource
:
service
,
...
...
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