2021-03-11 19:13:27 +05:30
|
|
|
import { mount, shallowMount } from '@vue/test-utils';
|
2019-12-04 20:38:33 +05:30
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
2021-03-11 19:13:27 +05:30
|
|
|
import $ from 'jquery';
|
2018-03-17 18:26:18 +05:30
|
|
|
import Vue from 'vue';
|
2021-12-11 22:18:48 +05:30
|
|
|
import setWindowLocation from 'helpers/set_window_location_helper';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { setTestTimeout } from 'helpers/timeout';
|
2021-12-11 22:18:48 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-04-29 21:17:54 +05:30
|
|
|
import DraftNote from '~/batch_comments/components/draft_note.vue';
|
|
|
|
import batchComments from '~/batch_comments/stores/modules/batch_comments';
|
2020-01-01 13:55:28 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import * as urlUtility from '~/lib/utils/url_utility';
|
2020-04-22 19:07:51 +05:30
|
|
|
import CommentForm from '~/notes/components/comment_form.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import NotesApp from '~/notes/components/notes_app.vue';
|
2020-04-22 19:07:51 +05:30
|
|
|
import * as constants from '~/notes/constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import createStore from '~/notes/stores';
|
2018-05-09 12:01:36 +05:30
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2019-12-04 20:38:33 +05:30
|
|
|
// TODO: use generated fixture (https://gitlab.com/gitlab-org/gitlab-foss/issues/62491)
|
2020-04-22 19:07:51 +05:30
|
|
|
import OrderedLayout from '~/vue_shared/components/ordered_layout.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import * as mockData from '../mock_data';
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
jest.mock('~/user_popovers', () => jest.fn());
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
setTestTimeout(1000);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
const TYPE_COMMENT_FORM = 'comment-form';
|
|
|
|
const TYPE_NOTES_LIST = 'notes-list';
|
|
|
|
|
|
|
|
const propsData = {
|
|
|
|
noteableData: mockData.noteableDataMock,
|
|
|
|
notesData: mockData.notesDataMock,
|
|
|
|
userData: mockData.userDataMock,
|
|
|
|
};
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('note_app', () => {
|
2019-12-04 20:38:33 +05:30
|
|
|
let axiosMock;
|
2018-03-17 18:26:18 +05:30
|
|
|
let mountComponent;
|
2019-03-02 22:35:43 +05:30
|
|
|
let wrapper;
|
2018-11-08 19:23:39 +05:30
|
|
|
let store;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const findCommentButton = () => wrapper.find('[data-testid="comment-button"]');
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
const getComponentOrder = () => {
|
|
|
|
return wrapper
|
|
|
|
.findAll('#notes-list,.js-comment-form')
|
2021-03-08 18:12:59 +05:30
|
|
|
.wrappers.map((node) => (node.is(CommentForm) ? TYPE_COMMENT_FORM : TYPE_NOTES_LIST));
|
2020-04-22 19:07:51 +05:30
|
|
|
};
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
/**
|
|
|
|
* waits for fetchNotes() to complete
|
|
|
|
*/
|
|
|
|
const waitForDiscussionsRequest = () =>
|
2021-03-08 18:12:59 +05:30
|
|
|
new Promise((resolve) => {
|
2019-09-04 21:01:54 +05:30
|
|
|
const { vm } = wrapper.find(NotesApp);
|
2021-03-08 18:12:59 +05:30
|
|
|
const unwatch = vm.$watch('isFetching', (isFetching) => {
|
2019-09-04 21:01:54 +05:30
|
|
|
if (isFetching) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unwatch();
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
beforeEach(() => {
|
2018-03-27 19:54:05 +05:30
|
|
|
$('body').attr('data-page', 'projects:merge_requests:show');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock = new AxiosMockAdapter(axios);
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
store = createStore();
|
2020-04-22 19:07:51 +05:30
|
|
|
mountComponent = () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
return mount(
|
|
|
|
{
|
|
|
|
components: {
|
|
|
|
NotesApp,
|
|
|
|
},
|
2019-12-26 22:10:19 +05:30
|
|
|
template: `<div class="js-vue-notes-event">
|
|
|
|
<notes-app ref="notesApp" v-bind="$attrs" />
|
|
|
|
</div>`,
|
2019-03-02 22:35:43 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
propsData,
|
|
|
|
store,
|
|
|
|
},
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.destroy();
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.restore();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('set data', () => {
|
|
|
|
beforeEach(() => {
|
2020-01-01 13:55:28 +05:30
|
|
|
setFixtures('<div class="js-discussions-count"></div>');
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.onAny().reply(200, []);
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = mountComponent();
|
2019-09-04 21:01:54 +05:30
|
|
|
return waitForDiscussionsRequest();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should set notes data', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(store.state.notesData).toEqual(mockData.notesDataMock);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should set issue data', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(store.state.noteableData).toEqual(mockData.noteableDataMock);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should set user data', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(store.state.userData).toEqual(mockData.userDataMock);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it('should fetch discussions', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(store.state.discussions).toEqual([]);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
it('updates discussions badge', () => {
|
|
|
|
expect(document.querySelector('.js-discussions-count').textContent).toEqual('0');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('render', () => {
|
|
|
|
beforeEach(() => {
|
2019-07-07 11:18:12 +05:30
|
|
|
setFixtures('<div class="js-discussions-count"></div>');
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.onAny().reply(mockData.getIndividualNoteResponse);
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = mountComponent();
|
2019-09-04 21:01:54 +05:30
|
|
|
return waitForDiscussionsRequest();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it('should render list of notes', () => {
|
2018-11-08 19:23:39 +05:30
|
|
|
const note =
|
|
|
|
mockData.INDIVIDUAL_NOTE_RESPONSE_MAP.GET[
|
2019-12-04 20:38:33 +05:30
|
|
|
'/gitlab-org/gitlab-foss/issues/26/discussions.json'
|
2018-11-08 19:23:39 +05:30
|
|
|
][0].notes[0];
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find('.main-notes-list .note-header-author-name').text().trim()).toEqual(
|
|
|
|
note.author.name,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(wrapper.find('.main-notes-list .note-text').html()).toContain(note.note_html);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render form', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find('.js-main-target-form').element.tagName).toBe('FORM');
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.js-main-target-form textarea').attributes('placeholder')).toEqual(
|
|
|
|
'Write a comment or drag your files here…',
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it('should render form comment button as disabled', () => {
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(findCommentButton().props('disabled')).toEqual(true);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it('updates discussions badge', () => {
|
|
|
|
expect(document.querySelector('.js-discussions-count').textContent).toEqual('2');
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
describe('render with comments disabled', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures('<div class="js-discussions-count"></div>');
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.onAny().reply(mockData.getIndividualNoteResponse);
|
2019-07-07 11:18:12 +05:30
|
|
|
store.state.commentsDisabled = true;
|
|
|
|
wrapper = mountComponent();
|
2019-12-04 20:38:33 +05:30
|
|
|
return waitForDiscussionsRequest();
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it('should not render form when commenting is disabled', () => {
|
|
|
|
expect(wrapper.find('.js-main-target-form').exists()).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it('should render discussion filter note `commentsDisabled` is true', () => {
|
|
|
|
expect(wrapper.find('.js-discussion-filter-note').exists()).toBe(true);
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
describe('timeline view', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setFixtures('<div class="js-discussions-count"></div>');
|
|
|
|
|
|
|
|
axiosMock.onAny().reply(mockData.getIndividualNoteResponse);
|
|
|
|
store.state.commentsDisabled = false;
|
|
|
|
store.state.isTimelineEnabled = true;
|
|
|
|
|
|
|
|
wrapper = mountComponent();
|
|
|
|
return waitForDiscussionsRequest();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render comments form', () => {
|
|
|
|
expect(wrapper.find('.js-main-target-form').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('while fetching data', () => {
|
|
|
|
beforeEach(() => {
|
2020-01-01 13:55:28 +05:30
|
|
|
setFixtures('<div class="js-discussions-count"></div>');
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.onAny().reply(200, []);
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = mountComponent();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
afterEach(() => waitForDiscussionsRequest());
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
it('renders skeleton notes', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.animation-container').exists()).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render form', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find('.js-main-target-form').element.tagName).toBe('FORM');
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.js-main-target-form textarea').attributes('placeholder')).toEqual(
|
|
|
|
'Write a comment or drag your files here…',
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
it('should not update discussions badge (it should be blank)', () => {
|
|
|
|
expect(document.querySelector('.js-discussions-count').textContent).toEqual('');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('update note', () => {
|
|
|
|
describe('individual note', () => {
|
2019-09-04 21:01:54 +05:30
|
|
|
beforeEach(() => {
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.onAny().reply(mockData.getIndividualNoteResponse);
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = mountComponent();
|
2019-09-04 21:01:54 +05:30
|
|
|
return waitForDiscussionsRequest().then(() => {
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.find('.js-note-edit').trigger('click');
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders edit form', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.js-vue-issue-note-form').exists()).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it('calls the store action to update the note', () => {
|
|
|
|
jest.spyOn(axios, 'put').mockImplementation(() => Promise.resolve({ data: {} }));
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.find('.js-vue-issue-note-form').value = 'this is a note';
|
|
|
|
wrapper.find('.js-vue-issue-save').trigger('click');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(axios.put).toHaveBeenCalled();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('discussion note', () => {
|
2019-09-04 21:01:54 +05:30
|
|
|
beforeEach(() => {
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.onAny().reply(mockData.getDiscussionNoteResponse);
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = mountComponent();
|
2019-09-04 21:01:54 +05:30
|
|
|
return waitForDiscussionsRequest().then(() => {
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.find('.js-note-edit').trigger('click');
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders edit form', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(wrapper.find('.js-vue-issue-note-form').exists()).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it('updates the note and resets the edit form', () => {
|
2020-04-08 14:13:33 +05:30
|
|
|
jest.spyOn(axios, 'put').mockImplementation(() => Promise.resolve({ data: {} }));
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.find('.js-vue-issue-note-form').value = 'this is a note';
|
|
|
|
wrapper.find('.js-vue-issue-save').trigger('click');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(axios.put).toHaveBeenCalled();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('new note form', () => {
|
|
|
|
beforeEach(() => {
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.onAny().reply(mockData.getIndividualNoteResponse);
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = mountComponent();
|
2019-09-04 21:01:54 +05:30
|
|
|
return waitForDiscussionsRequest();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render markdown docs url', () => {
|
|
|
|
const { markdownDocsPath } = mockData.notesDataMock;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find(`a[href="${markdownDocsPath}"]`).text().trim()).toEqual('Markdown');
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render quick action docs url', () => {
|
|
|
|
const { quickActionsDocsPath } = mockData.notesDataMock;
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find(`a[href="${quickActionsDocsPath}"]`).text().trim()).toEqual(
|
|
|
|
'quick actions',
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('edit form', () => {
|
|
|
|
beforeEach(() => {
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.onAny().reply(mockData.getIndividualNoteResponse);
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = mountComponent();
|
2019-09-04 21:01:54 +05:30
|
|
|
return waitForDiscussionsRequest();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it('should render markdown docs url', () => {
|
|
|
|
wrapper.find('.js-note-edit').trigger('click');
|
|
|
|
const { markdownDocsPath } = mockData.notesDataMock;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
return Vue.nextTick().then(() => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(wrapper.find(`.edit-note a[href="${markdownDocsPath}"]`).text().trim()).toEqual(
|
|
|
|
'Markdown is supported',
|
|
|
|
);
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it('should not render quick actions docs url', () => {
|
|
|
|
wrapper.find('.js-note-edit').trigger('click');
|
|
|
|
const { quickActionsDocsPath } = mockData.notesDataMock;
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.find(`.edit-note a[href="${quickActionsDocsPath}"]`).exists()).toBe(false);
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
describe('emoji awards', () => {
|
2019-09-04 21:01:54 +05:30
|
|
|
beforeEach(() => {
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.onAny().reply(200, []);
|
2019-09-04 21:01:54 +05:30
|
|
|
wrapper = mountComponent();
|
|
|
|
return waitForDiscussionsRequest();
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
it('dispatches toggleAward after toggleAward event', () => {
|
|
|
|
const toggleAwardEvent = new CustomEvent('toggleAward', {
|
|
|
|
detail: {
|
|
|
|
awardName: 'test',
|
|
|
|
noteId: 1,
|
|
|
|
},
|
|
|
|
});
|
2019-09-04 21:01:54 +05:30
|
|
|
const toggleAwardAction = jest.fn().mockName('toggleAward');
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.vm.$store.hotUpdate({
|
|
|
|
actions: {
|
|
|
|
toggleAward: toggleAwardAction,
|
2019-09-04 21:01:54 +05:30
|
|
|
stopPolling() {},
|
2019-03-02 22:35:43 +05:30
|
|
|
},
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper.vm.$parent.$el.dispatchEvent(toggleAwardEvent);
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
jest.advanceTimersByTime(2);
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(toggleAwardAction).toHaveBeenCalledTimes(1);
|
2019-09-04 21:01:54 +05:30
|
|
|
const [, payload] = toggleAwardAction.mock.calls[0];
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
expect(payload).toEqual({
|
2019-02-15 15:39:39 +05:30
|
|
|
awardName: 'test',
|
|
|
|
noteId: 1,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
describe('mounted', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
axiosMock.onAny().reply(mockData.getIndividualNoteResponse);
|
|
|
|
wrapper = mountComponent();
|
|
|
|
return waitForDiscussionsRequest();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen hashchange event', () => {
|
|
|
|
const notesApp = wrapper.find(NotesApp);
|
|
|
|
const hash = 'some dummy hash';
|
|
|
|
jest.spyOn(urlUtility, 'getLocationHash').mockReturnValueOnce(hash);
|
|
|
|
const setTargetNoteHash = jest.spyOn(notesApp.vm, 'setTargetNoteHash');
|
|
|
|
|
|
|
|
window.dispatchEvent(new Event('hashchange'), hash);
|
|
|
|
|
|
|
|
expect(setTargetNoteHash).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
describe('when sort direction is desc', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store = createStore();
|
|
|
|
store.state.discussionSortOrder = constants.DESC;
|
2022-01-26 12:08:38 +05:30
|
|
|
store.state.isLoading = true;
|
|
|
|
store.state.discussions = [mockData.discussionMock];
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
wrapper = shallowMount(NotesApp, {
|
|
|
|
propsData,
|
|
|
|
store,
|
|
|
|
stubs: {
|
|
|
|
'ordered-layout': OrderedLayout,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('finds CommentForm before notes list', () => {
|
|
|
|
expect(getComponentOrder()).toStrictEqual([TYPE_COMMENT_FORM, TYPE_NOTES_LIST]);
|
|
|
|
});
|
2022-01-26 12:08:38 +05:30
|
|
|
|
|
|
|
it('shows skeleton notes before the loaded discussions', () => {
|
|
|
|
expect(wrapper.find('#notes-list').html()).toMatchSnapshot();
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('when sort direction is asc', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store = createStore();
|
2022-01-26 12:08:38 +05:30
|
|
|
store.state.isLoading = true;
|
|
|
|
store.state.discussions = [mockData.discussionMock];
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
wrapper = shallowMount(NotesApp, {
|
|
|
|
propsData,
|
|
|
|
store,
|
|
|
|
stubs: {
|
|
|
|
'ordered-layout': OrderedLayout,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('finds CommentForm after notes list', () => {
|
|
|
|
expect(getComponentOrder()).toStrictEqual([TYPE_NOTES_LIST, TYPE_COMMENT_FORM]);
|
|
|
|
});
|
2022-01-26 12:08:38 +05:30
|
|
|
|
|
|
|
it('shows skeleton notes after the loaded discussions', () => {
|
|
|
|
expect(wrapper.find('#notes-list').html()).toMatchSnapshot();
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
describe('when multiple draft types are present', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store = createStore();
|
|
|
|
store.registerModule('batchComments', batchComments());
|
|
|
|
store.state.batchComments.drafts = [
|
|
|
|
mockData.draftDiffDiscussion,
|
|
|
|
mockData.draftReply,
|
|
|
|
...mockData.draftComments,
|
|
|
|
];
|
|
|
|
store.state.isLoading = false;
|
|
|
|
wrapper = shallowMount(NotesApp, {
|
|
|
|
propsData,
|
|
|
|
store,
|
|
|
|
stubs: {
|
|
|
|
OrderedLayout,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly finds only draft comments', () => {
|
|
|
|
const drafts = wrapper.findAll(DraftNote).wrappers;
|
|
|
|
|
|
|
|
expect(drafts.map((x) => x.props('draft'))).toEqual(
|
|
|
|
mockData.draftComments.map(({ note }) => expect.objectContaining({ note })),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
describe('fetching discussions', () => {
|
|
|
|
describe('when note anchor is not present', () => {
|
|
|
|
it('does not include extra query params', async () => {
|
|
|
|
wrapper = shallowMount(NotesApp, { propsData, store: createStore() });
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(axiosMock.history.get[0].params).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when note anchor is present', () => {
|
|
|
|
const mountWithNotesFilter = (notesFilter) =>
|
|
|
|
shallowMount(NotesApp, {
|
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
notesData: {
|
|
|
|
...propsData.notesData,
|
|
|
|
notesFilter,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
store: createStore(),
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
setWindowLocation('#note_1');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not include extra query params when filter is undefined', async () => {
|
|
|
|
wrapper = mountWithNotesFilter(undefined);
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(axiosMock.history.get[0].params).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not include extra query params when filter is already set to default', async () => {
|
|
|
|
wrapper = mountWithNotesFilter(constants.DISCUSSION_FILTERS_DEFAULT_VALUE);
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(axiosMock.history.get[0].params).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('includes extra query params when filter is not set to default', async () => {
|
|
|
|
wrapper = mountWithNotesFilter(constants.COMMENTS_ONLY_FILTER_VALUE);
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(axiosMock.history.get[0].params).toEqual({
|
|
|
|
notes_filter: constants.DISCUSSION_FILTERS_DEFAULT_VALUE,
|
|
|
|
persist_filter: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|