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
Léo-Paul Géneau
gitlab-ce
Commits
f5caabad
Commit
f5caabad
authored
Feb 15, 2018
by
Clement Ho
Committed by
Jacob Schatz
Feb 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace $.get with axios in importerStatus
parent
4342e391
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
28 deletions
+95
-28
app/assets/javascripts/importer_status.js
app/assets/javascripts/importer_status.js
+28
-21
spec/javascripts/importer_status_spec.js
spec/javascripts/importer_status_spec.js
+67
-7
No files found.
app/assets/javascripts/importer_status.js
View file @
f5caabad
...
@@ -59,8 +59,10 @@ class ImporterStatus {
...
@@ -59,8 +59,10 @@ class ImporterStatus {
.
catch
(()
=>
flash
(
__
(
'
An error occurred while importing project
'
)));
.
catch
(()
=>
flash
(
__
(
'
An error occurred while importing project
'
)));
}
}
setAutoUpdate
()
{
autoUpdate
()
{
return
setInterval
(()
=>
$
.
get
(
this
.
jobsUrl
,
data
=>
$
.
each
(
data
,
(
i
,
job
)
=>
{
return
axios
.
get
(
this
.
jobsUrl
)
.
then
(({
data
=
[]
})
=>
{
data
.
forEach
((
job
)
=>
{
const
jobItem
=
$
(
`#project_
${
job
.
id
}
`
);
const
jobItem
=
$
(
`#project_
${
job
.
id
}
`
);
const
statusField
=
jobItem
.
find
(
'
.job-status
'
);
const
statusField
=
jobItem
.
find
(
'
.job-status
'
);
...
@@ -81,7 +83,12 @@ class ImporterStatus {
...
@@ -81,7 +83,12 @@ class ImporterStatus {
statusField
.
html
(
job
.
import_status
);
statusField
.
html
(
job
.
import_status
);
break
;
break
;
}
}
})),
4000
);
});
});
}
setAutoUpdate
()
{
setInterval
(
this
.
autoUpdate
.
bind
(
this
),
4000
);
}
}
}
}
...
...
spec/javascripts/importer_status_spec.js
View file @
f5caabad
...
@@ -3,9 +3,18 @@ import axios from '~/lib/utils/axios_utils';
...
@@ -3,9 +3,18 @@ import axios from '~/lib/utils/axios_utils';
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
describe
(
'
Importer Status
'
,
()
=>
{
describe
(
'
Importer Status
'
,
()
=>
{
describe
(
'
addToImport
'
,
()
=>
{
let
instance
;
let
instance
;
let
mock
;
let
mock
;
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
});
afterEach
(()
=>
{
mock
.
restore
();
});
describe
(
'
addToImport
'
,
()
=>
{
const
importUrl
=
'
/import_url
'
;
const
importUrl
=
'
/import_url
'
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
...
@@ -21,11 +30,6 @@ describe('Importer Status', () => {
...
@@ -21,11 +30,6 @@ describe('Importer Status', () => {
spyOn
(
ImporterStatus
.
prototype
,
'
initStatusPage
'
).
and
.
callFake
(()
=>
{});
spyOn
(
ImporterStatus
.
prototype
,
'
initStatusPage
'
).
and
.
callFake
(()
=>
{});
spyOn
(
ImporterStatus
.
prototype
,
'
setAutoUpdate
'
).
and
.
callFake
(()
=>
{});
spyOn
(
ImporterStatus
.
prototype
,
'
setAutoUpdate
'
).
and
.
callFake
(()
=>
{});
instance
=
new
ImporterStatus
(
''
,
importUrl
);
instance
=
new
ImporterStatus
(
''
,
importUrl
);
mock
=
new
MockAdapter
(
axios
);
});
afterEach
(()
=>
{
mock
.
restore
();
});
});
it
(
'
sets table row to active after post request
'
,
(
done
)
=>
{
it
(
'
sets table row to active after post request
'
,
(
done
)
=>
{
...
@@ -44,4 +48,60 @@ describe('Importer Status', () => {
...
@@ -44,4 +48,60 @@ describe('Importer Status', () => {
.
catch
(
done
.
fail
);
.
catch
(
done
.
fail
);
});
});
});
});
describe
(
'
autoUpdate
'
,
()
=>
{
const
jobsUrl
=
'
/jobs_url
'
;
beforeEach
(()
=>
{
const
div
=
document
.
createElement
(
'
div
'
);
div
.
innerHTML
=
`
<div id="project_1">
<div class="job-status">
</div>
</div>
`
;
document
.
body
.
appendChild
(
div
);
spyOn
(
ImporterStatus
.
prototype
,
'
initStatusPage
'
).
and
.
callFake
(()
=>
{});
spyOn
(
ImporterStatus
.
prototype
,
'
setAutoUpdate
'
).
and
.
callFake
(()
=>
{});
instance
=
new
ImporterStatus
(
jobsUrl
);
});
function
setupMock
(
importStatus
)
{
mock
.
onGet
(
jobsUrl
).
reply
(
200
,
[{
id
:
1
,
import_status
:
importStatus
,
}]);
}
function
expectJobStatus
(
done
,
status
)
{
instance
.
autoUpdate
()
.
then
(()
=>
{
expect
(
document
.
querySelector
(
'
#project_1
'
).
innerText
.
trim
()).
toEqual
(
status
);
done
();
})
.
catch
(
done
.
fail
);
}
it
(
'
sets the job status to done
'
,
(
done
)
=>
{
setupMock
(
'
finished
'
);
expectJobStatus
(
done
,
'
done
'
);
});
it
(
'
sets the job status to scheduled
'
,
(
done
)
=>
{
setupMock
(
'
scheduled
'
);
expectJobStatus
(
done
,
'
scheduled
'
);
});
it
(
'
sets the job status to started
'
,
(
done
)
=>
{
setupMock
(
'
started
'
);
expectJobStatus
(
done
,
'
started
'
);
});
it
(
'
sets the job status to custom status
'
,
(
done
)
=>
{
setupMock
(
'
custom status
'
);
expectJobStatus
(
done
,
'
custom status
'
);
});
});
});
});
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