Skip to content

Commit

Permalink
Merge pull request #4761 from berkarslan-xo/bugfix/Issue-4760
Browse files Browse the repository at this point in the history
Issue-4760 - Deleting the parent page while the child page is open doesn't redirect
  • Loading branch information
valadas authored Aug 3, 2021
2 parents ecb356d + f31f512 commit 94d9733
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
jest.mock('../../services/pageService');
jest.mock('../../utils');
import pageActions from '../pageActions';
import utils from "../../utils";
import PagesService from "../../services/pageService";

describe('Dnn Page Actions', () => {
it('Redirects when parent page is deleted and the child page is the current page', done => {
// Arrange
const pageToDelete = {
tabId: 1,
hasChild: true
};
const defaultUrl = 'http://localhost';
const redirectUrl = 'http://localhost/test';
PagesService.deletePage.mockResolvedValue({});
PagesService.getPageHierarchy.mockResolvedValue([1, 2]);
utils.getCurrentPageId.mockReturnValue(2);
utils.getDefaultPageUrl.mockReturnValue(redirectUrl);
delete window.top.location;
window.top.location = new URL(defaultUrl);
Object.defineProperty(window.top.location, 'href', {
set: (value) => {
// Assert
expect(value).toBe(redirectUrl)
done();
}
});
expect.assertions(1);

// Act
pageActions.deletePage(pageToDelete, null)(() => {});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const loadPage = function (dispatch, pageId, callback) {
});
};

const redirectFromNonExistingPage = function (redirectUrl) {
window.top.location.href = redirectUrl ? redirectUrl : utils.getDefaultPageUrl();
};

const pageActions = {
getPageList(id) {
return (dispatch) => PagesService.getPageList(id).then(pageList => {
Expand Down Expand Up @@ -224,7 +228,15 @@ const pageActions = {
type: ActionTypes.DELETED_PAGE
});
if (page.tabId !== 0 && (page.tabId === utils.getCurrentPageId()) || redirectUrl) {
window.top.location.href = redirectUrl ? redirectUrl : utils.getDefaultPageUrl();
redirectFromNonExistingPage(redirectUrl);
}
else if (page.hasChild === true) {
let currentPageId = utils.getCurrentPageId();
PagesService.getPageHierarchy(currentPageId).then(hierarchy => {
if (Array.isArray(hierarchy) && hierarchy.indexOf(page.tabId) > -1) {
redirectFromNonExistingPage(redirectUrl);
}
});
}
}).catch((error) => {
dispatch({
Expand Down

0 comments on commit 94d9733

Please # to comment.