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';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2022-07-16 23:28:13 +05:30
|
|
|
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2021-12-11 22:18:48 +05:30
|
|
|
import setWindowLocation from 'helpers/set_window_location_helper';
|
|
|
|
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';
|
2022-11-25 23:54:43 +05:30
|
|
|
import NotesActivityHeader from '~/notes/components/notes_activity_header.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-04-22 19:07:51 +05:30
|
|
|
const TYPE_COMMENT_FORM = 'comment-form';
|
|
|
|
const TYPE_NOTES_LIST = 'notes-list';
|
2022-11-25 23:54:43 +05:30
|
|
|
const TEST_NOTES_FILTER_VALUE = 1;
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
const propsData = {
|
|
|
|
noteableData: mockData.noteableDataMock,
|
|
|
|
notesData: mockData.notesDataMock,
|
|
|
|
userData: mockData.userDataMock,
|
2022-11-25 23:54:43 +05:30
|
|
|
notesFilters: mockData.notesFilters,
|
|
|
|
notesFilterValue: TEST_NOTES_FILTER_VALUE,
|
2020-04-22 19:07:51 +05:30
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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();
|
2022-11-25 23:54:43 +05:30
|
|
|
mountComponent = ({ props = {} } = {}) => {
|
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
|
|
|
},
|
|
|
|
{
|
2022-11-25 23:54:43 +05:30
|
|
|
propsData: {
|
|
|
|
...propsData,
|
|
|
|
...props,
|
|
|
|
},
|
2019-03-02 22:35:43 +05:30
|
|
|
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(() => {
|
2022-07-16 23:28:13 +05:30
|
|
|
setHTMLFixture('<div class="js-discussions-count"></div>');
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.onAny().reply(200, []);
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = mountComponent();
|
2022-08-13 15:12:31 +05:30
|
|
|
return waitForPromises();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
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(() => {
|
2022-07-16 23:28:13 +05:30
|
|
|
setHTMLFixture('<div class="js-discussions-count"></div>');
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
axiosMock.onAny().reply(mockData.getIndividualNoteResponse);
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = mountComponent();
|
2022-08-13 15:12:31 +05:30
|
|
|
return waitForPromises();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
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
|
|
|
});
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
it('should render notes activity header', () => {
|
|
|
|
expect(wrapper.findComponent(NotesActivityHeader).props()).toEqual({
|
|
|
|
notesFilterValue: TEST_NOTES_FILTER_VALUE,
|
|
|
|
notesFilters: mockData.notesFilters,
|
|
|
|
});
|
|
|
|
});
|
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(() => {
|
2022-07-16 23:28:13 +05:30
|
|
|
setHTMLFixture('<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);
|
2022-11-25 23:54:43 +05:30
|
|
|
wrapper = mountComponent({
|
|
|
|
// why: In this integration test, previously we manually set store.state.commentsDisabled
|
|
|
|
// This stopped working when we added `<discussion-filter>` into the component tree.
|
|
|
|
// Let's lean into the integration scope and use a prop that "disables comments".
|
|
|
|
props: {
|
|
|
|
notesFilterValue: constants.HISTORY_ONLY_FILTER_VALUE,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
return waitForPromises();
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
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(() => {
|
2022-07-16 23:28:13 +05:30
|
|
|
setHTMLFixture('<div class="js-discussions-count"></div>');
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
axiosMock.onAny().reply(mockData.getIndividualNoteResponse);
|
|
|
|
store.state.commentsDisabled = false;
|
|
|
|
store.state.isTimelineEnabled = true;
|
|
|
|
|
|
|
|
wrapper = mountComponent();
|
2022-08-13 15:12:31 +05:30
|
|
|
return waitForPromises();
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
afterEach(() => {
|
|
|
|
resetHTMLFixture();
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
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', () => {
|
2022-08-13 15:12:31 +05:30
|
|
|
beforeEach(async () => {
|
2022-07-16 23:28:13 +05:30
|
|
|
setHTMLFixture('<div class="js-discussions-count"></div>');
|
2019-03-02 22:35:43 +05:30
|
|
|
wrapper = mountComponent();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
afterEach(() => {
|
2022-08-13 15:12:31 +05:30
|
|
|
return waitForPromises().then(() => resetHTMLFixture());
|
2022-07-16 23:28:13 +05:30
|
|
|
});
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
it('renders skeleton notes', () => {
|
2022-07-23 23:45:48 +05:30
|
|
|
expect(wrapper.find('.gl-skeleton-loader-default-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();
|
2022-08-13 15:12:31 +05:30
|
|
|
return waitForPromises().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();
|
2022-08-13 15:12:31 +05:30
|
|
|
return waitForPromises().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();
|
2022-08-13 15:12:31 +05:30
|
|
|
return waitForPromises();
|
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();
|
2022-08-13 15:12:31 +05:30
|
|
|
return waitForPromises();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should render markdown docs url', async () => {
|
2019-09-04 21:01:54 +05:30
|
|
|
wrapper.find('.js-note-edit').trigger('click');
|
|
|
|
const { markdownDocsPath } = mockData.notesDataMock;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.find(`.edit-note a[href="${markdownDocsPath}"]`).text().trim()).toEqual(
|
2022-06-21 17:19:12 +05:30
|
|
|
'Markdown',
|
2022-04-04 11:22:00 +05:30
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('should render quick actions docs url', async () => {
|
2019-09-04 21:01:54 +05:30
|
|
|
wrapper.find('.js-note-edit').trigger('click');
|
|
|
|
const { quickActionsDocsPath } = mockData.notesDataMock;
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(wrapper.find(`.edit-note a[href="${quickActionsDocsPath}"]`).text().trim()).toEqual(
|
|
|
|
'quick actions',
|
|
|
|
);
|
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();
|
2022-08-13 15:12:31 +05:30
|
|
|
return waitForPromises();
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
|
|
|
|
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();
|
2022-08-13 15:12:31 +05:30
|
|
|
return waitForPromises();
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should listen hashchange event', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const notesApp = wrapper.findComponent(NotesApp);
|
2019-12-26 22:10:19 +05:30
|
|
|
const hash = 'some dummy hash';
|
2022-11-25 23:54:43 +05:30
|
|
|
jest.spyOn(urlUtility, 'getLocationHash').mockReturnValue(hash);
|
2019-12-26 22:10:19 +05:30
|
|
|
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', () => {
|
2022-08-27 11:52:29 +05:30
|
|
|
const drafts = wrapper.findAllComponents(DraftNote).wrappers;
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
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();
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
expect(axiosMock.history.get[0].params).toEqual({ per_page: 20 });
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
expect(axiosMock.history.get[0].params).toEqual({ per_page: 20 });
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not include extra query params when filter is already set to default', async () => {
|
|
|
|
wrapper = mountWithNotesFilter(constants.DISCUSSION_FILTERS_DEFAULT_VALUE);
|
|
|
|
await waitForPromises();
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
expect(axiosMock.history.get[0].params).toEqual({ per_page: 20 });
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
2022-08-13 15:12:31 +05:30
|
|
|
per_page: 20,
|
2021-12-11 22:18:48 +05:30
|
|
|
persist_filter: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|