Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-22 09:09:36 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-22 09:09:36 +0300
commitdc90a96501705c4ed40a903e1c463af4e260712f (patch)
tree5ebf5fd6686704b7569c33c8ad1ae735c1ab4cf6 /spec/frontend/notes/components
parenta25809b2e5274fcd3251c79171cf1bb7d35f34b3 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/notes/components')
-rw-r--r--spec/frontend/notes/components/discussion_filter_spec.js81
-rw-r--r--spec/frontend/notes/components/sort_discussion_spec.js102
2 files changed, 71 insertions, 112 deletions
diff --git a/spec/frontend/notes/components/discussion_filter_spec.js b/spec/frontend/notes/components/discussion_filter_spec.js
index 27206bddbfc..ed9fc47540d 100644
--- a/spec/frontend/notes/components/discussion_filter_spec.js
+++ b/spec/frontend/notes/components/discussion_filter_spec.js
@@ -8,7 +8,14 @@ import createEventHub from '~/helpers/event_hub_factory';
import axios from '~/lib/utils/axios_utils';
import DiscussionFilter from '~/notes/components/discussion_filter.vue';
-import { DISCUSSION_FILTERS_DEFAULT_VALUE, DISCUSSION_FILTER_TYPES } from '~/notes/constants';
+import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
+import Tracking from '~/tracking';
+import {
+ DISCUSSION_FILTERS_DEFAULT_VALUE,
+ DISCUSSION_FILTER_TYPES,
+ ASC,
+ DESC,
+} from '~/notes/constants';
import notesModule from '~/notes/stores/modules';
import { discussionFiltersMock, discussionMock } from '../mock_data';
@@ -28,6 +35,8 @@ describe('DiscussionFilter component', () => {
const findFilter = (filterType) =>
wrapper.find(`.dropdown-item[data-filter-type="${filterType}"]`);
+ const findLocalStorageSync = () => wrapper.findComponent(LocalStorageSync);
+
const mountComponent = () => {
const discussions = [
{
@@ -68,6 +77,7 @@ describe('DiscussionFilter component', () => {
mock.onGet(DISCUSSION_PATH).reply(200, '');
window.mrTabs = undefined;
wrapper = mountComponent();
+ jest.spyOn(Tracking, 'event');
});
afterEach(() => {
@@ -75,6 +85,65 @@ describe('DiscussionFilter component', () => {
mock.restore();
});
+ describe('default', () => {
+ beforeEach(() => {
+ jest.spyOn(store, 'dispatch').mockImplementation();
+ });
+
+ it('has local storage sync with the correct props', () => {
+ expect(findLocalStorageSync().props('asString')).toBe(true);
+ });
+
+ it('calls setDiscussionSortDirection when update is emitted', () => {
+ findLocalStorageSync().vm.$emit('input', ASC);
+
+ expect(store.dispatch).toHaveBeenCalledWith('setDiscussionSortDirection', { direction: ASC });
+ });
+ });
+
+ describe('when asc', () => {
+ beforeEach(() => {
+ jest.spyOn(store, 'dispatch').mockImplementation();
+ });
+
+ describe('when the dropdown is clicked', () => {
+ it('calls the right actions', () => {
+ wrapper.find('.js-newest-first').vm.$emit('click');
+
+ expect(store.dispatch).toHaveBeenCalledWith('setDiscussionSortDirection', {
+ direction: DESC,
+ });
+ expect(Tracking.event).toHaveBeenCalledWith(undefined, 'change_discussion_sort_direction', {
+ property: DESC,
+ });
+ });
+ });
+ });
+
+ describe('when desc', () => {
+ beforeEach(() => {
+ store.state.discussionSortOrder = DESC;
+ jest.spyOn(store, 'dispatch').mockImplementation();
+ });
+
+ describe('when the dropdown item is clicked', () => {
+ it('calls the right actions', () => {
+ wrapper.find('.js-oldest-first').vm.$emit('click');
+
+ expect(store.dispatch).toHaveBeenCalledWith('setDiscussionSortDirection', {
+ direction: ASC,
+ });
+ expect(Tracking.event).toHaveBeenCalledWith(undefined, 'change_discussion_sort_direction', {
+ property: ASC,
+ });
+ });
+
+ it('sets is-checked to true on the active button in the dropdown', () => {
+ expect(wrapper.find('.js-newest-first').props('isChecked')).toBe(true);
+ });
+ });
+ });
+
it('renders the all filters', () => {
expect(wrapper.findAll('.discussion-filter-container .dropdown-item').length).toBe(
discussionFiltersMock.length,
@@ -82,7 +151,7 @@ describe('DiscussionFilter component', () => {
});
it('renders the default selected item', () => {
- expect(wrapper.find('#discussion-filter-dropdown .dropdown-item').text().trim()).toBe(
+ expect(wrapper.find('.discussion-filter-container .dropdown-item').text().trim()).toBe(
discussionFiltersMock[0].title,
);
});
@@ -127,14 +196,6 @@ describe('DiscussionFilter component', () => {
expect(wrapper.vm.$store.state.commentsDisabled).toBe(false);
});
- it('renders a dropdown divider for the default filter', () => {
- const defaultFilter = wrapper.findAll(
- `.discussion-filter-container .dropdown-item-wrapper > *`,
- );
-
- expect(defaultFilter.at(1).classes('gl-new-dropdown-divider')).toBe(true);
- });
-
describe('Merge request tabs', () => {
eventHub = createEventHub();
diff --git a/spec/frontend/notes/components/sort_discussion_spec.js b/spec/frontend/notes/components/sort_discussion_spec.js
deleted file mode 100644
index 8b6e05da3c0..00000000000
--- a/spec/frontend/notes/components/sort_discussion_spec.js
+++ /dev/null
@@ -1,102 +0,0 @@
-import { shallowMount } from '@vue/test-utils';
-import Vue from 'vue';
-import Vuex from 'vuex';
-import SortDiscussion from '~/notes/components/sort_discussion.vue';
-import { ASC, DESC } from '~/notes/constants';
-import createStore from '~/notes/stores';
-import Tracking from '~/tracking';
-import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
-
-Vue.use(Vuex);
-
-describe('Sort Discussion component', () => {
- let wrapper;
- let store;
-
- const createComponent = () => {
- jest.spyOn(store, 'dispatch').mockImplementation();
-
- wrapper = shallowMount(SortDiscussion, {
- store,
- });
- };
-
- const findLocalStorageSync = () => wrapper.findComponent(LocalStorageSync);
-
- beforeEach(() => {
- store = createStore();
- jest.spyOn(Tracking, 'event');
- });
-
- afterEach(() => {
- wrapper.destroy();
- wrapper = null;
- });
-
- describe('default', () => {
- beforeEach(() => {
- createComponent();
- });
-
- it('has local storage sync with the correct props', () => {
- expect(findLocalStorageSync().props('asString')).toBe(true);
- });
-
- it('calls setDiscussionSortDirection when update is emitted', () => {
- findLocalStorageSync().vm.$emit('input', ASC);
-
- expect(store.dispatch).toHaveBeenCalledWith('setDiscussionSortDirection', { direction: ASC });
- });
- });
-
- describe('when asc', () => {
- describe('when the dropdown is clicked', () => {
- it('calls the right actions', () => {
- createComponent();
-
- wrapper.find('.js-newest-first').vm.$emit('click');
-
- expect(store.dispatch).toHaveBeenCalledWith('setDiscussionSortDirection', {
- direction: DESC,
- });
- expect(Tracking.event).toHaveBeenCalledWith(undefined, 'change_discussion_sort_direction', {
- property: DESC,
- });
- });
- });
-
- it('shows the "Oldest First" as the dropdown', () => {
- createComponent();
-
- expect(wrapper.find('.js-dropdown-text').props('text')).toBe('Oldest first');
- });
- });
-
- describe('when desc', () => {
- beforeEach(() => {
- store.state.discussionSortOrder = DESC;
- createComponent();
- });
-
- describe('when the dropdown item is clicked', () => {
- it('calls the right actions', () => {
- wrapper.find('.js-oldest-first').vm.$emit('click');
-
- expect(store.dispatch).toHaveBeenCalledWith('setDiscussionSortDirection', {
- direction: ASC,
- });
- expect(Tracking.event).toHaveBeenCalledWith(undefined, 'change_discussion_sort_direction', {
- property: ASC,
- });
- });
-
- it('sets is-checked to true on the active button in the dropdown', () => {
- expect(wrapper.find('.js-newest-first').props('isChecked')).toBe(true);
- });
- });
-
- it('shows the "Newest First" as the dropdown', () => {
- expect(wrapper.find('.js-dropdown-text').props('text')).toBe('Newest first');
- });
- });
-});