Skip to content

Commit

Permalink
chore(edit-content): Fix #26163 Edit Contentlet implement Feature Flag (
Browse files Browse the repository at this point in the history
#26242)

* dev (general): add new library and route

* dev (configuration resource Java): Add Feature Flags to WhiteList

* copywritting (edit-content routing): change name to match standard

* dev (edit content guard): add guard to prevent navigation without feature flag

* dev (app routing): add guard to edit content and move pages route to angular

* fix (general): add guard to providers and fix bad use of inject

* dev (custom event handler): add feature flag to redirect to new form instead of jsp old dialog

* fix (general test): test were broken by bad import in providers

* fix (form component test): missing import

* dev (general): add routing for creating contentlet

* dev (dot custom event handler): add re routing for edit task

* dev (dot pages store): add redirect to new portlet when feature flag is on

* fix (pages portlet): some tests were broken

* dev (dot edit page nav): Add redirect to new edit contentlet

* fix (pages create dialog): route were wrong

* Revert "dev (dot edit page nav): Add redirect to new edit contentlet"

This reverts commit d9a3f9f.

* dev (jsp): add contentType to event

* dev (dot custom event handler service): add event for create contentlet from edit page

* dev (general): final replace of the route to content

* dev (general): solve feedback

* feedback (edit content guard): change the approach to be functional guard

* feedback (general): add tests and small refactor

* feedback (general): small refactor

* feedback (feature flags): fix content editor 2 value

* dev (dot properties service): add methods to get feature flags values directly

* dev (jsp): edit redirects now sends the content type in the event

* dev (host jsp): now host emits a different event to go to legacy portlet

* dev (custom event handler): refactor to handle new feature flag method and verify content types

* fix (custom event handler): tests were broken

* fix (dot properties service): Add missing done callback

* dev (general): apply refactor for new feature flag method

* fix (dot feature flag resolver): test were broken

* dev (dot pages): add redirect to new edit contentlet checking the content types

* fix (pages store): fix tests

* feedback (general): change name of methods

* feedback (general): fix feature flag name
  • Loading branch information
zJaaal authored and manuelrojas committed Oct 5, 2023
1 parent 0b8d03f commit 4460ecd
Show file tree
Hide file tree
Showing 60 changed files with 1,154 additions and 252 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { of } from 'rxjs';

import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';

import { ConfirmationService } from 'primeng/api';
Expand All @@ -18,6 +21,7 @@ import {
DotEventsService,
DotGenerateSecurePasswordService,
DotLicenseService,
DotPropertiesService,
DotWorkflowActionsFireService
} from '@dotcms/data-access';
import {
Expand All @@ -33,6 +37,7 @@ import {
StringUtils,
UserModel
} from '@dotcms/dotcms-js';
import { FeaturedFlags } from '@dotcms/dotcms-models';
import { DotLoadingIndicatorService } from '@dotcms/utils';
import {
CoreWebServiceMock,
Expand Down Expand Up @@ -62,9 +67,18 @@ describe('DotCustomEventHandlerService', () => {
let dotWorkflowEventHandlerService: DotWorkflowEventHandlerService;
let dotEventsService: DotEventsService;
let dotLicenseService: DotLicenseService;
let router: Router;

beforeEach(() => {
TestBed.configureTestingModule({
const createFeatureFlagResponse = (
enabled: string = 'NOT_FOUND',
contentType: string = '*'
) => ({
[FeaturedFlags.FEATURE_FLAG_CONTENT_EDITOR2_ENABLED]: enabled,
[FeaturedFlags.FEATURE_FLAG_CONTENT_EDITOR2_CONTENT_TYPE]: contentType
});

const setup = (dotPropertiesMock: unknown) => {
TestBed.resetTestingModule().configureTestingModule({
providers: [
DotCustomEventHandlerService,
DotLoadingIndicatorService,
Expand Down Expand Up @@ -100,7 +114,9 @@ describe('DotCustomEventHandlerService', () => {
DotDownloadBundleDialogService,
DotGenerateSecurePasswordService,
LoginService,
DotLicenseService
DotLicenseService,
{ provide: DotPropertiesService, useValue: dotPropertiesMock },
Router
],
imports: [RouterTestingModule, HttpClientTestingModule]
});
Expand All @@ -116,6 +132,13 @@ describe('DotCustomEventHandlerService', () => {
dotWorkflowEventHandlerService = TestBed.inject(DotWorkflowEventHandlerService);
dotEventsService = TestBed.inject(DotEventsService);
dotLicenseService = TestBed.inject(DotLicenseService);
router = TestBed.inject(Router);
};

beforeEach(() => {
setup({
getKeys: () => of(createFeatureFlagResponse())
});
});

it('should show loading indicator and go to edit page when event is emited by iframe', () => {
Expand Down Expand Up @@ -144,6 +167,7 @@ describe('DotCustomEventHandlerService', () => {

it('should create a contentlet', () => {
spyOn(dotContentletEditorService, 'create');

service.handle(
new CustomEvent('ng-event', {
detail: {
Expand All @@ -160,6 +184,43 @@ describe('DotCustomEventHandlerService', () => {
});
});

it('should create a host', () => {
spyOn(dotContentletEditorService, 'create');

service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'create-host',
data: { url: 'hello.world.com' }
}
})
);

expect(dotContentletEditorService.create).toHaveBeenCalledWith({
data: {
url: 'hello.world.com'
}
});
});

it('should create a contentlet from edit page', () => {
spyOn(dotContentletEditorService, 'create');
service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'create-contentlet-from-edit-page',
data: { url: 'hello.world.com' }
}
})
);

expect(dotContentletEditorService.create).toHaveBeenCalledWith({
data: {
url: 'hello.world.com'
}
});
});

it('should edit a contentlet', () => {
service.handle(
new CustomEvent('ng-event', {
Expand All @@ -174,6 +235,20 @@ describe('DotCustomEventHandlerService', () => {
expect(dotRouterService.goToEditContentlet).toHaveBeenCalledWith('123');
});

it('should edit a host', () => {
service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'edit-host',
data: {
inode: '123'
}
}
})
);
expect(dotRouterService.goToEditContentlet).toHaveBeenCalledWith('123');
});

it('should edit a a workflow task', () => {
service.handle(
new CustomEvent('ng-event', {
Expand Down Expand Up @@ -304,4 +379,162 @@ describe('DotCustomEventHandlerService', () => {
);
expect(dotLicenseService.updateLicense).toHaveBeenCalled();
});

describe('edit content 2 is enabled and contentTypes are catchall', () => {
beforeEach(() => {
setup({
getKeys: () => of(createFeatureFlagResponse('true'))
});

spyOn(router, 'navigate');
});

it('should create a contentlet', () => {
spyOn(dotContentletEditorService, 'create');

service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'create-contentlet',
data: { contentType: 'test' }
}
})
);

expect(router.navigate).toHaveBeenCalledWith(['content/new/test']);
});

it('should edit a a workflow task', () => {
service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'edit-task',
data: {
inode: '123',
contentType: 'test'
}
}
})
);

expect(router.navigate).toHaveBeenCalledWith(['content/123']);
});

it('should edit a contentlet', () => {
service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'edit-contentlet',
data: {
inode: '123',
contentType: 'test'
}
}
})
);
expect(router.navigate).toHaveBeenCalledWith(['content/123']);
});
});

describe('edit content 2 is enabled and contentTypes are limited', () => {
beforeEach(() => {
setup({
getKeys: () => of(createFeatureFlagResponse('true', 'test,test2'))
});

spyOn(router, 'navigate');
});

it('should create a contentlet', () => {
spyOn(dotContentletEditorService, 'create');

service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'create-contentlet',
data: { contentType: 'test' }
}
})
);

expect(router.navigate).toHaveBeenCalledWith(['content/new/test']);
});

it('should edit a a workflow task', () => {
service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'edit-task',
data: {
inode: '123',
contentType: 'test2'
}
}
})
);

expect(router.navigate).toHaveBeenCalledWith(['content/123']);
});

it('should edit a contentlet', () => {
service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'edit-contentlet',
data: {
inode: '123',
contentType: 'test2'
}
}
})
);
expect(router.navigate).toHaveBeenCalledWith(['content/123']);
});

it('should not create a contentlet', () => {
spyOn(dotContentletEditorService, 'create');

service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'create-contentlet',
data: { contentType: 'not in the list' }
}
})
);

expect(router.navigate).not.toHaveBeenCalledWith(['content/new/test']);
});

it('should not edit a a workflow task', () => {
service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'edit-task',
data: {
inode: '123',
contentType: 'not in the list'
}
}
})
);

expect(router.navigate).not.toHaveBeenCalledWith(['content/123']);
});

it('should not edit a contentlet', () => {
service.handle(
new CustomEvent('ng-event', {
detail: {
name: 'edit-contentlet',
data: {
inode: '123',
contentType: 'not in the list'
}
}
})
);
expect(router.navigate).not.toHaveBeenCalledWith(['content/123']);
});
});
});
Loading

0 comments on commit 4460ecd

Please sign in to comment.