diff options
author | André Luís <aluis@gitlab.com> | 2018-11-06 18:29:51 +0000 |
---|---|---|
committer | André Luís <aluis@gitlab.com> | 2018-11-06 18:29:53 +0000 |
commit | 4ebbd95296e34e9b066d8c9320133ca6de7ad0ef (patch) | |
tree | bc668aa3bf284254930e1872093fe1723aff3692 | |
parent | 26b694e96b32afe51aa7a0dc2db8a9d17f060c7b (diff) | |
download | gitlab-ce-51122-fix-navigating-discussions.tar.gz |
Add tests for fixing discussion navigation51122-fix-navigating-discussions
It adds a check for a dispatched action in
action: expandDiscussion()
Also adds relevant tests for added action
renderFileForDiscussionId()
-rw-r--r-- | spec/javascripts/diffs/store/actions_spec.js | 63 | ||||
-rw-r--r-- | spec/javascripts/notes/stores/actions_spec.js | 2 |
2 files changed, 64 insertions, 1 deletions
diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index bb623953710..18174797659 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -25,9 +25,11 @@ import actions, { toggleTreeOpen, scrollToFile, toggleShowTreeList, + renderFileForDiscussionId, } from '~/diffs/store/actions'; import * as types from '~/diffs/store/mutation_types'; import axios from '~/lib/utils/axios_utils'; +import eventHub from '~/notes/event_hub'; import testAction from '../../helpers/vuex_action_helper'; describe('DiffsStoreActions', () => { @@ -689,4 +691,65 @@ describe('DiffsStoreActions', () => { expect(localStorage.setItem).toHaveBeenCalledWith('mr_tree_show', true); }); }); + + describe('renderFileForDiscussionId', () => { + const rootGetters = { + allDiscussions: [ + { + id: '123', + diff_file: { + file_hash: 'HASH', + }, + }, + { + id: '456', + diff_file: { + file_hash: 'HASH', + }, + }, + ], + }; + let commit; + let $emit; + let $once; + let scrollToElement; + const state = ({ collapsed, renderIt }) => ({ + diffFiles: [ + { + fileHash: 'HASH', + collapsed, + renderIt, + }, + ], + }); + + beforeEach(() => { + commit = jasmine.createSpy('commit'); + scrollToElement = spyOnDependency(actions, 'scrollToElement').and.stub(); + $emit = spyOn(eventHub, '$emit'); + $once = spyOn(eventHub, '$once'); + }); + + it('renders and expands file for the given discussion id', () => { + const localState = state({ collapsed: true, renderIt: false }); + + renderFileForDiscussionId({ rootGetters, state: localState, commit }, '123'); + + expect(commit).toHaveBeenCalledWith('RENDER_FILE', localState.diffFiles[0]); + expect($emit).toHaveBeenCalledTimes(1); + expect($once).toHaveBeenCalledTimes(1); + expect(scrollToElement).toHaveBeenCalledTimes(1); + }); + + it('jumps to discussion on already rendered and expanded file', () => { + const localState = state({ collapsed: false, renderIt: true }); + + renderFileForDiscussionId({ rootGetters, state: localState, commit }, '123'); + + expect(commit).not.toHaveBeenCalled(); + expect($emit).toHaveBeenCalledTimes(1); + expect($once).not.toHaveBeenCalled(); + expect(scrollToElement).not.toHaveBeenCalled(); + }); + }); }); diff --git a/spec/javascripts/notes/stores/actions_spec.js b/spec/javascripts/notes/stores/actions_spec.js index f4643fd55ed..034962debc8 100644 --- a/spec/javascripts/notes/stores/actions_spec.js +++ b/spec/javascripts/notes/stores/actions_spec.js @@ -123,7 +123,7 @@ describe('Actions Notes Store', () => { { discussionId: discussionMock.id }, { notes: [discussionMock] }, [{ type: 'EXPAND_DISCUSSION', payload: { discussionId: discussionMock.id } }], - [], + [{ type: 'diffs/renderFileForDiscussionId', payload: discussionMock.id }], done, ); }); |