Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
dotCMS/core#18830 Layout edit displaying incorrectly (#1375)
Browse files Browse the repository at this point in the history
* #18714 Fixing error when try to add the same file container twice int… (#1368)

* #18714 Fixing error when try to add the same file container twice into a sidebar

* #18714 Removing f

* dotCMS/core#18779 (#1371)

* dotCMS/core#18830

Co-authored-by: Freddy Rodriguez <[email protected]>
  • Loading branch information
alfredo-dotcms and freddyDOTCMS authored Jul 14, 2020
1 parent 7349060 commit ea35128
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 146 deletions.
3 changes: 2 additions & 1 deletion src/app/api/services/dot-license/dot-license.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ describe('DotLicenseService', () => {
'/c/time-machine',
'/c/workflow-schemes',
'/c/es-search',
'/forms'
'/forms',
'/apps'
];
urls.forEach((url) => {
return this.dotLicenseService
Expand Down
5 changes: 5 additions & 0 deletions src/app/api/services/dot-license/dot-license.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const enterprisePorlets: DotUnlicensedPortletData[] = [
icon: 'business',
titleKey: 'Forms-and-Form-Builder',
url: '/forms'
},
{
icon: 'apps',
titleKey: 'com.dotcms.repackage.javax.portlet.title.apps',
url: '/apps'
}
];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,62 +1,51 @@
import { of as observableOf } from 'rxjs';
import { async } from '@angular/core/testing';
import { ActivatedRouteSnapshot } from '@angular/router';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { DOTTestBed } from '../../../test/dot-test-bed';
import { DotAppsService } from '@services/dot-apps/dot-apps.service';
import { DotAppsListResolver } from './dot-apps-list-resolver.service';
import { DotLicenseService } from '@services/dot-license/dot-license.service';

class AppsServicesMock {
get() {}
class DotLicenseServicesMock {
canAccessEnterprisePortlet(_url: string) {}
}

const activatedRouteSnapshotMock: any = jasmine.createSpyObj<ActivatedRouteSnapshot>(
'ActivatedRouteSnapshot',
['toString']
);
activatedRouteSnapshotMock.paramMap = {};

const routerStateSnapshotMock = jasmine.createSpyObj<RouterStateSnapshot>('RouterStateSnapshot', [
'toString'
]);
routerStateSnapshotMock.url = '/apps';

describe('DotAppsListResolver', () => {
let dotAppsServices: DotAppsService;
let dotLicenseServices: DotLicenseService;
let dotAppsListResolver: DotAppsListResolver;

beforeEach(async(() => {
const testbed = DOTTestBed.configureTestingModule({
providers: [
DotAppsListResolver,
{ provide: DotAppsService, useClass: AppsServicesMock },
{ provide: DotLicenseService, useClass: DotLicenseServicesMock },
{
provide: ActivatedRouteSnapshot,
useValue: activatedRouteSnapshotMock
}
]
});
dotAppsServices = testbed.get(DotAppsService);
dotLicenseServices = testbed.get(DotLicenseService);
dotAppsListResolver = testbed.get(DotAppsListResolver);
}));

it('should get and return an Apps list', () => {
const response = [
{
configurationsCount: 0,
key: 'google-calendar',
name: 'Google Calendar',
description: 'It\'s a tool to keep track of your life\'s events',
iconUrl: '/dA/d948d85c-3bc8-4d85-b0aa-0e989b9ae235/photo/surfer-profile.jpg'
},
{
configurationsCount: 1,
key: 'asana',
name: 'Asana',
description: 'It\'s asana to keep track of your asana events',
iconUrl: '/dA/792c7c9f-6b6f-427b-80ff-1643376c9999/photo/mountain-persona.jpg'
}
];

spyOn(dotAppsServices, 'get').and.returnValue(observableOf(response));
it('should get if portlet can be accessed', () => {
spyOn(dotLicenseServices, 'canAccessEnterprisePortlet').and.returnValue(observableOf(true));

dotAppsListResolver.resolve().subscribe((fakeContentType: any) => {
expect(fakeContentType).toEqual(response);
});
expect(dotAppsServices.get).toHaveBeenCalled();
dotAppsListResolver
.resolve(activatedRouteSnapshotMock, routerStateSnapshotMock)
.subscribe((canAccess: any) => {
expect(canAccess).toEqual(true);
});
expect(dotLicenseServices.canAccessEnterprisePortlet).toHaveBeenCalledWith('/apps');
});
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Observable } from 'rxjs';
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
import { Resolve, RouterStateSnapshot, ActivatedRouteSnapshot } from '@angular/router';
import { DotLicenseService } from '@services/dot-license/dot-license.service';
import { take } from 'rxjs/operators';
import { DotApps } from '@shared/models/dot-apps/dot-apps.model';
import { DotAppsService } from '@services/dot-apps/dot-apps.service';

/**
* Returns apps list from the system
Expand All @@ -13,10 +12,10 @@ import { DotAppsService } from '@services/dot-apps/dot-apps.service';
* @implements {Resolve<DotApps[]>}
*/
@Injectable()
export class DotAppsListResolver implements Resolve<DotApps[]> {
constructor(private dotAppsService: DotAppsService) {}
export class DotAppsListResolver implements Resolve<boolean> {
constructor(private dotLicenseService: DotLicenseService) {}

resolve(): Observable<DotApps[]> {
return this.dotAppsService.get().pipe(take(1));
resolve(_route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
return this.dotLicenseService.canAccessEnterprisePortlet(state.url).pipe(take(1));
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<div class="dot-apps__container">
<div class="dot-apps__header">
<input
pInputText
#searchInput
type="text"
[placeholder]="('apps.search.placeholder' | dm) || ''"
/>
<dot-not-licensed-component *ngIf="!canAccessPortlet; else licensed"></dot-not-licensed-component>
<ng-template #licensed
><div class="dot-apps__container">
<div class="dot-apps__header">
<input
pInputText
#searchInput
type="text"
[placeholder]="('apps.search.placeholder' | dm) || ''"
/>
</div>
<div class="dot-apps__body">
<dot-apps-card
*ngFor="let app of appsCopy"
[app]="app"
(actionFired)="goToApp($event)"
></dot-apps-card>
</div>
</div>
<div class="dot-apps__body">
<dot-apps-card
*ngFor="let app of appsCopy"
[app]="app"
(actionFired)="goToApp($event)"
></dot-apps-card>
</div>
</div>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -14,109 +14,130 @@ import { DotAppsCardModule } from './dot-apps-card/dot-apps-card.module';
import { By } from '@angular/platform-browser';
import { DotAppsCardComponent } from './dot-apps-card/dot-apps-card.component';
import { DotAppsService } from '@services/dot-apps/dot-apps.service';
import { NotLicensedModule } from '@components/not-licensed/not-licensed.module';

class AppsServicesMock {
get() {}
}

const routeDatamock = {
appsServices: [
{
allowExtraParams: true,
configurationsCount: 0,
key: 'google-calendar',
name: 'Google Calendar',
description: "It's a tool to keep track of your life's events",
iconUrl: '/dA/d948d85c-3bc8-4d85-b0aa-0e989b9ae235/photo/surfer-profile.jpg'
},
{
allowExtraParams: true,
configurationsCount: 1,
key: 'asana',
name: 'Asana',
description: "It's asana to keep track of your asana events",
iconUrl: '/dA/792c7c9f-6b6f-427b-80ff-1643376c9999/photo/mountain-persona.jpg'
}
]
};
const appsResponse = [
{
allowExtraParams: true,
configurationsCount: 0,
key: 'google-calendar',
name: 'Google Calendar',
description: "It's a tool to keep track of your life's events",
iconUrl: '/dA/d948d85c-3bc8-4d85-b0aa-0e989b9ae235/photo/surfer-profile.jpg'
},
{
allowExtraParams: true,
configurationsCount: 1,
key: 'asana',
name: 'Asana',
description: "It's asana to keep track of your asana events",
iconUrl: '/dA/792c7c9f-6b6f-427b-80ff-1643376c9999/photo/mountain-persona.jpg'
}
];

let canAccessPortletResponse = { canAccessPortlet: true };

class ActivatedRouteMock {
get data() {
return of(routeDatamock);
return of(canAccessPortletResponse);
}
}

describe('DotAppsListComponent', () => {
let component: DotAppsListComponent;
let fixture: ComponentFixture<DotAppsListComponent>;
let routerService: DotRouterService;
let dotAppsService: DotAppsService;

const messageServiceMock = new MockDotMessageService({
'apps.search.placeholder': 'Search'
});

beforeEach(
async(() => {
DOTTestBed.configureTestingModule({
imports: [
RouterTestingModule.withRoutes([
{
component: DotAppsListComponent,
path: ''
}
]),
DotAppsCardModule,
InputTextModule
],
declarations: [DotAppsListComponent],
providers: [
{ provide: DotMessageService, useValue: messageServiceMock },
beforeEach(async(() => {
DOTTestBed.configureTestingModule({
imports: [
RouterTestingModule.withRoutes([
{
provide: ActivatedRoute,
useClass: ActivatedRouteMock
},
{
provide: DotRouterService,
useClass: MockDotRouterService
},
{ provide: DotAppsService, useClass: AppsServicesMock },
DotAppsListResolver
]
});
})
);
component: DotAppsListComponent,
path: ''
}
]),
DotAppsCardModule,
InputTextModule,
NotLicensedModule
],
declarations: [DotAppsListComponent],
providers: [
{ provide: DotMessageService, useValue: messageServiceMock },
{
provide: ActivatedRoute,
useClass: ActivatedRouteMock
},
{
provide: DotRouterService,
useClass: MockDotRouterService
},
{ provide: DotAppsService, useClass: AppsServicesMock },
DotAppsListResolver
]
});
}));

beforeEach(() => {
fixture = DOTTestBed.createComponent(DotAppsListComponent);
component = fixture.debugElement.componentInstance;
routerService = fixture.debugElement.injector.get(DotRouterService);
fixture.detectChanges();
dotAppsService = fixture.debugElement.injector.get(DotAppsService);
});

it('should set App from resolver', () => {
expect(component.apps).toBe(routeDatamock.appsServices);
expect(component.appsCopy).toEqual(routeDatamock.appsServices);
});
describe('With access to portlet', () => {
beforeEach(() => {
spyOn(dotAppsService, 'get').and.returnValue(of(appsResponse));
fixture.detectChanges();
});

it('should contain 2 app configurations', () => {
expect(fixture.debugElement.queryAll(By.css('dot-apps-card')).length).toBe(2);
});
it('should set App from resolver', () => {
expect(component.apps).toBe(appsResponse);
expect(component.appsCopy).toEqual(appsResponse);
});

it('should set messages to Search Input', () => {
expect(fixture.debugElement.query(By.css('input')).nativeElement.placeholder).toBe(
messageServiceMock.get('apps.search.placeholder')
);
});
it('should contain 2 app configurations', () => {
expect(fixture.debugElement.queryAll(By.css('dot-apps-card')).length).toBe(2);
});

it('should set messages to Search Input', () => {
expect(fixture.debugElement.query(By.css('input')).nativeElement.placeholder).toBe(
messageServiceMock.get('apps.search.placeholder')
);
});

it('should set app data to service Card', () => {
expect(
fixture.debugElement.queryAll(By.css('dot-apps-card'))[0].componentInstance.app
).toEqual(routeDatamock.appsServices[0]);
it('should set app data to service Card', () => {
expect(
fixture.debugElement.queryAll(By.css('dot-apps-card'))[0].componentInstance.app
).toEqual(appsResponse[0]);
});

it('should redirect to detail configuration list page when app Card clicked', () => {
const card: DotAppsCardComponent = fixture.debugElement.queryAll(
By.css('dot-apps-card')
)[0].componentInstance;
card.actionFired.emit(component.apps[0].key);
expect(routerService.goToAppsConfiguration).toHaveBeenCalledWith(component.apps[0].key);
});
});

it('should redirect to detail configuration list page when app Card clicked', () => {
const card: DotAppsCardComponent = fixture.debugElement.queryAll(By.css('dot-apps-card'))[0]
.componentInstance;
card.actionFired.emit(component.apps[0].key);
expect(routerService.goToAppsConfiguration).toHaveBeenCalledWith(component.apps[0].key);
describe('Without access to portlet', () => {
beforeEach(() => {
canAccessPortletResponse = { canAccessPortlet: false };
fixture.detectChanges();
});

it('should display not licensed component', () => {
expect(fixture.debugElement.query(By.css('dot-not-licensed-component'))).toBeTruthy();
});
});
});
Loading

0 comments on commit ea35128

Please sign in to comment.