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
88b00fae
Commit
88b00fae
authored
May 13, 2020
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix specs and expose promise as return value of renderMetrics
parent
4c239f5c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
37 deletions
+33
-37
app/assets/javascripts/behaviors/markdown/render_metrics.js
app/assets/javascripts/behaviors/markdown/render_metrics.js
+15
-19
spec/frontend/behaviors/markdown/render_metrics_spec.js
spec/frontend/behaviors/markdown/render_metrics_spec.js
+18
-18
No files found.
app/assets/javascripts/behaviors/markdown/render_metrics.js
View file @
88b00fae
...
...
@@ -4,7 +4,7 @@ import { createStore } from '~/monitoring/stores/embed_group/';
// TODO: Handle copy-pasting - https://gitlab.com/gitlab-org/gitlab-foss/issues/64369.
export
default
function
renderMetrics
(
elements
)
{
if
(
!
elements
.
length
)
{
return
;
return
Promise
.
resolve
()
;
}
const
wrapperList
=
[];
...
...
@@ -28,24 +28,20 @@ export default function renderMetrics(elements) {
element
.
parentNode
.
removeChild
(
element
);
});
if
(
wrapperList
.
length
)
{
import
(
/* webpackChunkName: 'gfm_metrics' */
'
~/monitoring/components/embeds/embed_group.vue
'
)
.
then
(
EmbedGroup
=>
{
const
EmbedGroupComponent
=
Vue
.
extend
(
EmbedGroup
.
default
);
return
import
(
/* webpackChunkName: 'gfm_metrics' */
'
~/monitoring/components/embeds/embed_group.vue
'
).
then
(({
default
:
EmbedGroup
})
=>
{
const
EmbedGroupComponent
=
Vue
.
extend
(
EmbedGroup
);
wrapperList
.
forEach
(
wrapper
=>
{
// eslint-disable-next-line no-new
new
EmbedGroupComponent
({
el
:
wrapper
,
store
:
createStore
(),
propsData
:
{
urls
:
wrapper
.
urls
,
},
});
});
})
.
catch
(()
=>
{
// do nothing
wrapperList
.
forEach
(
wrapper
=>
{
// eslint-disable-next-line no-new
new
EmbedGroupComponent
({
el
:
wrapper
,
store
:
createStore
(),
propsData
:
{
urls
:
wrapper
.
urls
,
},
});
}
});
});
}
spec/frontend/behaviors/markdown/render_metrics_spec.js
View file @
88b00fae
...
...
@@ -11,20 +11,20 @@ const getElements = () => Array.from(document.getElementsByClassName('js-render-
describe
(
'
Render metrics for Gitlab Flavoured Markdown
'
,
()
=>
{
it
(
'
does nothing when no elements are found
'
,
()
=>
{
re
nderMetrics
([]);
expect
(
mockEmbedGroup
).
not
.
toHaveBeenCalled
(
);
re
turn
renderMetrics
([]).
then
(()
=>
{
expect
(
mockEmbedGroup
).
not
.
toHaveBeenCalled
();
}
);
});
it
(
'
renders a vue component when elements are found
'
,
()
=>
{
document
.
body
.
innerHTML
=
`<div class="js-render-metrics" data-dashboard-url="
${
TEST_HOST
}
"></div>`
;
re
nderMetrics
(
getElements
());
expect
(
mockEmbedGroup
).
toHaveBeenCalledTimes
(
1
);
expect
(
mockEmbedGroup
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
propsData
:
{
urls
:
[
`
${
TEST_HOST
}
`
]
}
}),
);
re
turn
renderMetrics
(
getElements
()).
then
(()
=>
{
expect
(
mockEmbedGroup
).
toHaveBeenCalledTimes
(
1
);
expect
(
mockEmbedGroup
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
propsData
:
{
urls
:
[
`
${
TEST_HOST
}
`
]
}
}),
);
}
);
});
it
(
'
takes sibling metrics and groups them under a shared parent
'
,
()
=>
{
...
...
@@ -36,14 +36,14 @@ describe('Render metrics for Gitlab Flavoured Markdown', () => {
<div class="js-render-metrics" data-dashboard-url="
${
TEST_HOST
}
/3"></div>
`
;
re
nderMetrics
(
getElements
());
expect
(
mockEmbedGroup
).
toHaveBeenCalledTimes
(
2
);
expect
(
mockEmbedGroup
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
propsData
:
{
urls
:
[
`
${
TEST_HOST
}
/1`
,
`
${
TEST_HOST
}
/2`
]
}
}),
);
expect
(
mockEmbedGroup
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
propsData
:
{
urls
:
[
`
${
TEST_HOST
}
/3`
]
}
}),
);
re
turn
renderMetrics
(
getElements
()).
then
(()
=>
{
expect
(
mockEmbedGroup
).
toHaveBeenCalledTimes
(
2
);
expect
(
mockEmbedGroup
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
propsData
:
{
urls
:
[
`
${
TEST_HOST
}
/1`
,
`
${
TEST_HOST
}
/2`
]
}
}),
);
expect
(
mockEmbedGroup
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
propsData
:
{
urls
:
[
`
${
TEST_HOST
}
/3`
]
}
}),
);
}
);
});
});
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