Skip to content

Commit

Permalink
Merge pull request #5321 from nextcloud/backport/5117/stable4.4
Browse files Browse the repository at this point in the history
[stable4.4] Fix creating empty events
  • Loading branch information
miaulalala authored Jun 29, 2023
2 parents f7ed0b4 + a8403e7 commit 835db27
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/mixins/EditorMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
163 changes: 162 additions & 1 deletion tests/javascript/unit/fullcalendar/interaction/eventClick.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
*/
import eventClick from "../../../../../src/fullcalendar/interaction/eventClick.js";
import EditorMixin from "../../../../../src/mixins/EditorMixin.js";
import {
getPrefixedRoute,
isPublicOrEmbeddedRoute,
Expand Down Expand Up @@ -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)
})
})

0 comments on commit 835db27

Please sign in to comment.