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
fad64474
Commit
fad64474
authored
Feb 04, 2020
by
Denys Mishunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Blob header default actions
1/4 components constituting the Blob File header component
parent
56a03c42
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
143 additions
and
0 deletions
+143
-0
app/assets/javascripts/blob/components/blob_header_default_actions.vue
...vascripts/blob/components/blob_header_default_actions.vue
+76
-0
app/assets/javascripts/blob/components/constants.js
app/assets/javascripts/blob/components/constants.js
+3
-0
spec/frontend/blob/components/blob_header_default_actions_spec.js
...ntend/blob/components/blob_header_default_actions_spec.js
+64
-0
No files found.
app/assets/javascripts/blob/components/blob_header_default_actions.vue
0 → 100644
View file @
fad64474
<
script
>
import
{
GlButton
,
GlButtonGroup
,
GlIcon
,
GlTooltipDirective
}
from
'
@gitlab/ui
'
;
import
{
__
}
from
'
~/locale
'
;
import
{
BTN_COPY_CONTENTS_TITLE
,
BTN_DOWNLOAD_TITLE
,
BTN_RAW_TITLE
}
from
'
./constants
'
;
export
default
{
components
:
{
GlIcon
,
GlButtonGroup
,
GlButton
,
},
directives
:
{
GlTooltip
:
GlTooltipDirective
,
},
props
:
{
blob
:
{
type
:
Object
,
required
:
true
,
},
},
computed
:
{
copyBtnTitle
()
{
return
__
(
BTN_COPY_CONTENTS_TITLE
);
},
rawBtnTitle
()
{
return
__
(
BTN_RAW_TITLE
);
},
downloadBtnTitle
()
{
return
__
(
BTN_DOWNLOAD_TITLE
);
},
rawUrl
()
{
return
this
.
blob
.
rawPath
;
},
downloadUrl
()
{
return
`
${
this
.
blob
.
rawPath
}
?inline=false`
;
},
},
methods
:
{
requestCopyContents
()
{
this
.
$emit
(
'
copy
'
);
},
},
};
</
script
>
<
template
>
<gl-button-group>
<gl-button
v-gl-tooltip
.
hover
:aria-label=
"copyBtnTitle"
:title=
"copyBtnTitle"
@
click=
"requestCopyContents"
>
<gl-icon
name=
"copy-to-clipboard"
:size=
"14"
/>
</gl-button>
<gl-button
v-gl-tooltip
.
hover
:aria-label=
"rawBtnTitle"
:title=
"rawBtnTitle"
:href=
"rawUrl"
rel=
"noopener noreferrer"
target=
"_blank"
>
<gl-icon
name=
"doc-code"
:size=
"14"
/>
</gl-button>
<gl-button
v-gl-tooltip
.
hover
:aria-label=
"downloadBtnTitle"
:title=
"downloadBtnTitle"
:href=
"downloadUrl"
rel=
"noopener noreferrer"
target=
"_blank"
>
<gl-icon
name=
"download"
:size=
"14"
/>
</gl-button>
</gl-button-group>
</
template
>
app/assets/javascripts/blob/components/constants.js
0 → 100644
View file @
fad64474
export
const
BTN_COPY_CONTENTS_TITLE
=
'
Copy file contents
'
;
export
const
BTN_RAW_TITLE
=
'
Open raw
'
;
export
const
BTN_DOWNLOAD_TITLE
=
'
Download
'
;
spec/frontend/blob/components/blob_header_default_actions_spec.js
0 → 100644
View file @
fad64474
import
{
mount
}
from
'
@vue/test-utils
'
;
import
BlobHeaderActions
from
'
~/blob/components/blob_header_default_actions.vue
'
;
import
{
BTN_COPY_CONTENTS_TITLE
,
BTN_DOWNLOAD_TITLE
,
BTN_RAW_TITLE
,
}
from
'
~/blob/components/constants
'
;
import
{
GlButtonGroup
,
GlButton
}
from
'
@gitlab/ui
'
;
import
{
Blob
}
from
'
./mock_data
'
;
describe
(
'
Blob Header Default Actions
'
,
()
=>
{
let
wrapper
;
let
btnGroup
;
let
buttons
;
const
hrefPrefix
=
'
http://localhost
'
;
function
createComponent
(
props
=
{})
{
wrapper
=
mount
(
BlobHeaderActions
,
{
propsData
:
{
blob
:
Object
.
assign
({},
Blob
,
props
),
},
});
}
beforeEach
(()
=>
{
createComponent
();
btnGroup
=
wrapper
.
find
(
GlButtonGroup
);
buttons
=
wrapper
.
findAll
(
GlButton
);
});
afterEach
(()
=>
{
wrapper
.
destroy
();
});
describe
(
'
renders
'
,
()
=>
{
it
(
'
gl-button-group component
'
,
()
=>
{
expect
(
btnGroup
.
exists
()).
toBe
(
true
);
});
it
(
'
exactly 3 buttons with predefined actions
'
,
()
=>
{
expect
(
buttons
.
length
).
toBe
(
3
);
[
BTN_COPY_CONTENTS_TITLE
,
BTN_RAW_TITLE
,
BTN_DOWNLOAD_TITLE
].
forEach
((
title
,
i
)
=>
{
expect
(
buttons
.
at
(
i
).
vm
.
$el
.
title
).
toBe
(
title
);
});
});
it
(
'
correct href attribute on RAW button
'
,
()
=>
{
expect
(
buttons
.
at
(
1
).
vm
.
$el
.
href
).
toBe
(
`
${
hrefPrefix
}${
Blob
.
rawPath
}
`
);
});
it
(
'
correct href attribute on Download button
'
,
()
=>
{
expect
(
buttons
.
at
(
2
).
vm
.
$el
.
href
).
toBe
(
`
${
hrefPrefix
}${
Blob
.
rawPath
}
?inline=false`
);
});
});
describe
(
'
functionally
'
,
()
=>
{
it
(
'
emits an event when a Copy Contents button is clicked
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
,
'
$emit
'
);
buttons
.
at
(
0
).
vm
.
$emit
(
'
click
'
);
expect
(
wrapper
.
vm
.
$emit
).
toHaveBeenCalledWith
(
'
copy
'
);
});
});
});
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