diff options
Diffstat (limited to 'spec/frontend/notes/components/notes_app_spec.js')
-rw-r--r-- | spec/frontend/notes/components/notes_app_spec.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/frontend/notes/components/notes_app_spec.js b/spec/frontend/notes/components/notes_app_spec.js index 241a89b2218..b3dbc26878f 100644 --- a/spec/frontend/notes/components/notes_app_spec.js +++ b/spec/frontend/notes/components/notes_app_spec.js @@ -2,11 +2,14 @@ import { mount, shallowMount } from '@vue/test-utils'; import AxiosMockAdapter from 'axios-mock-adapter'; import $ from 'jquery'; import Vue from 'vue'; +import setWindowLocation from 'helpers/set_window_location_helper'; import { setTestTimeout } from 'helpers/timeout'; +import waitForPromises from 'helpers/wait_for_promises'; import DraftNote from '~/batch_comments/components/draft_note.vue'; import batchComments from '~/batch_comments/stores/modules/batch_comments'; import axios from '~/lib/utils/axios_utils'; import * as urlUtility from '~/lib/utils/url_utility'; +import { discussionIntersectionObserverHandlerFactory } from '~/diffs/utils/discussions'; import CommentForm from '~/notes/components/comment_form.vue'; import NotesApp from '~/notes/components/notes_app.vue'; import * as constants from '~/notes/constants'; @@ -76,6 +79,9 @@ describe('note_app', () => { </div>`, }, { + provide: { + discussionObserverHandler: discussionIntersectionObserverHandlerFactory(), + }, propsData, store, }, @@ -430,4 +436,57 @@ describe('note_app', () => { ); }); }); + + 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, + }); + }); + }); + }); }); |