debian-mirror-gitlab/spec/frontend/notes/components/note_body_spec.js

119 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2018-03-17 18:26:18 +05:30
import Vue from 'vue';
2021-03-11 19:13:27 +05:30
import Vuex from 'vuex';
import { suggestionCommitMessage } from '~/diffs/store/getters';
2018-03-17 18:26:18 +05:30
import noteBody from '~/notes/components/note_body.vue';
2021-03-11 19:13:27 +05:30
import createStore from '~/notes/stores';
import notes from '~/notes/stores/modules/index';
import Suggestions from '~/vue_shared/components/markdown/suggestions.vue';
2018-03-17 18:26:18 +05:30
import { noteableDataMock, notesDataMock, note } from '../mock_data';
describe('issue_note_body component', () => {
2018-11-08 19:23:39 +05:30
let store;
2018-03-17 18:26:18 +05:30
let vm;
beforeEach(() => {
const Component = Vue.extend(noteBody);
2018-11-08 19:23:39 +05:30
store = createStore();
2018-03-17 18:26:18 +05:30
store.dispatch('setNoteableData', noteableDataMock);
store.dispatch('setNotesData', notesDataMock);
vm = new Component({
store,
propsData: {
note,
canEdit: true,
2018-05-09 12:01:36 +05:30
canAwardEmoji: true,
2018-03-17 18:26:18 +05:30
},
}).$mount();
});
afterEach(() => {
vm.$destroy();
});
it('should render the note', () => {
expect(vm.$el.querySelector('.note-text').innerHTML).toEqual(note.note_html);
});
2018-03-27 19:54:05 +05:30
it('should render awards list', () => {
expect(vm.$el.querySelector('.js-awards-block button [data-name="baseball"]')).not.toBeNull();
expect(vm.$el.querySelector('.js-awards-block button [data-name="bath_tone3"]')).not.toBeNull();
});
2018-03-17 18:26:18 +05:30
2018-03-27 19:54:05 +05:30
describe('isEditing', () => {
2021-03-08 18:12:59 +05:30
beforeEach((done) => {
2018-03-27 19:54:05 +05:30
vm.isEditing = true;
Vue.nextTick(done);
2018-03-17 18:26:18 +05:30
});
2018-03-27 19:54:05 +05:30
it('renders edit form', () => {
expect(vm.$el.querySelector('textarea.js-task-list-field')).not.toBeNull();
});
it('adds autosave', () => {
const autosaveKey = `autosave/Note/${note.noteable_type}/${note.id}`;
expect(vm.autosave).toExist();
expect(vm.autosave.key).toEqual(autosaveKey);
});
2018-03-17 18:26:18 +05:30
});
2021-03-11 19:13:27 +05:30
describe('commitMessage', () => {
let wrapper;
Vue.use(Vuex);
beforeEach(() => {
const notesStore = notes();
notesStore.state.notes = {};
store = new Vuex.Store({
modules: {
notes: notesStore,
diffs: {
namespaced: true,
state: {
defaultSuggestionCommitMessage:
'%{branch_name}%{project_path}%{project_name}%{username}%{user_full_name}%{file_paths}%{suggestions_count}%{files_count}',
},
getters: { suggestionCommitMessage },
},
2021-04-29 21:17:54 +05:30
page: {
namespaced: true,
state: {
mrMetadata: {
branch_name: 'branch',
project_path: '/path',
project_name: 'name',
username: 'user',
user_full_name: 'user userton',
},
},
},
2021-03-11 19:13:27 +05:30
},
});
wrapper = shallowMount(noteBody, {
store,
propsData: {
note: { ...note, suggestions: [12345] },
canEdit: true,
file: { file_path: 'abc' },
},
});
});
it('passes the correct default placeholder commit message for a suggestion to the suggestions component', () => {
const commitMessage = wrapper.find(Suggestions).attributes('defaultcommitmessage');
expect(commitMessage).toBe('branch/pathnameuseruser usertonabc11');
});
});
2018-03-17 18:26:18 +05:30
});