2022-09-05 02:12:53 -04:00
|
|
|
import { GlDropdownItem } from '@gitlab/ui';
|
|
|
|
import { mount } from '@vue/test-utils';
|
2022-01-25 07:14:14 -05:00
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import Vuex from 'vuex';
|
2020-02-25 16:09:23 -05:00
|
|
|
import DiscussionCounter from '~/notes/components/discussion_counter.vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import notesModule from '~/notes/stores/modules';
|
2020-02-25 16:09:23 -05:00
|
|
|
import * as types from '~/notes/stores/mutation_types';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { noteableDataMock, discussionMock, notesDataMock, userDataMock } from '../mock_data';
|
2020-02-25 16:09:23 -05:00
|
|
|
|
|
|
|
describe('DiscussionCounter component', () => {
|
|
|
|
let store;
|
|
|
|
let wrapper;
|
2020-09-24 08:09:37 -04:00
|
|
|
let setExpandDiscussionsFn;
|
2020-02-25 16:09:23 -05:00
|
|
|
|
2022-01-21 13:12:45 -05:00
|
|
|
Vue.use(Vuex);
|
2020-02-25 16:09:23 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
window.mrTabs = {};
|
|
|
|
const { state, getters, mutations, actions } = notesModule();
|
2020-09-24 08:09:37 -04:00
|
|
|
setExpandDiscussionsFn = jest.fn().mockImplementation(actions.setExpandDiscussions);
|
2020-02-25 16:09:23 -05:00
|
|
|
|
|
|
|
store = new Vuex.Store({
|
|
|
|
state: {
|
|
|
|
...state,
|
|
|
|
userData: userDataMock,
|
|
|
|
},
|
|
|
|
getters,
|
|
|
|
mutations,
|
2020-09-24 08:09:37 -04:00
|
|
|
actions: {
|
|
|
|
...actions,
|
|
|
|
setExpandDiscussions: setExpandDiscussionsFn,
|
|
|
|
},
|
2020-02-25 16:09:23 -05:00
|
|
|
});
|
|
|
|
store.dispatch('setNoteableData', {
|
|
|
|
...noteableDataMock,
|
|
|
|
create_issue_to_resolve_discussions_path: '/test',
|
|
|
|
});
|
|
|
|
store.dispatch('setNotesData', notesDataMock);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.vm.$destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('has no discussions', () => {
|
|
|
|
it('does not render', () => {
|
2022-09-05 02:12:53 -04:00
|
|
|
wrapper = mount(DiscussionCounter, { store, propsData: { blocksMerge: true } });
|
2020-02-25 16:09:23 -05:00
|
|
|
|
2022-08-17 05:11:44 -04:00
|
|
|
expect(wrapper.findComponent({ ref: 'discussionCounter' }).exists()).toBe(false);
|
2020-02-25 16:09:23 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('has no resolvable discussions', () => {
|
|
|
|
it('does not render', () => {
|
2021-11-16 04:13:21 -05:00
|
|
|
store.commit(types.ADD_OR_UPDATE_DISCUSSIONS, [{ ...discussionMock, resolvable: false }]);
|
2020-02-25 16:09:23 -05:00
|
|
|
store.dispatch('updateResolvableDiscussionsCounts');
|
2022-09-05 02:12:53 -04:00
|
|
|
wrapper = mount(DiscussionCounter, { store, propsData: { blocksMerge: true } });
|
2020-02-25 16:09:23 -05:00
|
|
|
|
2022-08-17 05:11:44 -04:00
|
|
|
expect(wrapper.findComponent({ ref: 'discussionCounter' }).exists()).toBe(false);
|
2020-02-25 16:09:23 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('has resolvable discussions', () => {
|
|
|
|
const updateStore = (note = {}) => {
|
|
|
|
discussionMock.notes[0] = { ...discussionMock.notes[0], ...note };
|
2021-11-16 04:13:21 -05:00
|
|
|
store.commit(types.ADD_OR_UPDATE_DISCUSSIONS, [discussionMock]);
|
2020-02-25 16:09:23 -05:00
|
|
|
store.dispatch('updateResolvableDiscussionsCounts');
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
delete discussionMock.notes[0].resolvable;
|
|
|
|
delete discussionMock.notes[0].resolved;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders', () => {
|
|
|
|
updateStore();
|
2022-09-05 02:12:53 -04:00
|
|
|
wrapper = mount(DiscussionCounter, { store, propsData: { blocksMerge: true } });
|
2020-02-25 16:09:23 -05:00
|
|
|
|
2022-08-17 05:11:44 -04:00
|
|
|
expect(wrapper.findComponent({ ref: 'discussionCounter' }).exists()).toBe(true);
|
2020-02-25 16:09:23 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
2022-05-13 08:08:49 -04:00
|
|
|
blocksMerge | color
|
|
|
|
${true} | ${'gl-bg-orange-50'}
|
|
|
|
${false} | ${'gl-bg-gray-50'}
|
|
|
|
`(
|
|
|
|
'changes background color to $color if blocksMerge is $blocksMerge',
|
|
|
|
({ blocksMerge, color }) => {
|
|
|
|
updateStore();
|
2022-05-16 08:07:51 -04:00
|
|
|
store.state.unresolvedDiscussionsCount = 1;
|
2022-09-05 02:12:53 -04:00
|
|
|
wrapper = mount(DiscussionCounter, { store, propsData: { blocksMerge } });
|
2022-05-13 08:08:49 -04:00
|
|
|
|
|
|
|
expect(wrapper.find('[data-testid="discussions-counter-text"]').classes()).toContain(color);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
title | resolved | groupLength
|
2022-09-05 02:12:53 -04:00
|
|
|
${'not allResolved'} | ${false} | ${2}
|
2022-05-13 08:08:49 -04:00
|
|
|
${'allResolved'} | ${true} | ${1}
|
2022-09-05 02:12:53 -04:00
|
|
|
`('renders correctly if $title', async ({ resolved, groupLength }) => {
|
2020-02-25 16:09:23 -05:00
|
|
|
updateStore({ resolvable: true, resolved });
|
2022-09-05 02:12:53 -04:00
|
|
|
wrapper = mount(DiscussionCounter, { store, propsData: { blocksMerge: true } });
|
|
|
|
await wrapper.find('.dropdown-toggle').trigger('click');
|
2020-02-25 16:09:23 -05:00
|
|
|
|
2022-09-05 02:12:53 -04:00
|
|
|
expect(wrapper.findAllComponents(GlDropdownItem)).toHaveLength(groupLength);
|
2020-02-25 16:09:23 -05:00
|
|
|
});
|
|
|
|
});
|
2020-03-24 08:09:42 -04:00
|
|
|
|
|
|
|
describe('toggle all threads button', () => {
|
|
|
|
let toggleAllButton;
|
2022-09-05 02:12:53 -04:00
|
|
|
const updateStoreWithExpanded = async (expanded) => {
|
2020-03-24 08:09:42 -04:00
|
|
|
const discussion = { ...discussionMock, expanded };
|
2021-11-16 04:13:21 -05:00
|
|
|
store.commit(types.ADD_OR_UPDATE_DISCUSSIONS, [discussion]);
|
2020-03-24 08:09:42 -04:00
|
|
|
store.dispatch('updateResolvableDiscussionsCounts');
|
2022-09-05 02:12:53 -04:00
|
|
|
wrapper = mount(DiscussionCounter, { store, propsData: { blocksMerge: true } });
|
|
|
|
await wrapper.find('.dropdown-toggle').trigger('click');
|
|
|
|
toggleAllButton = wrapper.find('[data-testid="toggle-all-discussions-btn"]');
|
2020-03-24 08:09:42 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => wrapper.destroy());
|
|
|
|
|
2022-09-05 02:12:53 -04:00
|
|
|
it('calls button handler when clicked', async () => {
|
|
|
|
await updateStoreWithExpanded(true);
|
2020-03-24 08:09:42 -04:00
|
|
|
|
2022-09-05 02:12:53 -04:00
|
|
|
toggleAllButton.trigger('click');
|
2020-03-24 08:09:42 -04:00
|
|
|
|
2020-09-24 08:09:37 -04:00
|
|
|
expect(setExpandDiscussionsFn).toHaveBeenCalledTimes(1);
|
2020-03-24 08:09:42 -04:00
|
|
|
});
|
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
it('collapses all discussions if expanded', async () => {
|
2022-09-05 02:12:53 -04:00
|
|
|
await updateStoreWithExpanded(true);
|
2020-03-24 08:09:42 -04:00
|
|
|
|
|
|
|
expect(wrapper.vm.allExpanded).toBe(true);
|
|
|
|
|
2022-09-05 02:12:53 -04:00
|
|
|
toggleAllButton.trigger('click');
|
2020-03-24 08:09:42 -04:00
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.vm.allExpanded).toBe(false);
|
2020-03-24 08:09:42 -04:00
|
|
|
});
|
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
it('expands all discussions if collapsed', async () => {
|
2022-09-05 02:12:53 -04:00
|
|
|
await updateStoreWithExpanded(false);
|
2020-03-24 08:09:42 -04:00
|
|
|
|
|
|
|
expect(wrapper.vm.allExpanded).toBe(false);
|
|
|
|
|
2022-09-05 02:12:53 -04:00
|
|
|
toggleAllButton.trigger('click');
|
2020-03-24 08:09:42 -04:00
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.vm.allExpanded).toBe(true);
|
2020-03-24 08:09:42 -04:00
|
|
|
});
|
|
|
|
});
|
2020-02-25 16:09:23 -05:00
|
|
|
});
|