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) => {
...
@@ -14,12 +14,17 @@ const waitForAllCallsToFinish = (service, waitForCount, successCallback) => {
timer
();
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
.
calls
.
reset
();
service
.
fetch
.
and
.
callFake
(
mockCall
);
service
.
fetch
.
and
.
callFake
(
()
=>
action
(
responseObject
)
);
}
}
describe
(
'
Poll
'
,
()
=>
{
f
describe
(
'
Poll
'
,
()
=>
{
const
service
=
jasmine
.
createSpyObj
(
'
service
'
,
[
'
fetch
'
]);
const
service
=
jasmine
.
createSpyObj
(
'
service
'
,
[
'
fetch
'
]);
let
callbacks
;
let
callbacks
;
...
@@ -33,11 +38,8 @@ describe('Poll', () => {
...
@@ -33,11 +38,8 @@ describe('Poll', () => {
spyOn
(
callbacks
,
'
error
'
);
spyOn
(
callbacks
,
'
error
'
);
});
});
it
(
'
calls the success callback when no header for interval is provided
'
,
(
done
)
=>
{
fit
(
'
calls the success callback when no header for interval is provided
'
,
(
done
)
=>
{
mockServiceCall
(
mockServiceCall
(
service
,
{
status
:
200
});
service
,
()
=>
Promise
.
resolve
({
status
:
200
,
headers
:
{}
}),
);
new
Poll
({
new
Poll
({
resource
:
service
,
resource
:
service
,
...
@@ -55,10 +57,7 @@ describe('Poll', () => {
...
@@ -55,10 +57,7 @@ describe('Poll', () => {
});
});
it
(
'
calls the error callback whe the http request returns an error
'
,
(
done
)
=>
{
it
(
'
calls the error callback whe the http request returns an error
'
,
(
done
)
=>
{
mockServiceCall
(
mockServiceCall
(
service
,
{
status
:
500
},
true
);
service
,
()
=>
Promise
.
reject
({
status
:
500
,
headers
:
{}
}),
);
new
Poll
({
new
Poll
({
resource
:
service
,
resource
:
service
,
...
@@ -76,31 +75,23 @@ describe('Poll', () => {
...
@@ -76,31 +75,23 @@ describe('Poll', () => {
});
});
it
(
'
should call the success callback when the interval header is -1
'
,
(
done
)
=>
{
it
(
'
should call the success callback when the interval header is -1
'
,
(
done
)
=>
{
mockServiceCall
(
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'
poll-interval
'
:
-
1
}
});
service
,
()
=>
Promise
.
resolve
({
status
:
200
,
headers
:
{
'
poll-interval
'
:
-
1
}
}),
);
new
Poll
({
new
Poll
({
resource
:
service
,
resource
:
service
,
method
:
'
fetch
'
,
method
:
'
fetch
'
,
successCallback
:
callbacks
.
success
,
successCallback
:
callbacks
.
success
,
errorCallback
:
callbacks
.
error
,
errorCallback
:
callbacks
.
error
,
}).
makeRequest
();
}).
makeRequest
().
then
(()
=>
{
setTimeout
(()
=>
{
expect
(
callbacks
.
success
).
toHaveBeenCalled
();
expect
(
callbacks
.
success
).
toHaveBeenCalled
();
expect
(
callbacks
.
error
).
not
.
toHaveBeenCalled
();
expect
(
callbacks
.
error
).
not
.
toHaveBeenCalled
();
done
();
done
();
}
,
0
);
}
).
catch
(
done
.
fail
);
});
});
it
(
'
starts polling when http status is 200 and interval header is provided
'
,
(
done
)
=>
{
it
(
'
starts polling when http status is 200 and interval header is provided
'
,
(
done
)
=>
{
mockServiceCall
(
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
});
service
,
()
=>
Promise
.
resolve
({
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
}),
);
const
Polling
=
new
Poll
({
const
Polling
=
new
Poll
({
resource
:
service
,
resource
:
service
,
...
@@ -126,10 +117,7 @@ describe('Poll', () => {
...
@@ -126,10 +117,7 @@ describe('Poll', () => {
describe
(
'
stop
'
,
()
=>
{
describe
(
'
stop
'
,
()
=>
{
it
(
'
stops polling when method is called
'
,
(
done
)
=>
{
it
(
'
stops polling when method is called
'
,
(
done
)
=>
{
mockServiceCall
(
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
});
service
,
()
=>
Promise
.
resolve
({
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
}),
);
const
Polling
=
new
Poll
({
const
Polling
=
new
Poll
({
resource
:
service
,
resource
:
service
,
...
@@ -157,10 +145,7 @@ describe('Poll', () => {
...
@@ -157,10 +145,7 @@ describe('Poll', () => {
describe
(
'
restart
'
,
()
=>
{
describe
(
'
restart
'
,
()
=>
{
it
(
'
should restart polling when its called
'
,
(
done
)
=>
{
it
(
'
should restart polling when its called
'
,
(
done
)
=>
{
mockServiceCall
(
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
});
service
,
()
=>
Promise
.
resolve
({
status
:
200
,
headers
:
{
'
poll-interval
'
:
1
}
}),
);
const
Polling
=
new
Poll
({
const
Polling
=
new
Poll
({
resource
:
service
,
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