BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
0b35dd07
Commit
0b35dd07
authored
Apr 12, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'poll-test-fix' into 'master'
Fixed random failures with Poll spec Closes #30824 See merge request !10654
parents
18188a53
194955fe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
36 deletions
+57
-36
poll_spec.js
spec/javascripts/lib/utils/poll_spec.js
+57
-36
No files found.
spec/javascripts/lib/utils/poll_spec.js
View file @
0b35dd07
...
...
@@ -4,6 +4,20 @@ import Poll from '~/lib/utils/poll';
Vue
.
use
(
VueResource
);
const
waitForAllCallsToFinish
=
(
service
,
waitForCount
,
successCallback
)
=>
{
const
timer
=
()
=>
{
setTimeout
(()
=>
{
if
(
service
.
fetch
.
calls
.
count
()
===
waitForCount
)
{
successCallback
();
}
else
{
timer
();
}
},
5
);
};
timer
();
};
class
ServiceMock
{
constructor
(
endpoint
)
{
this
.
service
=
Vue
.
resource
(
endpoint
);
...
...
@@ -16,6 +30,7 @@ class ServiceMock {
describe
(
'Poll'
,
()
=>
{
let
callbacks
;
let
service
;
beforeEach
(()
=>
{
callbacks
=
{
...
...
@@ -23,8 +38,11 @@ describe('Poll', () => {
error
:
()
=>
{},
};
service
=
new
ServiceMock
(
'endpoint'
);
spyOn
(
callbacks
,
'success'
);
spyOn
(
callbacks
,
'error'
);
spyOn
(
service
,
'fetch'
).
and
.
callThrough
();
});
it
(
'calls the success callback when no header for interval is provided'
,
(
done
)
=>
{
...
...
@@ -35,19 +53,20 @@ describe('Poll', () => {
Vue
.
http
.
interceptors
.
push
(
successInterceptor
);
new
Poll
({
resource
:
new
ServiceMock
(
'endpoint'
)
,
resource
:
service
,
method
:
'fetch'
,
successCallback
:
callbacks
.
success
,
errorCallback
:
callbacks
.
error
,
}).
makeRequest
();
setTimeout
(
()
=>
{
waitForAllCallsToFinish
(
service
,
1
,
()
=>
{
expect
(
callbacks
.
success
).
toHaveBeenCalled
();
expect
(
callbacks
.
error
).
not
.
toHaveBeenCalled
();
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
successInterceptor
);
done
();
},
0
);
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
successInterceptor
);
});
it
(
'calls the error callback whe the http request returns an error'
,
(
done
)
=>
{
...
...
@@ -58,19 +77,19 @@ describe('Poll', () => {
Vue
.
http
.
interceptors
.
push
(
errorInterceptor
);
new
Poll
({
resource
:
new
ServiceMock
(
'endpoint'
)
,
resource
:
service
,
method
:
'fetch'
,
successCallback
:
callbacks
.
success
,
errorCallback
:
callbacks
.
error
,
}).
makeRequest
();
setTimeout
(
()
=>
{
waitForAllCallsToFinish
(
service
,
1
,
()
=>
{
expect
(
callbacks
.
success
).
not
.
toHaveBeenCalled
();
expect
(
callbacks
.
error
).
toHaveBeenCalled
();
done
();
},
0
);
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
errorInterceptor
);
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
errorInterceptor
);
done
();
});
});
it
(
'should call the success callback when the interval header is -1'
,
(
done
)
=>
{
...
...
@@ -81,7 +100,7 @@ describe('Poll', () => {
Vue
.
http
.
interceptors
.
push
(
intervalInterceptor
);
new
Poll
({
resource
:
new
ServiceMock
(
'endpoint'
)
,
resource
:
service
,
method
:
'fetch'
,
successCallback
:
callbacks
.
success
,
errorCallback
:
callbacks
.
error
,
...
...
@@ -90,10 +109,11 @@ describe('Poll', () => {
setTimeout
(()
=>
{
expect
(
callbacks
.
success
).
toHaveBeenCalled
();
expect
(
callbacks
.
error
).
not
.
toHaveBeenCalled
();
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
intervalInterceptor
);
done
();
},
0
);
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
intervalInterceptor
);
});
it
(
'starts polling when http status is 200 and interval header is provided'
,
(
done
)
=>
{
...
...
@@ -103,26 +123,28 @@ describe('Poll', () => {
Vue
.
http
.
interceptors
.
push
(
pollInterceptor
);
const
service
=
new
ServiceMock
(
'endpoint'
);
spyOn
(
service
,
'fetch'
).
and
.
callThrough
();
new
Poll
({
const
Polling
=
new
Poll
({
resource
:
service
,
method
:
'fetch'
,
data
:
{
page
:
1
},
successCallback
:
callbacks
.
success
,
errorCallback
:
callbacks
.
error
,
}).
makeRequest
();
});
Polling
.
makeRequest
();
waitForAllCallsToFinish
(
service
,
2
,
()
=>
{
Polling
.
stop
();
setTimeout
(()
=>
{
expect
(
service
.
fetch
.
calls
.
count
()).
toEqual
(
2
);
expect
(
service
.
fetch
).
toHaveBeenCalledWith
({
page
:
1
});
expect
(
callbacks
.
success
).
toHaveBeenCalled
();
expect
(
callbacks
.
error
).
not
.
toHaveBeenCalled
();
done
();
},
5
);
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
pollInterceptor
);
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
pollInterceptor
);
done
();
});
});
describe
(
'stop'
,
()
=>
{
...
...
@@ -133,9 +155,6 @@ describe('Poll', () => {
Vue
.
http
.
interceptors
.
push
(
pollInterceptor
);
const
service
=
new
ServiceMock
(
'endpoint'
);
spyOn
(
service
,
'fetch'
).
and
.
callThrough
();
const
Polling
=
new
Poll
({
resource
:
service
,
method
:
'fetch'
,
...
...
@@ -150,14 +169,15 @@ describe('Poll', () => {
Polling
.
makeRequest
();
setTimeout
(
()
=>
{
waitForAllCallsToFinish
(
service
,
1
,
()
=>
{
expect
(
service
.
fetch
.
calls
.
count
()).
toEqual
(
1
);
expect
(
service
.
fetch
).
toHaveBeenCalledWith
({
page
:
1
});
expect
(
Polling
.
stop
).
toHaveBeenCalled
();
done
();
},
100
);
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
pollInterceptor
);
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
pollInterceptor
);
done
();
});
});
});
...
...
@@ -169,10 +189,6 @@ describe('Poll', () => {
Vue
.
http
.
interceptors
.
push
(
pollInterceptor
);
const
service
=
new
ServiceMock
(
'endpoint'
);
spyOn
(
service
,
'fetch'
).
and
.
callThrough
();
const
Polling
=
new
Poll
({
resource
:
service
,
method
:
'fetch'
,
...
...
@@ -187,17 +203,22 @@ describe('Poll', () => {
});
spyOn
(
Polling
,
'stop'
).
and
.
callThrough
();
spyOn
(
Polling
,
'restart'
).
and
.
callThrough
();
Polling
.
makeRequest
();
setTimeout
(()
=>
{
waitForAllCallsToFinish
(
service
,
2
,
()
=>
{
Polling
.
stop
();
expect
(
service
.
fetch
.
calls
.
count
()).
toEqual
(
2
);
expect
(
service
.
fetch
).
toHaveBeenCalledWith
({
page
:
1
});
expect
(
Polling
.
stop
).
toHaveBeenCalled
();
done
();
},
10
);
expect
(
Polling
.
restart
).
toHaveBeenCalled
();
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
pollInterceptor
);
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
pollInterceptor
);
done
();
});
});
});
});
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