Commit 5dd2e065 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'fix-diff-files-expand-all' into 'master'

Fix expand all button not working

Closes #51737

See merge request gitlab-org/gitlab-ce!25961
parents ad789b7f c36095b2
...@@ -125,9 +125,9 @@ export default { ...@@ -125,9 +125,9 @@ export default {
> >
{{ __('Show latest version') }} {{ __('Show latest version') }}
</gl-button> </gl-button>
<a v-show="hasCollapsedFile" class="btn btn-default append-right-8" @click="expandAllFiles"> <gl-button v-show="hasCollapsedFile" class="append-right-8" @click="expandAllFiles">
{{ __('Expand all') }} {{ __('Expand all') }}
</a> </gl-button>
<settings-dropdown /> <settings-dropdown />
</div> </div>
</div> </div>
......
...@@ -73,13 +73,23 @@ export default { ...@@ -73,13 +73,23 @@ export default {
if (!newVal && oldVal && !this.hasDiffLines) { if (!newVal && oldVal && !this.hasDiffLines) {
this.handleLoadCollapsedDiff(); this.handleLoadCollapsedDiff();
} }
this.setFileCollapsed({ filePath: this.file.file_path, collapsed: newVal });
},
'file.viewer.collapsed': function setIsCollapsed(newVal) {
this.isCollapsed = newVal;
}, },
}, },
created() { created() {
eventHub.$on(`loadCollapsedDiff/${this.file.file_hash}`, this.handleLoadCollapsedDiff); eventHub.$on(`loadCollapsedDiff/${this.file.file_hash}`, this.handleLoadCollapsedDiff);
}, },
methods: { methods: {
...mapActions('diffs', ['loadCollapsedDiff', 'assignDiscussionsToDiff', 'setRenderIt']), ...mapActions('diffs', [
'loadCollapsedDiff',
'assignDiscussionsToDiff',
'setRenderIt',
'setFileCollapsed',
]),
handleToggle() { handleToggle() {
if (!this.hasDiffLines) { if (!this.hasDiffLines) {
this.handleLoadCollapsedDiff(); this.handleLoadCollapsedDiff();
......
...@@ -344,5 +344,8 @@ export const toggleFullDiff = ({ dispatch, getters, state }, filePath) => { ...@@ -344,5 +344,8 @@ export const toggleFullDiff = ({ dispatch, getters, state }, filePath) => {
} }
}; };
export const setFileCollapsed = ({ commit }, { filePath, collapsed }) =>
commit(types.SET_FILE_COLLAPSED, { filePath, collapsed });
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {}; export default () => {};
...@@ -27,3 +27,4 @@ export const TOGGLE_FILE_FINDER_VISIBLE = 'TOGGLE_FILE_FINDER_VISIBLE'; ...@@ -27,3 +27,4 @@ export const TOGGLE_FILE_FINDER_VISIBLE = 'TOGGLE_FILE_FINDER_VISIBLE';
export const REQUEST_FULL_DIFF = 'REQUEST_FULL_DIFF'; export const REQUEST_FULL_DIFF = 'REQUEST_FULL_DIFF';
export const RECEIVE_FULL_DIFF_SUCCESS = 'RECEIVE_FULL_DIFF_SUCCESS'; export const RECEIVE_FULL_DIFF_SUCCESS = 'RECEIVE_FULL_DIFF_SUCCESS';
export const RECEIVE_FULL_DIFF_ERROR = 'RECEIVE_FULL_DIFF_ERROR'; export const RECEIVE_FULL_DIFF_ERROR = 'RECEIVE_FULL_DIFF_ERROR';
export const SET_FILE_COLLAPSED = 'SET_FILE_COLLAPSED';
...@@ -104,7 +104,10 @@ export default { ...@@ -104,7 +104,10 @@ export default {
[types.EXPAND_ALL_FILES](state) { [types.EXPAND_ALL_FILES](state) {
state.diffFiles = state.diffFiles.map(file => ({ state.diffFiles = state.diffFiles.map(file => ({
...file, ...file,
collapsed: false, viewer: {
...file.viewer,
collapsed: false,
},
})); }));
}, },
...@@ -300,4 +303,11 @@ export default { ...@@ -300,4 +303,11 @@ export default {
}), }),
}); });
}, },
[types.SET_FILE_COLLAPSED](state, { filePath, collapsed }) {
const file = state.diffFiles.find(f => f.file_path === filePath);
if (file && file.viewer) {
file.viewer.collapsed = collapsed;
}
},
}; };
...@@ -34,6 +34,16 @@ describe 'User views diffs', :js do ...@@ -34,6 +34,16 @@ describe 'User views diffs', :js do
expect(page).not_to have_selector('.mr-loading-status .loading', visible: true) expect(page).not_to have_selector('.mr-loading-status .loading', visible: true)
end end
it 'expands all diffs' do
first('#a5cc2925ca8258af241be7e5b0381edf30266302 .js-file-title').click
expect(page).to have_button('Expand all')
click_button 'Expand all'
expect(page).not_to have_button('Expand all')
end
context 'when in the inline view' do context 'when in the inline view' do
include_examples 'unfold diffs' include_examples 'unfold diffs'
end end
......
...@@ -109,6 +109,31 @@ describe('DiffFile', () => { ...@@ -109,6 +109,31 @@ describe('DiffFile', () => {
done(); done();
}); });
}); });
it('should update store state', done => {
spyOn(vm.$store, 'dispatch');
vm.isCollapsed = true;
vm.$nextTick(() => {
expect(vm.$store.dispatch).toHaveBeenCalledWith('diffs/setFileCollapsed', {
filePath: vm.file.file_path,
collapsed: true,
});
done();
});
});
it('updates local state when changing file state', done => {
vm.file.viewer.collapsed = true;
vm.$nextTick(() => {
expect(vm.isCollapsed).toBe(true);
done();
});
});
}); });
}); });
......
...@@ -35,6 +35,7 @@ import actions, { ...@@ -35,6 +35,7 @@ import actions, {
receiveFullDiffError, receiveFullDiffError,
fetchFullDiff, fetchFullDiff,
toggleFullDiff, toggleFullDiff,
setFileCollapsed,
} from '~/diffs/store/actions'; } from '~/diffs/store/actions';
import eventHub from '~/notes/event_hub'; import eventHub from '~/notes/event_hub';
import * as types from '~/diffs/store/mutation_types'; import * as types from '~/diffs/store/mutation_types';
...@@ -977,4 +978,17 @@ describe('DiffsStoreActions', () => { ...@@ -977,4 +978,17 @@ describe('DiffsStoreActions', () => {
); );
}); });
}); });
describe('setFileCollapsed', () => {
it('commits SET_FILE_COLLAPSED', done => {
testAction(
setFileCollapsed,
{ filePath: 'test', collapsed: true },
null,
[{ type: types.SET_FILE_COLLAPSED, payload: { filePath: 'test', collapsed: true } }],
[],
done,
);
});
});
}); });
...@@ -58,13 +58,15 @@ describe('DiffsStoreMutations', () => { ...@@ -58,13 +58,15 @@ describe('DiffsStoreMutations', () => {
describe('EXPAND_ALL_FILES', () => { describe('EXPAND_ALL_FILES', () => {
it('should change the collapsed prop from diffFiles', () => { it('should change the collapsed prop from diffFiles', () => {
const diffFile = { const diffFile = {
collapsed: true, viewer: {
collapsed: true,
},
}; };
const state = { expandAllFiles: true, diffFiles: [diffFile] }; const state = { expandAllFiles: true, diffFiles: [diffFile] };
mutations[types.EXPAND_ALL_FILES](state); mutations[types.EXPAND_ALL_FILES](state);
expect(state.diffFiles[0].collapsed).toEqual(false); expect(state.diffFiles[0].viewer.collapsed).toEqual(false);
}); });
}); });
...@@ -742,4 +744,16 @@ describe('DiffsStoreMutations', () => { ...@@ -742,4 +744,16 @@ describe('DiffsStoreMutations', () => {
expect(state.diffFiles[0].isShowingFullFile).toBe(true); expect(state.diffFiles[0].isShowingFullFile).toBe(true);
}); });
}); });
describe('SET_FILE_COLLAPSED', () => {
it('sets collapsed', () => {
const state = {
diffFiles: [{ file_path: 'test', viewer: { collapsed: false } }],
};
mutations[types.SET_FILE_COLLAPSED](state, { filePath: 'test', collapsed: true });
expect(state.diffFiles[0].viewer.collapsed).toBe(true);
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment