2021-03-11 19:13:27 +05:30
|
|
|
import Vuex from 'vuex';
|
2022-07-23 23:45:48 +05:30
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
import { suggestionCommitMessage } from '~/diffs/store/getters';
|
2022-07-16 23:28:13 +05:30
|
|
|
import NoteBody from '~/notes/components/note_body.vue';
|
|
|
|
import NoteAwardsList from '~/notes/components/note_awards_list.vue';
|
|
|
|
import NoteForm from '~/notes/components/note_form.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';
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
jest.mock('~/autosave');
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
const createComponent = ({
|
|
|
|
props = {},
|
|
|
|
noteableData = noteableDataMock,
|
|
|
|
notesData = notesDataMock,
|
|
|
|
store = null,
|
|
|
|
} = {}) => {
|
|
|
|
let mockStore;
|
|
|
|
|
|
|
|
if (!store) {
|
|
|
|
mockStore = createStore();
|
|
|
|
|
|
|
|
mockStore.dispatch('setNoteableData', noteableData);
|
|
|
|
mockStore.dispatch('setNotesData', notesData);
|
|
|
|
}
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
return shallowMountExtended(NoteBody, {
|
2022-07-16 23:28:13 +05:30
|
|
|
store: mockStore || store,
|
|
|
|
propsData: {
|
|
|
|
note,
|
|
|
|
canEdit: true,
|
|
|
|
canAwardEmoji: true,
|
|
|
|
isEditing: false,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('issue_note_body component', () => {
|
2022-07-16 23:28:13 +05:30
|
|
|
let wrapper;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-07-16 23:28:13 +05:30
|
|
|
wrapper = createComponent();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the note', () => {
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(wrapper.find('.note-text').html()).toContain(note.note_html);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
it('should render awards list', () => {
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(wrapper.findComponent(NoteAwardsList).exists()).toBe(true);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
describe('isInternalNote', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({ props: { isInternalNote: true } });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe('isEditing', () => {
|
2022-07-16 23:28:13 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent({ props: { isEditing: true } });
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
it('renders edit form', () => {
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(wrapper.findComponent(NoteForm).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
2022-10-11 01:57:18 +05:30
|
|
|
internal | buttonText
|
|
|
|
${false} | ${'Save comment'}
|
|
|
|
${true} | ${'Save internal note'}
|
|
|
|
`('renders save button with text "$buttonText"', ({ internal, buttonText }) => {
|
|
|
|
wrapper = createComponent({ props: { note: { ...note, internal }, isEditing: true } });
|
2022-07-16 23:28:13 +05:30
|
|
|
|
|
|
|
expect(wrapper.findComponent(NoteForm).props('saveButtonTitle')).toBe(buttonText);
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
describe('isInternalNote', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper.setProps({ isInternalNote: true });
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
describe('commitMessage', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const notesStore = notes();
|
|
|
|
|
|
|
|
notesStore.state.notes = {};
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
const store = new Vuex.Store({
|
2021-03-11 19:13:27 +05:30
|
|
|
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
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
wrapper = createComponent({
|
2021-03-11 19:13:27 +05:30
|
|
|
store,
|
2022-07-16 23:28:13 +05:30
|
|
|
props: {
|
2021-03-11 19:13:27 +05:30
|
|
|
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', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const commitMessage = wrapper.findComponent(Suggestions).attributes('defaultcommitmessage');
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
expect(commitMessage).toBe('branch/pathnameuseruser usertonabc11');
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|