Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Issue-4760 - Deleting the parent page while the child page is open doesn't redirect #4761

Merged
merged 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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