Fix #3820: Fix creating empty events.

Signed-off-by: Rita Gama <rita.gama@tecnico.ulisboa.pt>
This commit is contained in:
Rita Gama 2023-05-04 10:34:37 +01:00 committed by rita_gama
parent 8e78ea3c25
commit f1b2c8f08b
2 changed files with 166 additions and 2 deletions

View File

@ -811,7 +811,10 @@ export default {
}
try {
await this.save()
if ((from.name !== 'NewPopoverView' || to.name !== 'EditPopoverView')
&& (from.name !== 'NewPopoverView' || to.name !== 'EditSideBarView')) {
await this.save()
}
next()
} catch (error) {
console.debug(error)

View File

@ -20,6 +20,7 @@
*
*/
import eventClick from "../../../../../src/fullcalendar/interaction/eventClick.js";
import EditorMixin from "../../../../../src/mixins/EditorMixin.js";
import {
getPrefixedRoute,
isPublicOrEmbeddedRoute,
@ -412,4 +413,164 @@ describe('fullcalendar/eventClick test suite', () => {
expect(window.location).toEqual(oldLocation)
})
})
it('should do nothing when there is no require action on route leave', () => {
const fromRoute = {
name: 'Test1',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const toRoute = {
name: 'Test2',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const next = jest.fn()
EditorMixin.requiresActionOnRouteLeave = false
EditorMixin.beforeRouteLeave(toRoute, fromRoute, next)
})
it('should not save the event when new side bar view is open and then clicked in a saved event', () => {
const fromRoute = {
name: 'NewSideBarView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const toRoute = {
name: 'EditSideBarView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const next = jest.fn()
EditorMixin.requiresActionOnRouteLeave = true
EditorMixin.beforeRouteLeave(toRoute, fromRoute, next)
})
it('should not save the event when new popover view is open and then clicked in a saved event in popover view', () => {
const fromRoute = {
name: 'NewPopoverView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const toRoute = {
name: 'EditPopoverView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const next = jest.fn()
EditorMixin.requiresActionOnRouteLeave = true
EditorMixin.beforeRouteLeave(toRoute, fromRoute, next)
})
it('should not save the event when new popover view is open and then clicked in a saved event in sidebar view', () => {
const fromRoute = {
name: 'NewPopoverView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const toRoute = {
name: 'EditSideBarView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const next = jest.fn()
EditorMixin.requiresActionOnRouteLeave = true
EditorMixin.beforeRouteLeave(toRoute, fromRoute, next)
})
it('show save event', () => {
const fromRoute = {
name: 'EditPopoverView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const toRoute = {
name: 'NewPopoverView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const next = jest.fn()
EditorMixin.requiresActionOnRouteLeave = true
EditorMixin.beforeRouteLeave(toRoute, fromRoute, next)
})
it('show save event', () => {
const fromRoute = {
name: 'EditSideBarView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const toRoute = {
name: 'NewSideBarView',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const next = jest.fn()
EditorMixin.requiresActionOnRouteLeave = true
EditorMixin.beforeRouteLeave(toRoute, fromRoute, next)
})
it('should not save event with invalid to and from routes on beforeRouteLeave', () => {
const fromRoute = {
name: 'Test1',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const toRoute = {
name: 'Test2',
params: {
object: 'object123',
otherParam: '456',
recurrenceId: 'recurrence456',
}
}
const next = jest.fn()
EditorMixin.requiresActionOnRouteLeave = true
EditorMixin.beforeRouteLeave(toRoute, fromRoute, next)
})
})