Commit 497e1172 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '207240-snippet-blob-edit-header' into 'master'

Added Blob Edit Header component

See merge request gitlab-org/gitlab!26472
parents 31adccaf cffcdf69
<script>
import { GlFormInput } from '@gitlab/ui';
export default {
components: {
GlFormInput,
},
props: {
value: {
type: String,
required: true,
},
},
data() {
return {
name: this.value,
};
},
};
</script>
<template>
<div class="js-file-title file-title-flex-parent">
<gl-form-input
id="snippet_file_name"
v-model="name"
:placeholder="
s__('Snippets|Give your file a name to add code highlighting, e.g. example.rb for Ruby')
"
name="snippet_file_name"
class="form-control js-snippet-file-name qa-snippet-file-name"
type="text"
@change="$emit('input', name)"
/>
</div>
</template>
...@@ -17,7 +17,7 @@ const initAce = () => { ...@@ -17,7 +17,7 @@ const initAce = () => {
const initMonaco = () => { const initMonaco = () => {
const editorEl = document.getElementById('editor'); const editorEl = document.getElementById('editor');
const contentEl = document.querySelector('.snippet-file-content'); const contentEl = document.querySelector('.snippet-file-content');
const fileNameEl = document.querySelector('.snippet-file-name'); const fileNameEl = document.querySelector('.js-snippet-file-name');
const form = document.querySelector('.snippet-form-holder form'); const form = document.querySelector('.snippet-form-holder form');
editor = new Editor(); editor = new Editor();
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
= f.label :file_name, s_('Snippets|File') = f.label :file_name, s_('Snippets|File')
.file-holder.snippet .file-holder.snippet
.js-file-title.file-title-flex-parent .js-file-title.file-title-flex-parent
= f.text_field :file_name, placeholder: s_("Snippets|Give your file a name to add code highlighting, e.g. example.rb for Ruby"), class: 'form-control snippet-file-name qa-snippet-file-name' = f.text_field :file_name, placeholder: s_("Snippets|Give your file a name to add code highlighting, e.g. example.rb for Ruby"), class: 'form-control js-snippet-file-name qa-snippet-file-name'
.file-content.code .file-content.code
%pre#editor{ data: { 'editor-loading': true } }= @snippet.content %pre#editor{ data: { 'editor-loading': true } }= @snippet.content
= f.hidden_field :content, class: 'snippet-file-content' = f.hidden_field :content, class: 'snippet-file-content'
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Blob Header Editing rendering matches the snapshot 1`] = `
<div
class="js-file-title file-title-flex-parent"
>
<gl-form-input-stub
class="form-control js-snippet-file-name qa-snippet-file-name"
id="snippet_file_name"
name="snippet_file_name"
placeholder="Give your file a name to add code highlighting, e.g. example.rb for Ruby"
type="text"
value="foo.md"
/>
</div>
`;
import { shallowMount } from '@vue/test-utils';
import BlobEditHeader from '~/blob/components/blob_edit_header.vue';
import { GlFormInput } from '@gitlab/ui';
describe('Blob Header Editing', () => {
let wrapper;
const value = 'foo.md';
function createComponent() {
wrapper = shallowMount(BlobEditHeader, {
propsData: {
value,
},
});
}
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('rendering', () => {
it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot();
});
it('contains a form input field', () => {
expect(wrapper.contains(GlFormInput)).toBe(true);
});
});
describe('functionality', () => {
it('emits input event when the blob name is changed', () => {
const inputComponent = wrapper.find(GlFormInput);
const newValue = 'bar.txt';
wrapper.setData({
name: newValue,
});
inputComponent.vm.$emit('change');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().input[0]).toEqual([newValue]);
});
});
});
});
...@@ -27,7 +27,7 @@ describe('Snippet editor', () => { ...@@ -27,7 +27,7 @@ describe('Snippet editor', () => {
setHTMLFixture(` setHTMLFixture(`
<div class="snippet-form-holder"> <div class="snippet-form-holder">
<form> <form>
<input class="snippet-file-name" type="text" value="${name}"> <input class="js-snippet-file-name" type="text" value="${name}">
<input class="snippet-file-content" type="hidden" value="${content}"> <input class="snippet-file-content" type="hidden" value="${content}">
<pre id="editor"></pre> <pre id="editor"></pre>
</form> </form>
...@@ -39,7 +39,7 @@ describe('Snippet editor', () => { ...@@ -39,7 +39,7 @@ describe('Snippet editor', () => {
setUpFixture(name, content); setUpFixture(name, content);
editorEl = document.getElementById('editor'); editorEl = document.getElementById('editor');
contentEl = document.querySelector('.snippet-file-content'); contentEl = document.querySelector('.snippet-file-content');
fileNameEl = document.querySelector('.snippet-file-name'); fileNameEl = document.querySelector('.js-snippet-file-name');
form = document.querySelector('.snippet-form-holder form'); form = document.querySelector('.snippet-form-holder form');
initEditor(); initEditor();
......
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