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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

171 lines
4.8 KiB
JavaScript
Raw Normal View History

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';
2022-07-23 23:45:48 +05:30
import { INTERNAL_NOTE_CLASSES } from '~/notes/constants';
2021-03-11 19:13:27 +05:30
import Suggestions from '~/vue_shared/components/markdown/suggestions.vue';
2018-03-17 18:26:18 +05:30
import { noteableDataMock, notesDataMock, note } from '../mock_data';
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
});
afterEach(() => {
2022-07-16 23:28:13 +05:30
wrapper.destroy();
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
it('should not have internal note classes', () => {
expect(wrapper.findByTestId('note-internal-container').classes()).not.toEqual(
INTERNAL_NOTE_CLASSES,
);
});
describe('isInternalNote', () => {
beforeEach(() => {
wrapper = createComponent({ props: { isInternalNote: true } });
});
it('should have internal note classes', () => {
expect(wrapper.findByTestId('note-internal-container').classes()).toEqual(
INTERNAL_NOTE_CLASSES,
);
});
});
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`
confidential | buttonText
${false} | ${'Save comment'}
${true} | ${'Save internal note'}
`('renders save button with text "$buttonText"', ({ confidential, buttonText }) => {
wrapper = createComponent({ props: { note: { ...note, confidential }, isEditing: true } });
expect(wrapper.findComponent(NoteForm).props('saveButtonTitle')).toBe(buttonText);
2018-03-27 19:54:05 +05:30
});
it('adds autosave', () => {
const autosaveKey = `autosave/Note/${note.noteable_type}/${note.id}`;
2022-07-16 23:28:13 +05:30
// While we discourage testing wrapper props
// here we aren't testing a component prop
// but instead an instance object property
// which is defined in `app/assets/javascripts/notes/mixins/autosave.js`
expect(wrapper.vm.autosave.key).toEqual(autosaveKey);
2018-03-27 19:54:05 +05:30
});
2022-07-23 23:45:48 +05:30
describe('isInternalNote', () => {
beforeEach(() => {
wrapper.setProps({ isInternalNote: true });
});
it('should not have internal note classes', () => {
expect(wrapper.findByTestId('note-internal-container').classes()).not.toEqual(
INTERNAL_NOTE_CLASSES,
);
});
});
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', () => {
const commitMessage = wrapper.find(Suggestions).attributes('defaultcommitmessage');
expect(commitMessage).toBe('branch/pathnameuseruser usertonabc11');
});
});
2018-03-17 18:26:18 +05:30
});