Skip to content
Snippets Groups Projects
Commit 89c3c88e authored by Jacob Schatz's avatar Jacob Schatz
Browse files

Add confirm when navigating away from page with tests.

parent 50a64953
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -152,6 +152,12 @@
hasUpdated() {
return !!this.state.updatedAt;
},
issueChanged() {
return this.initialDescriptionText
!== this.store.formState.description
|| this.initialTitleText
!== this.store.formState.title;
},
},
created() {
this.service = new Service(this.endpoint);
Loading
Loading
@@ -176,6 +182,8 @@
}
});
 
window.addEventListener('beforeunload', this.handleBeforeUnloadEvent);
eventHub.$on('delete.issuable', this.deleteIssuable);
eventHub.$on('update.issuable', this.updateIssuable);
eventHub.$on('close.form', this.closeForm);
Loading
Loading
@@ -188,6 +196,14 @@
eventHub.$off('open.form', this.openForm);
},
methods: {
handleBeforeUnloadEvent(e) {
const event = e;
if (this.showForm && this.issueChanged) {
event.returnValue = 'Are you sure you want to lose your issue information?';
}
return undefined;
},
openForm() {
if (!this.showForm) {
this.showForm = true;
Loading
Loading
Loading
Loading
@@ -218,6 +218,39 @@ describe('Issuable output', () => {
});
});
 
describe('shows dialog when issue has unsaved changed', () => {
it('confirms on title change', (done) => {
vm.showForm = true;
vm.state.titleText = 'title has changed';
const e = { returnValue: null };
vm.handleBeforeUnloadEvent(e);
Vue.nextTick(() => {
expect(e.returnValue).not.toBeNull();
done();
});
});
it('confirms on description change', (done) => {
vm.showForm = true;
vm.state.descriptionText = 'description has changed';
const e = { returnValue: null };
vm.handleBeforeUnloadEvent(e);
Vue.nextTick(() => {
expect(e.returnValue).not.toBeNull();
done();
});
});
it('does nothing when nothing has changed', (done) => {
const e = { returnValue: null };
vm.handleBeforeUnloadEvent(e);
Vue.nextTick(() => {
expect(e.returnValue).toBeNull();
done();
});
});
});
describe('error when updating', () => {
beforeEach(() => {
spyOn(window, 'Flash').and.callThrough();
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment