Commit 6c504c83 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'dmishunov/276913-snippet-copy-content' into 'master'

Fixed copy contents functionality for snippets

See merge request gitlab-org/gitlab!47646
parents ec218553 587f8738
......@@ -32,6 +32,7 @@ export default {
default: false,
},
},
inject: ['blobHash'],
computed: {
downloadUrl() {
return `${this.rawPath}?inline=false`;
......@@ -39,6 +40,9 @@ export default {
copyDisabled() {
return this.activeViewer === RICH_BLOB_VIEWER;
},
getBlobHashTarget() {
return `[data-blob-hash="${this.blobHash}"]`;
},
},
BTN_COPY_CONTENTS_TITLE,
BTN_DOWNLOAD_TITLE,
......@@ -53,7 +57,7 @@ export default {
:aria-label="$options.BTN_COPY_CONTENTS_TITLE"
:title="$options.BTN_COPY_CONTENTS_TITLE"
:disabled="copyDisabled"
data-clipboard-target="#blob-code-content"
:data-clipboard-target="getBlobHashTarget"
data-testid="copyContentsButton"
icon="copy-to-clipboard"
category="primary"
......
......@@ -51,6 +51,13 @@ export default {
required: true,
},
},
provide() {
return {
blobHash: Math.random()
.toString()
.split('.')[1],
};
},
data() {
return {
blobContent: '',
......
......@@ -9,6 +9,7 @@ export default {
GlIcon,
},
mixins: [ViewerMixin],
inject: ['blobHash'],
data() {
return {
highlightedLine: null,
......@@ -64,7 +65,7 @@ export default {
</a>
</div>
<div class="blob-content">
<pre class="code highlight"><code id="blob-code-content" v-html="content"></code></pre>
<pre class="code highlight"><code :data-blob-hash="blobHash" v-html="content"></code></pre>
</div>
</div>
</template>
---
title: Fixed copy contents functionality for snippets
merge_request: 47646
author:
type: fixed
......@@ -14,8 +14,13 @@ describe('Blob Header Default Actions', () => {
let btnGroup;
let buttons;
const blobHash = 'foo-bar';
function createComponent(propsData = {}) {
wrapper = mount(BlobHeaderActions, {
provide: {
blobHash,
},
propsData: {
rawPath: Blob.rawPath,
...propsData,
......
......@@ -11,7 +11,11 @@ describe('Blob Header Default Actions', () => {
function createComponent(blobProps = {}, options = {}, propsData = {}, shouldMount = false) {
const method = shouldMount ? mount : shallowMount;
const blobHash = 'foo-bar';
wrapper = method.call(this, BlobHeader, {
provide: {
blobHash,
},
propsData: {
blob: { ...Blob, ...blobProps },
...propsData,
......
......@@ -59,7 +59,7 @@ exports[`Blob Simple Viewer component rendering matches the snapshot 1`] = `
class="code highlight"
>
<code
id="blob-code-content"
data-blob-hash="foo-bar"
>
<span
id="LC1"
......
......@@ -5,9 +5,13 @@ import { HIGHLIGHT_CLASS_NAME } from '~/vue_shared/components/blob_viewers/const
describe('Blob Simple Viewer component', () => {
let wrapper;
const contentMock = `<span id="LC1">First</span>\n<span id="LC2">Second</span>\n<span id="LC3">Third</span>`;
const blobHash = 'foo-bar';
function createComponent(content = contentMock) {
wrapper = shallowMount(SimpleViewer, {
provide: {
blobHash,
},
propsData: {
content,
type: 'text',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment