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
859e3a72
Commit
859e3a72
authored
Aug 15, 2018
by
Paul Slaughter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EE Port (Resolve "Follow up to "Styling of the MR widget's info and pipeline sections"")
parent
d2989917
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
324 additions
and
75 deletions
+324
-75
app/assets/javascripts/vue_merge_request_widget/components/deployment.vue
...cripts/vue_merge_request_widget/components/deployment.vue
+15
-7
app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.vue
.../vue_merge_request_widget/components/mr_widget_header.vue
+21
-40
app/assets/javascripts/vue_merge_request_widget/components/mr_widget_pipeline.vue
...ue_merge_request_widget/components/mr_widget_pipeline.vue
+11
-4
app/assets/javascripts/vue_merge_request_widget/mr_widget_options.vue
...avascripts/vue_merge_request_widget/mr_widget_options.vue
+1
-0
app/assets/javascripts/vue_shared/components/tooltip_on_truncate.vue
...javascripts/vue_shared/components/tooltip_on_truncate.vue
+67
-0
app/assets/stylesheets/pages/merge_requests.scss
app/assets/stylesheets/pages/merge_requests.scss
+21
-18
changelogs/unreleased/49110-update-mr-widget-styles.yml
changelogs/unreleased/49110-update-mr-widget-styles.yml
+5
-0
locale/gitlab.pot
locale/gitlab.pot
+3
-0
spec/javascripts/helpers/vue_mount_component_helper.js
spec/javascripts/helpers/vue_mount_component_helper.js
+10
-0
spec/javascripts/vue_mr_widget/components/mr_widget_header_spec.js
...scripts/vue_mr_widget/components/mr_widget_header_spec.js
+8
-6
spec/javascripts/vue_shared/components/tooltip_on_truncate_spec.js
...scripts/vue_shared/components/tooltip_on_truncate_spec.js
+162
-0
No files found.
app/assets/javascripts/vue_merge_request_widget/components/deployment.vue
View file @
859e3a72
<
script
>
<
script
>
import
Icon
from
'
~/vue_shared/components/icon.vue
'
;
import
Icon
from
'
~/vue_shared/components/icon.vue
'
;
import
TooltipOnTruncate
from
'
~/vue_shared/components/tooltip_on_truncate.vue
'
;
import
timeagoMixin
from
'
../../vue_shared/mixins/timeago
'
;
import
timeagoMixin
from
'
../../vue_shared/mixins/timeago
'
;
import
tooltip
from
'
../../vue_shared/directives/tooltip
'
;
import
tooltip
from
'
../../vue_shared/directives/tooltip
'
;
import
LoadingButton
from
'
../../vue_shared/components/loading_button.vue
'
;
import
LoadingButton
from
'
../../vue_shared/components/loading_button.vue
'
;
...
@@ -16,6 +17,7 @@ export default {
...
@@ -16,6 +17,7 @@ export default {
MemoryUsage
,
MemoryUsage
,
StatusIcon
,
StatusIcon
,
Icon
,
Icon
,
TooltipOnTruncate
,
},
},
directives
:
{
directives
:
{
tooltip
,
tooltip
,
...
@@ -88,14 +90,20 @@ export default {
...
@@ -88,14 +90,20 @@ export default {
<span>
<span>
Deployed to
Deployed to
</span>
</span>
<a
<tooltip-on-truncate
:href=
"deployment.url"
:title=
"deployment.name"
target=
"_blank"
truncate-target=
"child"
rel=
"noopener noreferrer nofollow"
class=
"deploy-link label-truncate"
class=
"deploy-link js-deploy-meta"
>
>
{{
deployment
.
name
}}
<a
</a>
:href=
"deployment.url"
target=
"_blank"
rel=
"noopener noreferrer nofollow"
class=
"js-deploy-meta"
>
{{
deployment
.
name
}}
</a>
</tooltip-on-truncate>
</
template
>
</
template
>
<span
<span
v-tooltip
v-tooltip
...
...
app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.vue
View file @
859e3a72
<
script
>
<
script
>
import
tooltip
from
'
~/vue_shared/directives/tooltip
'
;
import
_
from
'
underscore
'
;
import
{
n__
}
from
'
~/locale
'
;
import
{
n__
,
s__
,
sprintf
}
from
'
~/locale
'
;
import
{
mergeUrlParams
,
webIDEUrl
}
from
'
~/lib/utils/url_utility
'
;
import
{
mergeUrlParams
,
webIDEUrl
}
from
'
~/lib/utils/url_utility
'
;
import
Icon
from
'
~/vue_shared/components/icon.vue
'
;
import
Icon
from
'
~/vue_shared/components/icon.vue
'
;
import
clipboardButton
from
'
~/vue_shared/components/clipboard_button.vue
'
;
import
clipboardButton
from
'
~/vue_shared/components/clipboard_button.vue
'
;
import
TooltipOnTruncate
from
'
~/vue_shared/components/tooltip_on_truncate.vue
'
;
export
default
{
export
default
{
name
:
'
MRWidgetHeader
'
,
name
:
'
MRWidgetHeader
'
,
directives
:
{
tooltip
,
},
components
:
{
components
:
{
Icon
,
Icon
,
clipboardButton
,
clipboardButton
,
TooltipOnTruncate
,
},
},
props
:
{
props
:
{
mr
:
{
mr
:
{
...
@@ -24,8 +23,12 @@ export default {
...
@@ -24,8 +23,12 @@ export default {
shouldShowCommitsBehindText
()
{
shouldShowCommitsBehindText
()
{
return
this
.
mr
.
divergedCommitsCount
>
0
;
return
this
.
mr
.
divergedCommitsCount
>
0
;
},
},
commitsText
()
{
commitsBehindText
()
{
return
n__
(
'
%d commit behind
'
,
'
%d commits behind
'
,
this
.
mr
.
divergedCommitsCount
);
return
sprintf
(
s__
(
'
mrWidget|The source branch is %{commitsBehindLinkStart}%{commitsBehind}%{commitsBehindLinkEnd} the target branch
'
),
{
commitsBehindLinkStart
:
`<a href="
${
_
.
escape
(
this
.
mr
.
targetBranchPath
)}
">`
,
commitsBehind
:
n__
(
'
%d commit behind
'
,
'
%d commits behind
'
,
this
.
mr
.
divergedCommitsCount
),
commitsBehindLinkEnd
:
'
</a>
'
,
},
false
);
},
},
branchNameClipboardData
()
{
branchNameClipboardData
()
{
// This supports code in app/assets/javascripts/copy_to_clipboard.js that
// This supports code in app/assets/javascripts/copy_to_clipboard.js that
...
@@ -36,12 +39,6 @@ export default {
...
@@ -36,12 +39,6 @@ export default {
gfm
:
`\`
${
this
.
mr
.
sourceBranch
}
\``
,
gfm
:
`\`
${
this
.
mr
.
sourceBranch
}
\``
,
});
});
},
},
isSourceBranchLong
()
{
return
this
.
isBranchTitleLong
(
this
.
mr
.
sourceBranch
);
},
isTargetBranchLong
()
{
return
this
.
isBranchTitleLong
(
this
.
mr
.
targetBranch
);
},
webIdePath
()
{
webIdePath
()
{
return
mergeUrlParams
({
return
mergeUrlParams
({
target_project
:
this
.
mr
.
sourceProjectFullPath
!==
this
.
mr
.
targetProjectFullPath
?
target_project
:
this
.
mr
.
sourceProjectFullPath
!==
this
.
mr
.
targetProjectFullPath
?
...
@@ -49,11 +46,6 @@ export default {
...
@@ -49,11 +46,6 @@ export default {
},
webIDEUrl
(
`/
${
this
.
mr
.
sourceProjectFullPath
}
/merge_requests/
${
this
.
mr
.
iid
}
`
));
},
webIDEUrl
(
`/
${
this
.
mr
.
sourceProjectFullPath
}
/merge_requests/
${
this
.
mr
.
iid
}
`
));
},
},
},
},
methods
:
{
isBranchTitleLong
(
branchTitle
)
{
return
branchTitle
.
length
>
32
;
},
},
};
};
</
script
>
</
script
>
<
template
>
<
template
>
...
@@ -65,30 +57,21 @@ export default {
...
@@ -65,30 +57,21 @@ export default {
<div
class=
"normal"
>
<div
class=
"normal"
>
<strong>
<strong>
{{
s__
(
"
mrWidget|Request to merge
"
)
}}
{{
s__
(
"
mrWidget|Request to merge
"
)
}}
<span
<tooltip-on-truncate
:class=
"
{ 'label-truncated': isSourceBranchLong }"
:title=
"mr.sourceBranch"
:title="isSourceBranchLong ? mr.sourceBranch : ''"
truncate-target=
"child"
:v-tooltip="isSourceBranchLong"
class=
"label-branch label-truncate js-source-branch"
class="label-branch js-source-branch"
data-placement="bottom"
v-html=
"mr.sourceBranchLink"
v-html=
"mr.sourceBranchLink"
>
/><clipboard-button
</span>
<clipboard-button
:text=
"branchNameClipboardData"
:text=
"branchNameClipboardData"
:title=
"__('Copy branch name to clipboard')"
:title=
"__('Copy branch name to clipboard')"
css-class=
"btn-default btn-transparent btn-clipboard"
css-class=
"btn-default btn-transparent btn-clipboard"
/>
/>
{{
s__
(
"
mrWidget|into
"
)
}}
{{
s__
(
"
mrWidget|into
"
)
}}
<tooltip-on-truncate
<span
:title=
"mr.targetBranch"
:v-tooltip=
"isTargetBranchLong"
truncate-target=
"child"
:class=
"
{ 'label-truncatedtooltip': isTargetBranchLong }"
class=
"label-branch label-truncate"
:title="isTargetBranchLong ? mr.targetBranch : ''"
class="label-branch"
data-placement="bottom"
>
>
<a
<a
:href=
"mr.targetBranchTreePath"
:href=
"mr.targetBranchTreePath"
...
@@ -96,15 +79,13 @@ export default {
...
@@ -96,15 +79,13 @@ export default {
>
>
{{
mr
.
targetBranch
}}
{{
mr
.
targetBranch
}}
</a>
</a>
</
span
>
</
tooltip-on-truncate
>
</strong>
</strong>
<div
<div
v-if=
"shouldShowCommitsBehindText"
v-if=
"shouldShowCommitsBehindText"
class=
"diverged-commits-count"
class=
"diverged-commits-count"
v-html=
"commitsBehindText"
>
>
<span
class=
"monospace"
>
{{
mr
.
sourceBranch
}}
</span>
is
{{
commitsText
}}
<span
class=
"monospace"
>
{{
mr
.
targetBranch
}}
</span>
</div>
</div>
</div>
</div>
...
...
app/assets/javascripts/vue_merge_request_widget/components/mr_widget_pipeline.vue
View file @
859e3a72
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
PipelineStage
from
'
~/pipelines/components/stage.vue
'
;
import
PipelineStage
from
'
~/pipelines/components/stage.vue
'
;
import
CiIcon
from
'
~/vue_shared/components/ci_icon.vue
'
;
import
CiIcon
from
'
~/vue_shared/components/ci_icon.vue
'
;
import
Icon
from
'
~/vue_shared/components/icon.vue
'
;
import
Icon
from
'
~/vue_shared/components/icon.vue
'
;
import
TooltipOnTruncate
from
'
~/vue_shared/components/tooltip_on_truncate.vue
'
;
import
LinkedPipelinesMiniList
from
'
ee/vue_shared/components/linked_pipelines_mini_list.vue
'
;
import
LinkedPipelinesMiniList
from
'
ee/vue_shared/components/linked_pipelines_mini_list.vue
'
;
export
default
{
export
default
{
...
@@ -11,6 +12,7 @@ export default {
...
@@ -11,6 +12,7 @@ export default {
PipelineStage
,
PipelineStage
,
CiIcon
,
CiIcon
,
Icon
,
Icon
,
TooltipOnTruncate
,
LinkedPipelinesMiniList
,
LinkedPipelinesMiniList
,
},
},
props
:
{
props
:
{
...
@@ -32,6 +34,10 @@ export default {
...
@@ -32,6 +34,10 @@ export default {
type
:
String
,
type
:
String
,
required
:
false
,
required
:
false
,
},
},
sourceBranch
:
{
type
:
String
,
required
:
false
,
},
},
},
computed
:
{
computed
:
{
hasPipeline
()
{
hasPipeline
()
{
...
@@ -121,11 +127,12 @@ export default {
...
@@ -121,11 +127,12 @@ export default {
>
>
{{
pipeline
.
commit
.
short_id
}}
</a>
{{
pipeline
.
commit
.
short_id
}}
</a>
on
on
<span
<tooltip-on-truncate
class=
"label-branch"
:title=
"sourceBranch"
truncate-target=
"child"
class=
"label-branch label-truncate"
v-html=
"sourceBranchLink"
v-html=
"sourceBranchLink"
>
/>
</span>
</
template
>
</
template
>
</div>
</div>
<div
<div
...
...
app/assets/javascripts/vue_merge_request_widget/mr_widget_options.vue
View file @
859e3a72
...
@@ -255,6 +255,7 @@ export default {
...
@@ -255,6 +255,7 @@ export default {
:pipeline=
"mr.pipeline"
:pipeline=
"mr.pipeline"
:ci-status=
"mr.ciStatus"
:ci-status=
"mr.ciStatus"
:has-ci=
"mr.hasCI"
:has-ci=
"mr.hasCI"
:source-branch=
"mr.sourceBranch"
:source-branch-link=
"mr.sourceBranchLink"
:source-branch-link=
"mr.sourceBranchLink"
/>
/>
<deployment
<deployment
...
...
app/assets/javascripts/vue_shared/components/tooltip_on_truncate.vue
0 → 100644
View file @
859e3a72
<
script
>
import
_
from
'
underscore
'
;
import
tooltip
from
'
../directives/tooltip
'
;
export
default
{
directives
:
{
tooltip
,
},
props
:
{
title
:
{
type
:
String
,
required
:
false
,
default
:
''
,
},
placement
:
{
type
:
String
,
required
:
false
,
default
:
'
top
'
,
},
truncateTarget
:
{
type
:
[
String
,
Function
],
required
:
false
,
default
:
''
,
},
},
data
()
{
return
{
showTooltip
:
false
,
};
},
mounted
()
{
const
target
=
this
.
selectTarget
();
if
(
target
&&
target
.
scrollWidth
>
target
.
offsetWidth
)
{
this
.
showTooltip
=
true
;
}
},
methods
:
{
selectTarget
()
{
if
(
_
.
isFunction
(
this
.
truncateTarget
))
{
return
this
.
truncateTarget
(
this
.
$el
);
}
else
if
(
this
.
truncateTarget
===
'
child
'
)
{
return
this
.
$el
.
childNodes
[
0
];
}
return
this
.
$el
;
},
},
};
</
script
>
<
template
>
<span
v-tooltip
v-if=
"showTooltip"
:title=
"title"
:data-placement=
"placement"
class=
"js-show-tooltip"
>
<slot></slot>
</span>
<span
v-else
>
<slot></slot>
</span>
</
template
>
app/assets/stylesheets/pages/merge_requests.scss
View file @
859e3a72
...
@@ -195,6 +195,7 @@
...
@@ -195,6 +195,7 @@
.ci-widget-content
{
.ci-widget-content
{
display
:
flex
;
display
:
flex
;
align-items
:
center
;
align-items
:
center
;
flex
:
1
;
}
}
}
}
...
@@ -222,6 +223,7 @@
...
@@ -222,6 +223,7 @@
.normal
{
.normal
{
flex
:
1
;
flex
:
1
;
flex-basis
:
auto
;
}
}
.capitalize
{
.capitalize
{
...
@@ -235,22 +237,23 @@
...
@@ -235,22 +237,23 @@
font-weight
:
normal
;
font-weight
:
normal
;
overflow
:
hidden
;
overflow
:
hidden
;
word-break
:
break-all
;
word-break
:
break-all
;
}
&
.label-truncated
{
.deploy-link
,
position
:
relative
;
.label-branch
{
display
:
inline-block
;
&
.label-truncate
{
width
:
250px
;
// NOTE: This selector targets its children because some of the HTML comes from
margin-bottom
:
-3px
;
// 'source_branch_link'. Once this external HTML is no longer used, we could
white-space
:
nowrap
;
// simplify this.
text-overflow
:
clip
;
>
a
,
line-height
:
14px
;
>
span
{
display
:
inline-block
;
&
:
:
after
{
max-width
:
12
.5em
;
position
:
absolute
;
margin-bottom
:
-3px
;
content
:
'...'
;
white-space
:
nowrap
;
right
:
0
;
text-overflow
:
ellipsis
;
font-family
:
$regular-font
;
line-height
:
14px
;
background-color
:
$gray-light
;
overflow
:
hidden
;
}
}
}
}
}
}
...
@@ -582,7 +585,7 @@
...
@@ -582,7 +585,7 @@
@include
media-breakpoint-down
(
md
)
{
@include
media-breakpoint-down
(
md
)
{
flex-direction
:
column
;
flex-direction
:
column
;
align-items
:
flex-start
;
align-items
:
stretch
;
.branch-actions
{
.branch-actions
{
margin-top
:
16px
;
margin-top
:
16px
;
...
@@ -593,13 +596,13 @@
...
@@ -593,13 +596,13 @@
.branch-actions
{
.branch-actions
{
align-self
:
center
;
align-self
:
center
;
margin-left
:
$gl-padding
;
margin-left
:
$gl-padding
;
white-space
:
nowrap
;
}
}
}
}
}
}
.diverged-commits-count
{
.diverged-commits-count
{
color
:
$gl-text-color-secondary
;
color
:
$gl-text-color-secondary
;
font-size
:
12px
;
}
}
}
}
...
@@ -918,7 +921,7 @@
...
@@ -918,7 +921,7 @@
flex
:
1
;
flex
:
1
;
flex-direction
:
row
;
flex-direction
:
row
;
@include
media-breakpoint-down
(
md
)
{
@include
media-breakpoint-down
(
sm
)
{
flex-direction
:
column
;
flex-direction
:
column
;
.stage-cell
.stage-container
{
.stage-cell
.stage-container
{
...
...
changelogs/unreleased/49110-update-mr-widget-styles.yml
0 → 100644
View file @
859e3a72
---
title
:
Truncate branch names and update "commits behind" text in MR page
merge_request
:
21206
author
:
type
:
changed
locale/gitlab.pot
View file @
859e3a72
...
@@ -8608,6 +8608,9 @@ msgstr ""
...
@@ -8608,6 +8608,9 @@ msgstr ""
msgid "mrWidget|The source branch has been removed"
msgid "mrWidget|The source branch has been removed"
msgstr ""
msgstr ""
msgid "mrWidget|The source branch is %{commitsBehindLinkStart}%{commitsBehind}%{commitsBehindLinkEnd} the target branch"
msgstr ""
msgid "mrWidget|The source branch is being removed"
msgid "mrWidget|The source branch is being removed"
msgstr ""
msgstr ""
...
...
spec/javascripts/helpers/vue_mount_component_helper.js
View file @
859e3a72
import
Vue
from
'
vue
'
;
const
mountComponent
=
(
Component
,
props
=
{},
el
=
null
)
=>
const
mountComponent
=
(
Component
,
props
=
{},
el
=
null
)
=>
new
Component
({
new
Component
({
propsData
:
props
,
propsData
:
props
,
...
@@ -25,4 +27,12 @@ export const mountComponentWithSlots = (Component, { props, slots }) => {
...
@@ -25,4 +27,12 @@ export const mountComponentWithSlots = (Component, { props, slots }) => {
return
component
.
$mount
();
return
component
.
$mount
();
};
};
/**
* Mount a component with the given render method.
*
* This helps with inserting slots that need to be compiled.
*/
export
const
mountComponentWithRender
=
(
render
,
el
=
null
)
=>
mountComponent
(
Vue
.
extend
({
render
}),
{},
el
);
export
default
mountComponent
;
export
default
mountComponent
;
spec/javascripts/vue_mr_widget/components/mr_widget_header_spec.js
View file @
859e3a72
...
@@ -45,7 +45,7 @@ describe('MRWidgetHeader', () => {
...
@@ -45,7 +45,7 @@ describe('MRWidgetHeader', () => {
});
});
});
});
describe
(
'
commitsText
'
,
()
=>
{
describe
(
'
commits
Behind
Text
'
,
()
=>
{
it
(
'
returns singular when there is one commit
'
,
()
=>
{
it
(
'
returns singular when there is one commit
'
,
()
=>
{
vm
=
mountComponent
(
Component
,
{
vm
=
mountComponent
(
Component
,
{
mr
:
{
mr
:
{
...
@@ -53,11 +53,12 @@ describe('MRWidgetHeader', () => {
...
@@ -53,11 +53,12 @@ describe('MRWidgetHeader', () => {
sourceBranch
:
'
mr-widget-refactor
'
,
sourceBranch
:
'
mr-widget-refactor
'
,
sourceBranchLink
:
'
<a href="/foo/bar/mr-widget-refactor">Link</a>
'
,
sourceBranchLink
:
'
<a href="/foo/bar/mr-widget-refactor">Link</a>
'
,
targetBranch
:
'
master
'
,
targetBranch
:
'
master
'
,
targetBranchPath
:
'
/foo/bar/master
'
,
statusPath
:
'
abc
'
,
statusPath
:
'
abc
'
,
},
},
});
});
expect
(
vm
.
commits
Text
).
toEqual
(
'
1 commit behind
'
);
expect
(
vm
.
commits
BehindText
).
toEqual
(
'
The source branch is <a href="/foo/bar/master">1 commit behind</a> the target branch
'
);
});
});
it
(
'
returns plural when there is more than one commit
'
,
()
=>
{
it
(
'
returns plural when there is more than one commit
'
,
()
=>
{
...
@@ -67,11 +68,12 @@ describe('MRWidgetHeader', () => {
...
@@ -67,11 +68,12 @@ describe('MRWidgetHeader', () => {
sourceBranch
:
'
mr-widget-refactor
'
,
sourceBranch
:
'
mr-widget-refactor
'
,
sourceBranchLink
:
'
<a href="/foo/bar/mr-widget-refactor">Link</a>
'
,
sourceBranchLink
:
'
<a href="/foo/bar/mr-widget-refactor">Link</a>
'
,
targetBranch
:
'
master
'
,
targetBranch
:
'
master
'
,
targetBranchPath
:
'
/foo/bar/master
'
,
statusPath
:
'
abc
'
,
statusPath
:
'
abc
'
,
},
},
});
});
expect
(
vm
.
commits
Text
).
toEqual
(
'
2 commits behind
'
);
expect
(
vm
.
commits
BehindText
).
toEqual
(
'
The source branch is <a href="/foo/bar/master">2 commits behind</a> the target branch
'
);
});
});
});
});
});
});
...
@@ -280,9 +282,9 @@ describe('MRWidgetHeader', () => {
...
@@ -280,9 +282,9 @@ describe('MRWidgetHeader', () => {
});
});
it
(
'
renders diverged commits info
'
,
()
=>
{
it
(
'
renders diverged commits info
'
,
()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
.diverged-commits-count
'
).
textContent
).
to
Match
(
expect
(
vm
.
$el
.
querySelector
(
'
.diverged-commits-count
'
).
textContent
).
to
Equal
(
'
The source branch is 12 commits behind the target branch
'
);
/
(
mr-widget-refactor
[\s\S]
+
?
is 12 commits behind
[\s\S]
+
?
master
)
/
,
expect
(
vm
.
$el
.
querySelector
(
'
.diverged-commits-count a
'
).
textContent
).
toEqual
(
'
12 commits behind
'
);
);
expect
(
vm
.
$el
.
querySelector
(
'
.diverged-commits-count a
'
)).
toHaveAttr
(
'
href
'
,
vm
.
mr
.
targetBranchPath
);
});
});
});
});
});
});
...
...
spec/javascripts/vue_shared/components/tooltip_on_truncate_spec.js
0 → 100644
View file @
859e3a72
import
{
mountComponentWithRender
}
from
'
spec/helpers/vue_mount_component_helper
'
;
import
TooltipOnTruncate
from
'
~/vue_shared/components/tooltip_on_truncate.vue
'
;
const
TEST_TITLE
=
'
lorem-ipsum-dolar-sit-amit-consectur-adipiscing-elit-sed-do
'
;
const
CLASS_SHOW_TOOLTIP
=
'
js-show-tooltip
'
;
const
STYLE_TRUNCATED
=
{
display
:
'
inline-block
'
,
'
max-width
'
:
'
20px
'
,
};
const
STYLE_NORMAL
=
{
display
:
'
inline-block
'
,
'
max-width
'
:
'
1000px
'
,
};
function
mountTooltipOnTruncate
(
options
,
createChildren
)
{
return
mountComponentWithRender
(
h
=>
h
(
TooltipOnTruncate
,
options
,
createChildren
(
h
)),
'
#app
'
);
}
describe
(
'
TooltipOnTruncate component
'
,
()
=>
{
let
vm
;
beforeEach
(()
=>
{
const
el
=
document
.
createElement
(
'
div
'
);
el
.
id
=
'
app
'
;
document
.
body
.
appendChild
(
el
);
});
afterEach
(()
=>
{
vm
.
$destroy
();
});
describe
(
'
with default target
'
,
()
=>
{
it
(
'
renders tooltip if truncated
'
,
done
=>
{
const
options
=
{
style
:
STYLE_TRUNCATED
,
props
:
{
title
:
TEST_TITLE
,
},
};
vm
=
mountTooltipOnTruncate
(
options
,
()
=>
[
TEST_TITLE
]);
vm
.
$nextTick
()
.
then
(()
=>
{
expect
(
vm
.
$el
).
toHaveClass
(
CLASS_SHOW_TOOLTIP
);
expect
(
vm
.
$el
).
toHaveData
(
'
original-title
'
,
TEST_TITLE
);
expect
(
vm
.
$el
).
toHaveData
(
'
placement
'
,
'
top
'
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
does not render tooltip if normal
'
,
done
=>
{
const
options
=
{
style
:
STYLE_NORMAL
,
props
:
{
title
:
TEST_TITLE
,
},
};
vm
=
mountTooltipOnTruncate
(
options
,
()
=>
[
TEST_TITLE
]);
vm
.
$nextTick
()
.
then
(()
=>
{
expect
(
vm
.
$el
).
not
.
toHaveClass
(
CLASS_SHOW_TOOLTIP
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
describe
(
'
with child target
'
,
()
=>
{
it
(
'
renders tooltip if truncated
'
,
done
=>
{
const
options
=
{
style
:
STYLE_NORMAL
,
props
:
{
title
:
TEST_TITLE
,
truncateTarget
:
'
child
'
,
},
};
vm
=
mountTooltipOnTruncate
(
options
,
(
h
)
=>
[
h
(
'
a
'
,
{
style
:
STYLE_TRUNCATED
},
TEST_TITLE
),
]);
vm
.
$nextTick
()
.
then
(()
=>
{
expect
(
vm
.
$el
).
toHaveClass
(
CLASS_SHOW_TOOLTIP
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
it
(
'
does not render tooltip if normal
'
,
done
=>
{
const
options
=
{
props
:
{
title
:
TEST_TITLE
,
truncateTarget
:
'
child
'
,
},
};
vm
=
mountTooltipOnTruncate
(
options
,
(
h
)
=>
[
h
(
'
a
'
,
{
style
:
STYLE_NORMAL
},
TEST_TITLE
),
]);
vm
.
$nextTick
()
.
then
(()
=>
{
expect
(
vm
.
$el
).
not
.
toHaveClass
(
CLASS_SHOW_TOOLTIP
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
describe
(
'
with fn target
'
,
()
=>
{
it
(
'
renders tooltip if truncated
'
,
done
=>
{
const
options
=
{
style
:
STYLE_NORMAL
,
props
:
{
title
:
TEST_TITLE
,
truncateTarget
:
(
el
)
=>
el
.
childNodes
[
1
],
},
};
vm
=
mountTooltipOnTruncate
(
options
,
(
h
)
=>
[
h
(
'
a
'
,
{
style
:
STYLE_NORMAL
},
TEST_TITLE
),
h
(
'
span
'
,
{
style
:
STYLE_TRUNCATED
},
TEST_TITLE
),
]);
vm
.
$nextTick
()
.
then
(()
=>
{
expect
(
vm
.
$el
).
toHaveClass
(
CLASS_SHOW_TOOLTIP
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
describe
(
'
placement
'
,
()
=>
{
it
(
'
sets data-placement when tooltip is rendered
'
,
done
=>
{
const
options
=
{
props
:
{
title
:
TEST_TITLE
,
truncateTarget
:
'
child
'
,
placement
:
'
bottom
'
,
},
};
vm
=
mountTooltipOnTruncate
(
options
,
(
h
)
=>
[
h
(
'
a
'
,
{
style
:
STYLE_TRUNCATED
},
TEST_TITLE
),
]);
vm
.
$nextTick
()
.
then
(()
=>
{
expect
(
vm
.
$el
).
toHaveClass
(
CLASS_SHOW_TOOLTIP
);
expect
(
vm
.
$el
).
toHaveData
(
'
placement
'
,
options
.
props
.
placement
);
})
.
then
(
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