Commit 4f46a580 authored by Mark Florian's avatar Mark Florian

Merge branch '213238-fix-ide-discard-empty-file' into 'master'

Fix discard button not showing up in Web IDE

See merge request gitlab-org/gitlab!30767
parents 4bfb5964 097b0131
...@@ -24,8 +24,8 @@ export default { ...@@ -24,8 +24,8 @@ export default {
discardModalTitle() { discardModalTitle() {
return sprintf(__('Discard changes to %{path}?'), { path: this.activeFile.path }); return sprintf(__('Discard changes to %{path}?'), { path: this.activeFile.path });
}, },
isStaged() { canDiscard() {
return !this.activeFile.changed && this.activeFile.staged; return this.activeFile.changed || this.activeFile.staged;
}, },
}, },
methods: { methods: {
...@@ -53,7 +53,7 @@ export default { ...@@ -53,7 +53,7 @@ export default {
<changed-file-icon :file="activeFile" :is-centered="false" /> <changed-file-icon :file="activeFile" :is-centered="false" />
<div class="ml-auto"> <div class="ml-auto">
<button <button
v-if="!isStaged" v-if="canDiscard"
ref="discardButton" ref="discardButton"
type="button" type="button"
class="btn btn-remove btn-inverted append-right-8" class="btn btn-remove btn-inverted append-right-8"
......
---
title: Fix discard button not showing for new empty files in Web IDE
merge_request: 30767
author:
type: fixed
...@@ -7,27 +7,32 @@ import { file } from '../../helpers'; ...@@ -7,27 +7,32 @@ import { file } from '../../helpers';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
const TEST_FILE_PATH = 'test/file/path';
describe('IDE commit editor header', () => { describe('IDE commit editor header', () => {
let wrapper; let wrapper;
let f;
let store; let store;
const findDiscardModal = () => wrapper.find({ ref: 'discardModal' }); const createComponent = (fileProps = {}) => {
const findDiscardButton = () => wrapper.find({ ref: 'discardButton' });
beforeEach(() => {
f = file('file');
store = createStore();
wrapper = mount(EditorHeader, { wrapper = mount(EditorHeader, {
store, store,
localVue, localVue,
propsData: { propsData: {
activeFile: f, activeFile: {
...file(TEST_FILE_PATH),
staged: true,
...fileProps,
},
}, },
}); });
};
jest.spyOn(wrapper.vm, 'discardChanges').mockImplementation(); const findDiscardModal = () => wrapper.find({ ref: 'discardModal' });
const findDiscardButton = () => wrapper.find({ ref: 'discardButton' });
beforeEach(() => {
store = createStore();
jest.spyOn(store, 'dispatch').mockImplementation();
}); });
afterEach(() => { afterEach(() => {
...@@ -35,29 +40,38 @@ describe('IDE commit editor header', () => { ...@@ -35,29 +40,38 @@ describe('IDE commit editor header', () => {
wrapper = null; wrapper = null;
}); });
it('renders button to discard', () => { it.each`
expect(wrapper.vm.$el.querySelectorAll('.btn')).toHaveLength(1); fileProps | shouldExist
${{ staged: false, changed: false }} | ${false}
${{ staged: true, changed: false }} | ${true}
${{ staged: false, changed: true }} | ${true}
${{ staged: true, changed: true }} | ${true}
`('with $fileProps, show discard button is $shouldExist', ({ fileProps, shouldExist }) => {
createComponent(fileProps);
expect(findDiscardButton().exists()).toBe(shouldExist);
}); });
describe('discard button', () => { describe('discard button', () => {
let modal;
beforeEach(() => { beforeEach(() => {
modal = findDiscardModal(); createComponent();
const modal = findDiscardModal();
jest.spyOn(modal.vm, 'show'); jest.spyOn(modal.vm, 'show');
findDiscardButton().trigger('click'); findDiscardButton().trigger('click');
}); });
it('opens a dialog confirming discard', () => { it('opens a dialog confirming discard', () => {
expect(modal.vm.show).toHaveBeenCalled(); expect(findDiscardModal().vm.show).toHaveBeenCalled();
}); });
it('calls discardFileChanges if dialog result is confirmed', () => { it('calls discardFileChanges if dialog result is confirmed', () => {
modal.vm.$emit('ok'); expect(store.dispatch).not.toHaveBeenCalled();
findDiscardModal().vm.$emit('ok');
expect(wrapper.vm.discardChanges).toHaveBeenCalledWith(f.path); expect(store.dispatch).toHaveBeenCalledWith('discardFileChanges', TEST_FILE_PATH);
}); });
}); });
}); });
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