[AAE-12179] Remove process-services and content-services dependencies… (#8161)

* [AAE-12179] Remove process-services and content-services dependencies from core comment-list component

* [AAE-12179] Remove comment-list injection token

* [AAE-12179] remove token injection in task module and node module
This commit is contained in:
Diogo Bastos
2023-01-31 15:21:01 +00:00
committed by GitHub
parent 11c3a02acc
commit 0ab39e28fd
28 changed files with 304 additions and 262 deletions

View File

@@ -17,117 +17,46 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { CommentModel, UserProcessModel } from '../models';
import { CommentModel } from '../../models/comment.model';
import { CommentListComponent } from './comment-list.component';
import { By } from '@angular/platform-browser';
import { EcmUserService } from '../services/ecm-user.service';
import { PeopleProcessService } from '../services/people-process.service';
import { setupTestBed } from '../testing/setup-test-bed';
import { CoreTestingModule } from '../testing/core.testing.module';
import { setupTestBed } from '../../testing/setup-test-bed';
import { CoreTestingModule } from '../../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core';
const testUser = new UserProcessModel({
id: '1',
firstName: 'Test',
lastName: 'User',
email: 'tu@domain.com'
});
const processCommentOne = new CommentModel({
id: 1,
message: 'Test Comment',
created: new Date(),
createdBy: testUser
});
const processCommentTwo = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
createdBy: testUser
});
const contentCommentUserPictureDefined = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
createdBy: {
enabled: true,
firstName: 'some',
lastName: 'one',
email: 'some-one@somegroup.com',
emailNotificationsEnabled: true,
company: {},
id: 'fake-email@dom.com',
avatarId: '001-001-001'
}
});
const processCommentUserPictureDefined = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
createdBy: {
id: '1',
firstName: 'Test',
lastName: 'User',
email: 'tu@domain.com',
pictureId: '001-001-001'
}
});
const contentCommentUserNoPictureDefined = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
createdBy: {
enabled: true,
firstName: 'some',
lastName: 'one',
email: 'some-one@somegroup.com',
emailNotificationsEnabled: true,
company: {},
id: 'fake-email@dom.com'
}
});
const processCommentUserNoPictureDefined = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
createdBy: {
id: '1',
firstName: 'Test',
lastName: 'User',
email: 'tu@domain.com'
}
});
import {
commentUserNoPictureDefined,
commentUserPictureDefined,
mockCommentOne,
mockCommentTwo,
testUser
} from './mocks/comment-list.mock';
import { CommentListServiceMock } from './mocks/comment-list.service.mock';
import { ADF_COMMENTS_SERVICE } from '../interfaces/comments.token';
describe('CommentListComponent', () => {
let commentList: CommentListComponent;
let fixture: ComponentFixture<CommentListComponent>;
let element: HTMLElement;
let ecmUserService: EcmUserService;
let peopleProcessService: PeopleProcessService;
setupTestBed({
imports: [
TranslateModule.forRoot(),
CoreTestingModule
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
{
provide: ADF_COMMENTS_SERVICE,
useClass: CommentListServiceMock
}
]
});
beforeEach(() => {
ecmUserService = TestBed.inject(EcmUserService);
spyOn(ecmUserService, 'getUserProfileImage').and.returnValue('alfresco-logo.svg');
peopleProcessService = TestBed.inject(PeopleProcessService);
spyOn(peopleProcessService, 'getUserImage').and.returnValue('alfresco-logo.svg');
fixture = TestBed.createComponent(CommentListComponent);
commentList = fixture.componentInstance;
element = fixture.nativeElement;
fixture.detectChanges();
});
@@ -137,7 +66,7 @@ describe('CommentListComponent', () => {
});
it('should emit row click event', fakeAsync(() => {
commentList.comments = [Object.assign({}, processCommentOne)];
commentList.comments = [Object.assign({}, mockCommentOne)];
commentList.clickRow.subscribe((selectedComment: CommentModel) => {
expect(selectedComment.id).toEqual(1);
@@ -154,9 +83,9 @@ describe('CommentListComponent', () => {
}));
it('should deselect the previous selected comment when a new one is clicked', fakeAsync(() => {
processCommentOne.isSelected = true;
const commentOne = Object.assign({}, processCommentOne);
const commentTwo = Object.assign({}, processCommentTwo);
mockCommentOne.isSelected = true;
const commentOne = Object.assign({}, mockCommentOne);
const commentTwo = Object.assign({}, mockCommentTwo);
commentList.selectedComment = commentOne;
commentList.comments = [commentOne, commentTwo];
@@ -182,31 +111,31 @@ describe('CommentListComponent', () => {
});
it('should show comment message when input is given', async () => {
commentList.comments = [Object.assign({}, processCommentOne)];
commentList.comments = [Object.assign({}, mockCommentOne)];
fixture.detectChanges();
await fixture.whenStable();
const elements = fixture.nativeElement.querySelectorAll('.adf-comment-message');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe(processCommentOne.message);
expect(elements[0].innerText).toBe(mockCommentOne.message);
expect(fixture.nativeElement.querySelector('.adf-comment-message:empty')).toBeNull();
});
it('should show comment user when input is given', async () => {
commentList.comments = [Object.assign({}, processCommentOne)];
commentList.comments = [Object.assign({}, mockCommentOne)];
fixture.detectChanges();
await fixture.whenStable();
const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-name');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe(processCommentOne.createdBy.firstName + ' ' + processCommentOne.createdBy.lastName);
expect(elements[0].innerText).toBe(mockCommentOne.createdBy.firstName + ' ' + mockCommentOne.createdBy.lastName);
expect(fixture.nativeElement.querySelector('.adf-comment-user-name:empty')).toBeNull();
});
it('comment date time should start with few seconds ago when comment date is few seconds ago', async () => {
const commentFewSecond = Object.assign({}, processCommentOne);
const commentFewSecond = Object.assign({}, mockCommentOne);
commentFewSecond.created = new Date();
commentList.comments = [commentFewSecond];
@@ -219,7 +148,7 @@ describe('CommentListComponent', () => {
});
it('comment date time should start with Yesterday when comment date is yesterday', async () => {
const commentOld = Object.assign({}, processCommentOne);
const commentOld = Object.assign({}, mockCommentOne);
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000));
commentList.comments = [commentOld];
@@ -231,7 +160,7 @@ describe('CommentListComponent', () => {
});
it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async () => {
const commentOld = Object.assign({}, processCommentOne);
const commentOld = Object.assign({}, mockCommentOne);
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000 * 2));
commentList.comments = [commentOld];
@@ -244,51 +173,29 @@ describe('CommentListComponent', () => {
});
it('should show user icon when input is given', async () => {
commentList.comments = [Object.assign({}, processCommentOne)];
commentList.comments = [Object.assign({}, mockCommentOne)];
fixture.detectChanges();
await fixture.whenStable();
const elements = fixture.nativeElement.querySelectorAll('.adf-comment-img-container');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toContain(commentList.getUserShortName(processCommentOne.createdBy));
expect(elements[0].innerText).toContain(commentList.getUserShortName(mockCommentOne.createdBy));
expect(fixture.nativeElement.querySelector('.adf-comment-img-container:empty')).toBeNull();
});
it('should return content picture when is a content user with a picture', async () => {
commentList.comments = [contentCommentUserPictureDefined];
it('should return picture when is a user with a picture', async () => {
commentList.comments = [commentUserPictureDefined];
fixture.detectChanges();
await fixture.whenStable();
const elements = fixture.nativeElement.querySelectorAll('.adf-people-img');
expect(elements.length).toBe(1);
expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('alfresco-logo.svg');
});
it('should return process picture when is a process user with a picture', async () => {
commentList.comments = [processCommentUserPictureDefined];
fixture.detectChanges();
await fixture.whenStable();
const elements = fixture.nativeElement.querySelectorAll('.adf-people-img');
expect(elements.length).toBe(1);
expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('alfresco-logo.svg');
});
it('should return content short name when is a content user without a picture', async () => {
commentList.comments = [contentCommentUserNoPictureDefined];
fixture.detectChanges();
await fixture.whenStable();
const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon');
expect(elements.length).toBe(1);
});
it('should return process short name when is a process user without a picture', async () => {
commentList.comments = [processCommentUserNoPictureDefined];
it('should return short name when is a user without a picture', async () => {
commentList.comments = [commentUserNoPictureDefined];
fixture.detectChanges();
await fixture.whenStable();

View File

@@ -16,11 +16,11 @@
*/
import { Meta, moduleMetadata, Story } from '@storybook/angular';
import { CoreStoryModule } from '../testing/core.story.module';
import { CoreStoryModule } from '../../testing/core.story.module';
import { CommentListComponent } from './comment-list.component';
import { CommentsModule } from './comments.module';
import { commentsTaskData, commentsNodeData } from './mocks/comments.stories.mock';
import { EcmUserService } from '../services';
import { CommentsModule } from '../comments.module';
import { commentsTaskData, commentsNodeData } from '../mocks/comments.stories.mock';
import { EcmUserService } from '../../services';
export default {
component: CommentListComponent,

View File

@@ -15,13 +15,13 @@
* limitations under the License.
*/
import { Component, EventEmitter, Input, Output, ViewEncapsulation, OnInit, OnDestroy } from '@angular/core';
import { CommentModel } from '../models/comment.model';
import { EcmUserService } from '../services/ecm-user.service';
import { PeopleProcessService } from '../services/people-process.service';
import { UserPreferencesService, UserPreferenceValues } from '../common/services/user-preferences.service';
import { Component, EventEmitter, Input, Output, ViewEncapsulation, OnInit, OnDestroy, Inject } from '@angular/core';
import { CommentModel } from '../../models/comment.model';
import { UserPreferencesService, UserPreferenceValues } from '../../common/services/user-preferences.service';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { CommentsService } from '../interfaces/comments-service.interface';
import { ADF_COMMENTS_SERVICE } from '../interfaces/comments.token';
@Component({
selector: 'adf-comment-list',
@@ -44,9 +44,10 @@ export class CommentListComponent implements OnInit, OnDestroy {
currentLocale;
private onDestroy$ = new Subject<boolean>();
constructor(public peopleProcessService: PeopleProcessService,
public ecmUserService: EcmUserService,
public userPreferenceService: UserPreferencesService) {
constructor(
@Inject(ADF_COMMENTS_SERVICE) private commentsService: Partial<CommentsService>,
public userPreferenceService: UserPreferencesService
) {
}
ngOnInit() {
@@ -88,14 +89,6 @@ export class CommentListComponent implements OnInit, OnDestroy {
}
getUserImage(user: any): string {
if (this.isAContentUsers(user)) {
return this.ecmUserService.getUserProfileImage(user.avatarId);
} else {
return this.peopleProcessService.getUserImage(user);
}
}
private isAContentUsers(user: any): boolean {
return user.avatarId;
return this.commentsService.getUserImage(user);
}
}

View File

@@ -0,0 +1,51 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatListModule } from '@angular/material/list';
import { MatLineModule } from '@angular/material/core';
import { FormsModule } from '@angular/forms';
import { PipeModule } from '../../pipes/pipe.module';
import { CommentListComponent } from './comment-list.component';
@NgModule({
imports: [
PipeModule,
FormsModule,
CommonModule,
TranslateModule,
MatButtonModule,
MatFormFieldModule,
MatInputModule,
MatListModule,
MatLineModule
],
declarations: [
CommentListComponent
],
exports: [
CommentListComponent
]
})
export class CommentListModule {
}

View File

@@ -0,0 +1,18 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './public-api';

View File

@@ -0,0 +1,71 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CommentModel } from '../../../models/comment.model';
import { UserProcessModel } from '../../../models/user-process.model';
export const testUser = new UserProcessModel({
id: '1',
firstName: 'Test',
lastName: 'User',
email: 'tu@domain.com'
});
export const mockCommentOne = new CommentModel({
id: 1,
message: 'Test Comment',
created: new Date(),
createdBy: testUser
});
export const mockCommentTwo = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
createdBy: testUser
});
export const commentUserPictureDefined = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
createdBy: {
enabled: true,
firstName: 'some',
lastName: 'one',
email: 'some-one@somegroup.com',
emailNotificationsEnabled: true,
company: {},
id: 'fake-email@dom.com',
avatarId: '001-001-001'
}
});
export const commentUserNoPictureDefined = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
createdBy: {
enabled: true,
firstName: 'some',
lastName: 'one',
email: 'some-one@somegroup.com',
emailNotificationsEnabled: true,
company: {},
id: 'fake-email@dom.com'
}
});

View File

@@ -0,0 +1,27 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CommentsService } from '../../interfaces/comments-service.interface';
export class CommentListServiceMock implements Partial<CommentsService> {
constructor() {}
getUserImage(_user: any): string {
return 'mock-user-image-path';
}
}

View File

@@ -0,0 +1,20 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './comment-list.component';
export * from './comment-list.module';

View File

@@ -25,8 +25,8 @@ import { MatListModule } from '@angular/material/list';
import { MatLineModule } from '@angular/material/core';
import { FormsModule } from '@angular/forms';
import { PipeModule } from '../pipes/pipe.module';
import { CommentListModule } from './comment-list/comment-list.module';
import { CommentListComponent } from './comment-list.component';
import { CommentsComponent } from './comments.component';
@NgModule({
@@ -39,14 +39,13 @@ import { CommentsComponent } from './comments.component';
MatFormFieldModule,
MatInputModule,
MatListModule,
MatLineModule
MatLineModule,
CommentListModule
],
declarations: [
CommentListComponent,
CommentsComponent
],
exports: [
CommentListComponent,
CommentsComponent
]
})

View File

@@ -21,4 +21,5 @@ import { CommentModel } from '../../models/comment.model';
export interface CommentsService {
get(id: string): Observable<CommentModel[]>;
add(id: string, message: string): Observable<CommentModel>;
getUserImage(user: any): string;
}

View File

@@ -19,7 +19,7 @@ import { CommentModel, EcmUserModel } from '../../models';
import { Observable, of } from 'rxjs';
import { CommentsService } from '../interfaces';
export class CommentsServiceMock implements CommentsService {
export class CommentsServiceMock implements Partial<CommentsService> {
constructor() {}

View File

@@ -20,7 +20,7 @@ import { Observable, of } from 'rxjs';
import { CommentsService } from '../interfaces';
import { testUser } from './comments.stories.mock';
export class CommentsServiceStoriesMock implements CommentsService {
export class CommentsServiceStoriesMock implements Partial<CommentsService> {
constructor() {}

View File

@@ -15,9 +15,10 @@
* limitations under the License.
*/
export * from './comment-list.component';
export * from './comments.component';
export * from './interfaces/index';
export * from './comments.module';
export * from './comment-list/index';

View File

@@ -36,6 +36,7 @@ import { ViewerModule } from './viewer/viewer.module';
import { FormBaseModule } from './form/form-base.module';
import { SidenavLayoutModule } from './layout/layout.module';
import { CommentsModule } from './comments/comments.module';
import { CommentListModule } from './comments/comment-list/comment-list.module';
import { ButtonsMenuModule } from './buttons-menu/buttons-menu.module';
import { TemplateModule } from './templates/template.module';
import { ClipboardModule } from './clipboard/clipboard.module';
@@ -85,6 +86,7 @@ import { MAT_SNACK_BAR_DEFAULT_OPTIONS } from '@angular/material/snack-bar';
CardViewModule,
FormBaseModule,
CommentsModule,
CommentListModule,
LoginModule,
LanguageMenuModule,
InfoDrawerModule,
@@ -124,6 +126,7 @@ import { MAT_SNACK_BAR_DEFAULT_OPTIONS } from '@angular/material/snack-bar';
CardViewModule,
FormBaseModule,
CommentsModule,
CommentListModule,
LoginModule,
LanguageMenuModule,
InfoDrawerModule,