Skip to content

Commit

Permalink
fix(core): Edit Options not Showing on UrlContent Page #26314
Browse files Browse the repository at this point in the history
* dev (edit page state controller): regenerate menuItems when navigating inside the iframe

* fix (edit page state controller): test was broken
  • Loading branch information
zJaaal authored Oct 20, 2023
1 parent 808a924 commit f1c2d90
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -585,5 +585,36 @@ describe('DotEditPageStateControllerComponent', () => {
component.menu.onHide.emit();
expect(resetMock).toHaveBeenCalledWith(DotPageMode.EDIT);
});

it('should have menuItems if the page goes from not having urlContentMap to having it', async () => {
let pageRenderStateMocked: DotPageRenderState = new DotPageRenderState(
{ ...mockUser(), userId: '457' },
{
...mockDotRenderedPage()
}
);
fixtureHost.componentInstance.pageState = _.cloneDeep(pageRenderStateMocked);
fixtureHost.detectChanges();

await fixtureHost.whenStable();
expect(component.menuItems.length).toBe(0);

pageRenderStateMocked = new DotPageRenderState(
{ ...mockUser(), userId: '457' },
{
...mockDotRenderedPage(),
urlContentMap: {
title: 'Title',
inode: '123',
contentType: 'test'
}
}
);
fixtureHost.componentInstance.pageState = _.cloneDeep(pageRenderStateMocked);
fixtureHost.detectChanges();

await fixtureHost.whenStable();
expect(component.menuItems.length).toBe(2);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class DotEditPageStateControllerComponent implements OnChanges, OnInit {
mode: DotPageMode;
options: SelectItem[] = [];
featureFlagEditURLContentMapIsOn = false;
menuItems: MenuItem[];
menuItems: MenuItem[] = [];

readonly dotPageMode = DotPageMode;
readonly featureFlagEditURLContentMap = FeaturedFlags.FEATURE_FLAG_EDIT_URL_CONTENT_MAP;
Expand Down Expand Up @@ -89,6 +89,12 @@ export class DotEditPageStateControllerComponent implements OnChanges, OnInit {
this.lock = this.isLocked(pageState);
this.lockWarn = this.shouldWarnLock(pageState);
this.mode = pageState.state.mode;

if (this.featureFlagEditURLContentMapIsOn && pageState.params.urlContentMap) {
this.menuItems = this.getMenuItems();
} else if (this.menuItems.length) {
this.menuItems = []; // We have to clean the menu items because the menu is not re-rendered when the flag is off or the urlContentMap is null
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ describe('DotEditPageStateControllerSeoComponent', () => {
});

it('should not have menuItems if page does not have URLContentMap', async () => {
expect(component.menuItems).toBe(undefined);
expect(component.menuItems.length).toBe(0);
});
});

Expand Down Expand Up @@ -617,5 +617,36 @@ describe('DotEditPageStateControllerSeoComponent', () => {

expect(dotTabButtons.resetDropdownById).toHaveBeenCalledWith(DotPageMode.PREVIEW);
});

it('should have menuItems if the page goes from not having urlContentMap to having it', async () => {
let pageRenderStateMocked: DotPageRenderState = new DotPageRenderState(
{ ...mockUser(), userId: '457' },
{
...mockDotRenderedPage()
}
);
fixtureHost.componentInstance.pageState = _.cloneDeep(pageRenderStateMocked);
fixtureHost.detectChanges();

await fixtureHost.whenStable();
expect(component.menuItems.length).toBe(0);

pageRenderStateMocked = new DotPageRenderState(
{ ...mockUser(), userId: '457' },
{
...mockDotRenderedPage(),
urlContentMap: {
title: 'Title',
inode: '123',
contentType: 'test'
}
}
);
fixtureHost.componentInstance.pageState = _.cloneDeep(pageRenderStateMocked);
fixtureHost.detectChanges();

await fixtureHost.whenStable();
expect(component.menuItems.length).toBe(2);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class DotEditPageStateControllerSeoComponent implements OnInit, OnChanges
featureFlagEditURLContentMapIsOn = false;
mode: DotPageMode;
options: SelectItem[] = [];
menuItems: MenuItem[];
menuItems: MenuItem[] = [];

readonly dotPageMode = DotPageMode;

Expand Down Expand Up @@ -128,6 +128,12 @@ export class DotEditPageStateControllerSeoComponent implements OnInit, OnChanges
this.lock = this.isLocked(pageState);
this.lockWarn = this.shouldWarnLock(pageState);
this.mode = pageState.state.mode;

if (this.featureFlagEditURLContentMapIsOn && pageState.params.urlContentMap) {
this.menuItems = this.getMenuItems();
} else if (this.menuItems.length) {
this.menuItems = []; // We have to clean the menu items because the menu is not re-rendered when the flag is off or the urlContentMap is null
}
}
}

Expand Down

0 comments on commit f1c2d90

Please sign in to comment.