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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
2f1a55fa
Commit
2f1a55fa
authored
Jan 31, 2018
by
Clement Ho
Committed by
Fatih Acet
Jan 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use axios instead of jquery ajax for setCiStatusFavicon
parent
a0fc0fcc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
39 deletions
+38
-39
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+6
-11
spec/javascripts/job_spec.js
spec/javascripts/job_spec.js
+6
-15
spec/javascripts/lib/utils/common_utils_spec.js
spec/javascripts/lib/utils/common_utils_spec.js
+26
-13
No files found.
app/assets/javascripts/lib/utils/common_utils.js
View file @
2f1a55fa
import
{
getLocationHash
}
from
'
./url_utility
'
;
import
{
getLocationHash
}
from
'
./url_utility
'
;
import
axios
from
'
./axios_utils
'
;
export
const
getPagePath
=
(
index
=
0
)
=>
$
(
'
body
'
).
attr
(
'
data-page
'
).
split
(
'
:
'
)[
index
];
export
const
getPagePath
=
(
index
=
0
)
=>
$
(
'
body
'
).
attr
(
'
data-page
'
).
split
(
'
:
'
)[
index
];
...
@@ -382,22 +383,16 @@ export const resetFavicon = () => {
...
@@ -382,22 +383,16 @@ export const resetFavicon = () => {
}
}
};
};
export
const
setCiStatusFavicon
=
(
pageUrl
)
=>
{
export
const
setCiStatusFavicon
=
pageUrl
=>
$
.
ajax
({
axios
.
get
(
pageUrl
)
url
:
pageUrl
,
.
then
(({
data
})
=>
{
dataType
:
'
json
'
,
success
:
(
data
)
=>
{
if
(
data
&&
data
.
favicon
)
{
if
(
data
&&
data
.
favicon
)
{
setFavicon
(
data
.
favicon
);
setFavicon
(
data
.
favicon
);
}
else
{
}
else
{
resetFavicon
();
resetFavicon
();
}
}
},
})
error
:
()
=>
{
.
catch
(
resetFavicon
);
resetFavicon
();
},
});
};
export
const
spriteIcon
=
(
icon
,
className
=
''
)
=>
{
export
const
spriteIcon
=
(
icon
,
className
=
''
)
=>
{
const
classAttribute
=
className
.
length
>
0
?
`class="
${
className
}
"`
:
''
;
const
classAttribute
=
className
.
length
>
0
?
`class="
${
className
}
"`
:
''
;
...
...
spec/javascripts/job_spec.js
View file @
2f1a55fa
...
@@ -58,8 +58,7 @@ describe('Job', () => {
...
@@ -58,8 +58,7 @@ describe('Job', () => {
it
(
'
updates the build trace on an interval
'
,
function
()
{
it
(
'
updates the build trace on an interval
'
,
function
()
{
const
deferred1
=
$
.
Deferred
();
const
deferred1
=
$
.
Deferred
();
const
deferred2
=
$
.
Deferred
();
const
deferred2
=
$
.
Deferred
();
const
deferred3
=
$
.
Deferred
();
spyOn
(
$
,
'
ajax
'
).
and
.
returnValues
(
deferred1
.
promise
(),
deferred2
.
promise
());
spyOn
(
$
,
'
ajax
'
).
and
.
returnValues
(
deferred1
.
promise
(),
deferred2
.
promise
(),
deferred3
.
promise
());
spyOn
(
urlUtils
,
'
visitUrl
'
);
spyOn
(
urlUtils
,
'
visitUrl
'
);
deferred1
.
resolve
({
deferred1
.
resolve
({
...
@@ -70,9 +69,7 @@ describe('Job', () => {
...
@@ -70,9 +69,7 @@ describe('Job', () => {
complete
:
false
,
complete
:
false
,
});
});
deferred2
.
resolve
();
deferred2
.
resolve
({
deferred3
.
resolve
({
html
:
'
<span>More</span>
'
,
html
:
'
<span>More</span>
'
,
status
:
'
running
'
,
status
:
'
running
'
,
state
:
'
finalstate
'
,
state
:
'
finalstate
'
,
...
@@ -94,9 +91,8 @@ describe('Job', () => {
...
@@ -94,9 +91,8 @@ describe('Job', () => {
it
(
'
replaces the entire build trace
'
,
()
=>
{
it
(
'
replaces the entire build trace
'
,
()
=>
{
const
deferred1
=
$
.
Deferred
();
const
deferred1
=
$
.
Deferred
();
const
deferred2
=
$
.
Deferred
();
const
deferred2
=
$
.
Deferred
();
const
deferred3
=
$
.
Deferred
();
spyOn
(
$
,
'
ajax
'
).
and
.
returnValues
(
deferred1
.
promise
(),
deferred2
.
promise
()
,
deferred3
.
promise
()
);
spyOn
(
$
,
'
ajax
'
).
and
.
returnValues
(
deferred1
.
promise
(),
deferred2
.
promise
());
spyOn
(
urlUtils
,
'
visitUrl
'
);
spyOn
(
urlUtils
,
'
visitUrl
'
);
...
@@ -107,9 +103,7 @@ describe('Job', () => {
...
@@ -107,9 +103,7 @@ describe('Job', () => {
complete
:
false
,
complete
:
false
,
});
});
deferred2
.
resolve
();
deferred2
.
resolve
({
deferred3
.
resolve
({
html
:
'
<span>Different</span>
'
,
html
:
'
<span>Different</span>
'
,
status
:
'
running
'
,
status
:
'
running
'
,
append
:
false
,
append
:
false
,
...
@@ -170,9 +164,8 @@ describe('Job', () => {
...
@@ -170,9 +164,8 @@ describe('Job', () => {
it
(
'
shows incremented size
'
,
()
=>
{
it
(
'
shows incremented size
'
,
()
=>
{
const
deferred1
=
$
.
Deferred
();
const
deferred1
=
$
.
Deferred
();
const
deferred2
=
$
.
Deferred
();
const
deferred2
=
$
.
Deferred
();
const
deferred3
=
$
.
Deferred
();
spyOn
(
$
,
'
ajax
'
).
and
.
returnValues
(
deferred1
.
promise
(),
deferred2
.
promise
()
,
deferred3
.
promise
()
);
spyOn
(
$
,
'
ajax
'
).
and
.
returnValues
(
deferred1
.
promise
(),
deferred2
.
promise
());
spyOn
(
urlUtils
,
'
visitUrl
'
);
spyOn
(
urlUtils
,
'
visitUrl
'
);
...
@@ -184,8 +177,6 @@ describe('Job', () => {
...
@@ -184,8 +177,6 @@ describe('Job', () => {
total
:
100
,
total
:
100
,
});
});
deferred2
.
resolve
();
this
.
job
=
new
Job
();
this
.
job
=
new
Job
();
expect
(
expect
(
...
@@ -194,7 +185,7 @@ describe('Job', () => {
...
@@ -194,7 +185,7 @@ describe('Job', () => {
jasmine
.
clock
().
tick
(
4001
);
jasmine
.
clock
().
tick
(
4001
);
deferred
3
.
resolve
({
deferred
2
.
resolve
({
html
:
'
<span>Update</span>
'
,
html
:
'
<span>Update</span>
'
,
status
:
'
success
'
,
status
:
'
success
'
,
append
:
true
,
append
:
true
,
...
...
spec/javascripts/lib/utils/common_utils_spec.js
View file @
2f1a55fa
/* eslint-disable promise/catch-or-return */
/* eslint-disable promise/catch-or-return */
import
*
as
commonUtils
from
'
~/lib/utils/common_utils
'
;
import
*
as
commonUtils
from
'
~/lib/utils/common_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
describe
(
'
common_utils
'
,
()
=>
{
describe
(
'
common_utils
'
,
()
=>
{
describe
(
'
parseUrl
'
,
()
=>
{
describe
(
'
parseUrl
'
,
()
=>
{
...
@@ -413,37 +415,48 @@ describe('common_utils', () => {
...
@@ -413,37 +415,48 @@ describe('common_utils', () => {
describe
(
'
setCiStatusFavicon
'
,
()
=>
{
describe
(
'
setCiStatusFavicon
'
,
()
=>
{
const
BUILD_URL
=
`
${
gl
.
TEST_HOST
}
/frontend-fixtures/builds-project/-/jobs/1/status.json`
;
const
BUILD_URL
=
`
${
gl
.
TEST_HOST
}
/frontend-fixtures/builds-project/-/jobs/1/status.json`
;
let
mock
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
const
favicon
=
document
.
createElement
(
'
link
'
);
const
favicon
=
document
.
createElement
(
'
link
'
);
favicon
.
setAttribute
(
'
id
'
,
'
favicon
'
);
favicon
.
setAttribute
(
'
id
'
,
'
favicon
'
);
document
.
body
.
appendChild
(
favicon
);
document
.
body
.
appendChild
(
favicon
);
mock
=
new
MockAdapter
(
axios
);
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
mock
.
restore
();
document
.
body
.
removeChild
(
document
.
getElementById
(
'
favicon
'
));
document
.
body
.
removeChild
(
document
.
getElementById
(
'
favicon
'
));
});
});
it
(
'
should reset favicon in case of error
'
,
()
=>
{
it
(
'
should reset favicon in case of error
'
,
(
done
)
=>
{
const
favicon
=
document
.
getElementById
(
'
favicon
'
);
mock
.
onGet
(
BUILD_URL
).
networkError
();
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(
function
(
options
)
{
options
.
error
();
expect
(
favicon
.
getAttribute
(
'
href
'
)).
toEqual
(
'
null
'
);
});
commonUtils
.
setCiStatusFavicon
(
BUILD_URL
);
commonUtils
.
setCiStatusFavicon
(
BUILD_URL
)
.
then
(()
=>
{
const
favicon
=
document
.
getElementById
(
'
favicon
'
);
expect
(
favicon
.
getAttribute
(
'
href
'
)).
toEqual
(
'
null
'
);
done
();
})
// Error is already caught in catch() block of setCiStatusFavicon,
// It won't throw another error for us to catch
.
catch
(
done
.
fail
);
});
});
it
(
'
should set page favicon to CI status favicon based on provided status
'
,
()
=>
{
it
(
'
should set page favicon to CI status favicon based on provided status
'
,
(
done
)
=>
{
const
FAVICON_PATH
=
'
//icon_status_success
'
;
const
FAVICON_PATH
=
'
//icon_status_success
'
;
const
favicon
=
document
.
getElementById
(
'
favicon
'
);
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(
function
(
options
)
{
mock
.
onGet
(
BUILD_URL
).
reply
(
200
,
{
options
.
success
({
favicon
:
FAVICON_PATH
});
favicon
:
FAVICON_PATH
,
expect
(
favicon
.
getAttribute
(
'
href
'
)).
toEqual
(
FAVICON_PATH
);
});
});
commonUtils
.
setCiStatusFavicon
(
BUILD_URL
);
commonUtils
.
setCiStatusFavicon
(
BUILD_URL
)
.
then
(()
=>
{
const
favicon
=
document
.
getElementById
(
'
favicon
'
);
expect
(
favicon
.
getAttribute
(
'
href
'
)).
toEqual
(
FAVICON_PATH
);
done
();
})
.
catch
(
done
.
fail
);
});
});
});
});
...
...
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