mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[AE-11486] remove unused comment services and improve doc (#8092)
* remove unused comment services and improve doc * fix after review * fix unit test * fix stories
This commit is contained in:
parent
aa37cad995
commit
6f6af8cd4e
@ -207,12 +207,19 @@ v6.0.0 and after:
|
||||
|
||||
this.nodesApiService.nodeUpdated.pipe .....
|
||||
|
||||
### Comments component
|
||||
|
||||
```adf-comments``` component is now a real presentational components. The `taskId` and `nodeId` has now renamed to `id`
|
||||
The ```adf-comments``` has now two specialization in :
|
||||
|
||||
- ```adf-node-comments``` [Node Comments Componen](../content-services/components/node-comments.component.md)
|
||||
- ```adf-task-comments``` [Task Comments Component](../process-services/components/task-comments.component.md)
|
||||
|
||||
|
||||
## Renamed items
|
||||
|
||||
### New Classes or Services
|
||||
|
||||
### Properties and methods
|
||||
|
||||
- `<adf-comments>`: The `taskId` input has now been renamed as `id`
|
||||
|
||||
### Component selectors
|
||||
|
@ -19,7 +19,7 @@ import { Meta, moduleMetadata, Story } from '@storybook/angular';
|
||||
import { CoreStoryModule } from '../testing/core.story.module';
|
||||
import { CommentListComponent } from './comment-list.component';
|
||||
import { CommentsModule } from './comments.module';
|
||||
import { commentsTaskData, commentsNodeData } from '../mock/comment-content.mock';
|
||||
import { commentsTaskData, commentsNodeData } from './mocks/comments.stories.mock';
|
||||
import { EcmUserService } from '../services';
|
||||
|
||||
export default {
|
||||
|
@ -103,3 +103,65 @@ export const commentsStoriesData: CommentModel[] = [
|
||||
isSelected: false
|
||||
}
|
||||
];
|
||||
|
||||
export const commentsNodeData: CommentModel[] = [
|
||||
{
|
||||
id: 1,
|
||||
message: `I've done this component, is it cool?`,
|
||||
created: getDateXMinutesAgo(30),
|
||||
createdBy: johnDoe,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
message: 'Yeah',
|
||||
created: getDateXMinutesAgo(15),
|
||||
createdBy: janeEod,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
message: '+1',
|
||||
created: getDateXMinutesAgo(12),
|
||||
createdBy: robertSmith,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
message: 'ty',
|
||||
created: new Date(),
|
||||
createdBy: johnDoe,
|
||||
isSelected: false
|
||||
}
|
||||
];
|
||||
|
||||
export const commentsTaskData: CommentModel[] = [
|
||||
{
|
||||
id: 1,
|
||||
message: `I've done this task, what's next?`,
|
||||
created: getDateXMinutesAgo(30),
|
||||
createdBy: johnDoe,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
message: `I've assigned you another one 🤠`,
|
||||
created: getDateXMinutesAgo(15),
|
||||
createdBy: janeEod,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
message: '+1',
|
||||
created: getDateXMinutesAgo(12),
|
||||
createdBy: robertSmith,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
message: 'Cheers',
|
||||
created: new Date(),
|
||||
createdBy: johnDoe,
|
||||
isSelected: false
|
||||
}
|
||||
];
|
||||
|
@ -1,44 +0,0 @@
|
||||
/*!
|
||||
* @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 { Injectable } from '@angular/core';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { CommentModel } from '../models/comment.model';
|
||||
import { CommentContentServiceInterface } from '../services/comment-content.service.interface';
|
||||
import { testUser } from '../mock/comment-content.mock';
|
||||
|
||||
@Injectable()
|
||||
export class CommentContentServiceMock implements CommentContentServiceInterface {
|
||||
private comments: CommentModel [] = [];
|
||||
|
||||
addNodeComment(nodeId: string, message: string): Observable<CommentModel> {
|
||||
const comment = new CommentModel({
|
||||
id: nodeId,
|
||||
message: message,
|
||||
created: new Date(),
|
||||
createdBy: testUser,
|
||||
isSelected: false
|
||||
});
|
||||
this.comments.push(comment);
|
||||
|
||||
return of(comment);
|
||||
}
|
||||
|
||||
getNodeComments(_nodeId: string): Observable<CommentModel[]>{
|
||||
return of(this.comments);
|
||||
};
|
||||
}
|
@ -1,209 +0,0 @@
|
||||
/*!
|
||||
* @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, EcmCompanyModel, EcmUserModel } from '../models';
|
||||
|
||||
export const fakeUser1 = {
|
||||
enabled: true,
|
||||
firstName: 'firstName',
|
||||
lastName: 'lastName',
|
||||
email: 'fake-email@dom.com',
|
||||
emailNotificationsEnabled: true,
|
||||
company: {},
|
||||
id: 'fake-email@dom.com',
|
||||
avatarId: '123-123-123'
|
||||
};
|
||||
|
||||
export const fakeUser2 = {
|
||||
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 fakeContentComments = {
|
||||
list: {
|
||||
pagination: {
|
||||
count: 4,
|
||||
hasMoreItems: false,
|
||||
totalItems: 4,
|
||||
skipCount: 0,
|
||||
maxItems: 100
|
||||
},
|
||||
entries: [{
|
||||
entry: {
|
||||
createdAt: '2018-03-27T10:55:45.725+0000',
|
||||
createdBy: fakeUser1,
|
||||
edited: false,
|
||||
modifiedAt: '2018-03-27T10:55:45.725+0000',
|
||||
canEdit: true,
|
||||
modifiedBy: fakeUser1,
|
||||
canDelete: true,
|
||||
id: '35a0cea7-b6d0-4abc-9030-f4e461dd1ac7',
|
||||
content: 'fake-message-1'
|
||||
}
|
||||
}, {
|
||||
entry: {
|
||||
createdAt: '2018-03-27T10:55:45.725+0000',
|
||||
createdBy: fakeUser2,
|
||||
edited: false,
|
||||
modifiedAt: '2018-03-27T10:55:45.725+0000',
|
||||
canEdit: true,
|
||||
modifiedBy: fakeUser2,
|
||||
canDelete: true,
|
||||
id: '35a0cea7-b6d0-4abc-9030-f4e461dd1ac7',
|
||||
content: 'fake-message-2'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
export const fakeContentComment = {
|
||||
entry: {
|
||||
createdAt: '2018-03-29T11:49:51.735+0000',
|
||||
createdBy: fakeUser1,
|
||||
edited: false,
|
||||
modifiedAt: '2018-03-29T11:49:51.735+0000',
|
||||
canEdit: true,
|
||||
modifiedBy: fakeUser1,
|
||||
canDelete: true,
|
||||
id: '4d07cdc5-f00c-4391-b39d-a842b12478b2',
|
||||
content: 'fake-comment-message'
|
||||
}
|
||||
};
|
||||
|
||||
const fakeCompany: EcmCompanyModel = {
|
||||
organization: '',
|
||||
address1: '',
|
||||
address2: '',
|
||||
address3: '',
|
||||
postcode: '',
|
||||
telephone: '',
|
||||
fax: '',
|
||||
email: ''
|
||||
};
|
||||
|
||||
const johnDoe: EcmUserModel = {
|
||||
id: '1',
|
||||
email: 'john.doe@alfresco.com',
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
company: fakeCompany,
|
||||
enabled: true,
|
||||
isAdmin: undefined,
|
||||
avatarId: '001'
|
||||
};
|
||||
|
||||
const janeEod: EcmUserModel = {
|
||||
id: '2',
|
||||
email: 'jane.eod@alfresco.com',
|
||||
firstName: 'Jane',
|
||||
lastName: 'Eod',
|
||||
company: fakeCompany,
|
||||
enabled: true,
|
||||
isAdmin: undefined
|
||||
};
|
||||
|
||||
const robertSmith: EcmUserModel = {
|
||||
id: '3',
|
||||
email: 'robert.smith@alfresco.com',
|
||||
firstName: 'Robert',
|
||||
lastName: 'Smith',
|
||||
company: fakeCompany,
|
||||
enabled: true,
|
||||
isAdmin: undefined
|
||||
};
|
||||
|
||||
export const testUser: EcmUserModel = {
|
||||
id: '44',
|
||||
email: 'test.user@hyland.com',
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
company: fakeCompany,
|
||||
enabled: true,
|
||||
isAdmin: undefined,
|
||||
avatarId: '044'
|
||||
};
|
||||
|
||||
export const getDateXMinutesAgo = (minutes: number) => new Date(new Date().getTime() - minutes * 60000);
|
||||
|
||||
export const commentsNodeData: CommentModel[] = [
|
||||
{
|
||||
id: 1,
|
||||
message: `I've done this component, is it cool?`,
|
||||
created: getDateXMinutesAgo(30),
|
||||
createdBy: johnDoe,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
message: 'Yeah',
|
||||
created: getDateXMinutesAgo(15),
|
||||
createdBy: janeEod,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
message: '+1',
|
||||
created: getDateXMinutesAgo(12),
|
||||
createdBy: robertSmith,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
message: 'ty',
|
||||
created: new Date(),
|
||||
createdBy: johnDoe,
|
||||
isSelected: false
|
||||
}
|
||||
];
|
||||
|
||||
export const commentsTaskData: CommentModel[] = [
|
||||
{
|
||||
id: 1,
|
||||
message: `I've done this task, what's next?`,
|
||||
created: getDateXMinutesAgo(30),
|
||||
createdBy: johnDoe,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
message: `I've assigned you another one 🤠`,
|
||||
created: getDateXMinutesAgo(15),
|
||||
createdBy: janeEod,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
message: '+1',
|
||||
created: getDateXMinutesAgo(12),
|
||||
createdBy: robertSmith,
|
||||
isSelected: false
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
message: 'Cheers',
|
||||
created: new Date(),
|
||||
createdBy: johnDoe,
|
||||
isSelected: false
|
||||
}
|
||||
];
|
@ -1,42 +0,0 @@
|
||||
/*!
|
||||
* @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 fakeUser1 = { id: 1, email: 'fake-email@dom.com', firstName: 'firstName', lastName: 'lastName' };
|
||||
|
||||
export const fakeUser2 = { id: 1001, email: 'some-one@somegroup.com', firstName: 'some', lastName: 'one' };
|
||||
|
||||
export const fakeTasksComment = {
|
||||
size: 2, total: 2, start: 0,
|
||||
data: [
|
||||
{
|
||||
id: 1, message: 'fake-message-1', created: '', createdBy: fakeUser1
|
||||
},
|
||||
{
|
||||
id: 2, message: 'fake-message-2', created: '', createdBy: fakeUser1
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export const fakeProcessComment = new CommentModel({id: 1, message: 'Test', created: new Date('2016-11-10T03:37:30.010+0000'), createdBy: new UserProcessModel({
|
||||
id: 13,
|
||||
firstName: 'Wilbur',
|
||||
lastName: 'Adams',
|
||||
email: 'wilbur@app.com'
|
||||
})});
|
@ -17,7 +17,6 @@
|
||||
|
||||
export * from './alfresco-api.mock';
|
||||
export * from './bpm-user.service.mock';
|
||||
export * from './comment-process-service.mock';
|
||||
export * from './cookie.service.mock';
|
||||
export * from './ecm-user.service.mock';
|
||||
export * from './event.mock';
|
||||
|
@ -1,90 +0,0 @@
|
||||
/*!
|
||||
* @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 { TestBed } from '@angular/core/testing';
|
||||
import { CommentModel } from '../models/comment.model';
|
||||
import { fakeContentComment, fakeContentComments } from '../mock/comment-content.mock';
|
||||
import { CommentContentService } from './comment-content.service';
|
||||
import { setupTestBed } from '../testing/setup-test-bed';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
describe('Comment Content Service', () => {
|
||||
|
||||
let service: CommentContentService;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.inject(CommentContentService);
|
||||
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
describe('Node comments', () => {
|
||||
|
||||
it('should add a comment node ', (done) => {
|
||||
service.addNodeComment('999', 'fake-comment-message').subscribe(
|
||||
(res: CommentModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).not.toEqual(null);
|
||||
expect(res.message).toEqual('fake-comment-message');
|
||||
expect(res.created).not.toEqual(null);
|
||||
expect(res.createdBy.email).toEqual('fake-email@dom.com');
|
||||
expect(res.createdBy.firstName).toEqual('firstName');
|
||||
expect(res.createdBy.lastName).toEqual('lastName');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeContentComment)
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the nodes comments ', (done) => {
|
||||
service.getNodeComments('999').subscribe(
|
||||
(res: CommentModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(2);
|
||||
expect(res[0].message).toEqual('fake-message-1');
|
||||
expect(res[1].message).toEqual('fake-message-2');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeContentComments)
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,92 +0,0 @@
|
||||
/*!
|
||||
* @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 { Injectable } from '@angular/core';
|
||||
import { Observable, from, throwError } from 'rxjs';
|
||||
import { CommentModel } from '../models/comment.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { LogService } from '../common/services/log.service';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { CommentEntry, CommentsApi } from '@alfresco/js-api';
|
||||
import { CommentContentServiceInterface } from './comment-content.service.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CommentContentService implements CommentContentServiceInterface {
|
||||
|
||||
_commentsApi: CommentsApi;
|
||||
get commentsApi(): CommentsApi {
|
||||
this._commentsApi = this._commentsApi ?? new CommentsApi(this.apiService.getInstance());
|
||||
return this._commentsApi;
|
||||
}
|
||||
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private logService: LogService) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a comment to a node.
|
||||
*
|
||||
* @param nodeId ID of the target node
|
||||
* @param message Text for the comment
|
||||
* @returns Details of the comment added
|
||||
*/
|
||||
addNodeComment(nodeId: string, message: string): Observable<CommentModel> {
|
||||
return from(this.commentsApi.createComment(nodeId, { content: message }))
|
||||
.pipe(
|
||||
map((response: CommentEntry) => new CommentModel({
|
||||
id: response.entry.id,
|
||||
message: response.entry.content,
|
||||
created: response.entry.createdAt,
|
||||
createdBy: response.entry.createdBy
|
||||
})),
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all comments that have been added to a node.
|
||||
*
|
||||
* @param nodeId ID of the target node
|
||||
* @returns Details for each comment
|
||||
*/
|
||||
getNodeComments(nodeId: string): Observable<CommentModel[]> {
|
||||
return from(this.commentsApi.listComments(nodeId))
|
||||
.pipe(
|
||||
map((response) => {
|
||||
const comments: CommentModel[] = [];
|
||||
response.list.entries.forEach((comment: any) => {
|
||||
comments.push(new CommentModel({
|
||||
id: comment.entry.id,
|
||||
message: comment.entry.content,
|
||||
created: comment.entry.createdAt,
|
||||
createdBy: comment.entry.createdBy
|
||||
}));
|
||||
});
|
||||
return comments;
|
||||
}),
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
}
|
||||
|
||||
private handleError(error: any) {
|
||||
this.logService.error(error);
|
||||
return throwError(error || 'Server error');
|
||||
}
|
||||
|
||||
}
|
@ -1,190 +0,0 @@
|
||||
/*!
|
||||
* @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 { TestBed } from '@angular/core/testing';
|
||||
import { CommentModel } from '../models/comment.model';
|
||||
import { fakeProcessComment, fakeTasksComment, fakeUser1 } from '../mock/comment-process.mock';
|
||||
import { CommentProcessService } from './comment-process.service';
|
||||
import { setupTestBed } from '../testing/setup-test-bed';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
describe('Comment ProcessService Service', () => {
|
||||
|
||||
let service: CommentProcessService;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.inject(CommentProcessService);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
describe('Process comments', () => {
|
||||
|
||||
const processId = '1001';
|
||||
|
||||
describe('get comments', () => {
|
||||
|
||||
let getProcessInstanceComments: jasmine.Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
getProcessInstanceComments = spyOn(service['commentsApi'], 'getProcessInstanceComments')
|
||||
.and
|
||||
.returnValue(Promise.resolve({ data: [fakeProcessComment, fakeProcessComment] }) as any);
|
||||
});
|
||||
|
||||
it('should return the correct number of comments', (done) => {
|
||||
service.getProcessInstanceComments(processId).subscribe((tasks) => {
|
||||
expect(tasks.length).toBe(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the correct comment data', (done) => {
|
||||
service.getProcessInstanceComments(processId).subscribe((comments) => {
|
||||
const comment: any = comments[0];
|
||||
expect(comment.id).toBe(fakeProcessComment.id);
|
||||
expect(comment.created).toBe(fakeProcessComment.created);
|
||||
expect(comment.message).toBe(fakeProcessComment.message);
|
||||
expect(comment.createdBy.id).toBe(fakeProcessComment.createdBy.id);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should call service to fetch process instance comments', () => {
|
||||
service.getProcessInstanceComments(processId);
|
||||
expect(getProcessInstanceComments).toHaveBeenCalledWith(processId);
|
||||
});
|
||||
|
||||
it('should return a default error if no data is returned by the API', (done) => {
|
||||
getProcessInstanceComments = getProcessInstanceComments.and.returnValue(Promise.reject(null));
|
||||
service.getProcessInstanceComments(processId).subscribe(
|
||||
() => {
|
||||
},
|
||||
(res) => {
|
||||
expect(res).toBe('Server error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('add comment', () => {
|
||||
|
||||
const message = 'Test message';
|
||||
let addProcessInstanceComment: jasmine.Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
addProcessInstanceComment = spyOn(service['commentsApi'], 'addProcessInstanceComment')
|
||||
.and
|
||||
.returnValue(Promise.resolve(fakeProcessComment) as any);
|
||||
});
|
||||
|
||||
it('should call service to add comment', () => {
|
||||
service.addProcessInstanceComment(processId, message);
|
||||
expect(addProcessInstanceComment).toHaveBeenCalledWith({
|
||||
message
|
||||
}, processId);
|
||||
});
|
||||
|
||||
it('should return the created comment', (done) => {
|
||||
service.addProcessInstanceComment(processId, message).subscribe((comment) => {
|
||||
expect(comment.id).toBe(fakeProcessComment.id);
|
||||
expect(comment.created).toBe(fakeProcessComment.created);
|
||||
expect(comment.message).toBe(fakeProcessComment.message);
|
||||
expect(comment.createdBy).toBe(fakeProcessComment.createdBy);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a default error if no data is returned by the API', (done) => {
|
||||
addProcessInstanceComment = addProcessInstanceComment.and.returnValue(Promise.reject(null));
|
||||
service.addProcessInstanceComment(processId, message).subscribe(
|
||||
() => {
|
||||
},
|
||||
(res) => {
|
||||
expect(res).toBe('Server error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('Task comments', () => {
|
||||
|
||||
it('should add a comment task ', (done) => {
|
||||
service.addTaskComment('999', 'fake-comment-message').subscribe(
|
||||
(res: CommentModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).not.toEqual(null);
|
||||
expect(res.message).toEqual('fake-comment-message');
|
||||
expect(res.created).not.toEqual(null);
|
||||
expect(res.createdBy.email).toEqual('fake-email@dom.com');
|
||||
expect(res.createdBy.firstName).toEqual('firstName');
|
||||
expect(res.createdBy.lastName).toEqual('lastName');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({
|
||||
id: '111', message: 'fake-comment-message',
|
||||
createdBy: fakeUser1,
|
||||
created: '2016-07-15T11:19:17.440+0000'
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the tasks comments ', (done) => {
|
||||
service.getTaskComments('999').subscribe(
|
||||
(res: CommentModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(2);
|
||||
expect(res[0].message).toEqual('fake-message-1');
|
||||
expect(res[1].message).toEqual('fake-message-2');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeTasksComment)
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -31,8 +31,6 @@ export * from './people-content.service';
|
||||
export * from './people-process.service';
|
||||
export * from './shared-links-api.service';
|
||||
export * from './discovery-api.service';
|
||||
export * from './comment-process.service';
|
||||
export * from './comment-content.service';
|
||||
export * from './login-dialog.service';
|
||||
export * from './external-alfresco-api.service';
|
||||
export * from './download-zip.service';
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { CommentModel } from '../models/comment.model';
|
||||
import { CommentModel } from '@alfresco/adf-core';
|
||||
|
||||
export interface CommentProcessServiceInterface {
|
||||
addTaskComment(taskId: string, message: string): Observable<CommentModel>;
|
@ -18,9 +18,9 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, from, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { CommentModel, UserProcessModel } from '../models';
|
||||
import { CommentProcessServiceInterface } from '../services/comment-process.service.interface';
|
||||
import { testUser, fakeUser1 } from '../mock/comment-content.mock';
|
||||
import { CommentModel, UserProcessModel } from '@alfresco/adf-core';
|
||||
import { CommentProcessServiceInterface } from '../interfaces/comment-process.service.interface';
|
||||
import { testUser, fakeUser1 } from '../mock/comment-process.mock';
|
||||
|
||||
@Injectable()
|
||||
export class CommentProcessServiceMock implements CommentProcessServiceInterface {
|
@ -15,10 +15,26 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { CommentModel } from '../models/comment.model';
|
||||
import { EcmUserModel } from '@alfresco/adf-core';
|
||||
|
||||
export interface CommentContentServiceInterface {
|
||||
addNodeComment(nodeId: string, message: string): Observable<CommentModel>;
|
||||
getNodeComments(nodeId: string): Observable<CommentModel[]>;
|
||||
}
|
||||
export const fakeUser1 = { id: 1, email: 'fake-email@dom.com', firstName: 'firstName', lastName: 'lastName' };
|
||||
|
||||
export const testUser: EcmUserModel = {
|
||||
id: '44',
|
||||
email: 'test.user@hyland.com',
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
company: {
|
||||
organization: '',
|
||||
address1: '',
|
||||
address2: '',
|
||||
address3: '',
|
||||
postcode: '',
|
||||
telephone: '',
|
||||
fax: '',
|
||||
email: ''
|
||||
},
|
||||
enabled: true,
|
||||
isAdmin: undefined,
|
||||
avatarId: '044'
|
||||
};
|
@ -19,7 +19,8 @@ import { SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { of, throwError } from 'rxjs';
|
||||
|
||||
import { CommentProcessService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { CommentProcessService } from './services/comment-process.service';
|
||||
|
||||
import { ProcessCommentsComponent } from './process-comments.component';
|
||||
import { ProcessTestingModule } from '../testing/process.testing.module';
|
||||
|
@ -15,7 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CommentModel, CommentProcessService } from '@alfresco/adf-core';
|
||||
import { CommentModel } from '@alfresco/adf-core';
|
||||
import { CommentProcessService } from './services/comment-process.service';
|
||||
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, OnDestroy, ViewEncapsulation } from '@angular/core';
|
||||
import { Observable, Observer, Subject } from 'rxjs';
|
||||
import { share, takeUntil } from 'rxjs/operators';
|
||||
|
@ -17,4 +17,6 @@
|
||||
|
||||
export * from './process-comments.component';
|
||||
|
||||
export * from './services/comment-process.service';
|
||||
|
||||
export * from './process-comments.module';
|
||||
|
@ -17,13 +17,10 @@
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, from, throwError } from 'rxjs';
|
||||
import { CommentModel } from '../models/comment.model';
|
||||
import { UserProcessModel } from '../models/user-process.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { LogService } from '../common/services/log.service';
|
||||
import { CommentModel, UserProcessModel, AlfrescoApiService, LogService } from '@alfresco/adf-core';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { ActivitiCommentsApi } from '@alfresco/js-api';
|
||||
import { CommentProcessServiceInterface } from './comment-process.service.interface';
|
||||
import { CommentProcessServiceInterface } from '../interfaces/comment-process.service.interface';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
@ -20,7 +20,8 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
import { setupTestBed, CommentProcessService } from '@alfresco/adf-core';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { CommentProcessService } from '../../process-comments/services/comment-process.service';
|
||||
import { TaskListModule } from '../../task-list/task-list.module';
|
||||
|
||||
import { exampleProcess, exampleProcessNoName, mockRunningProcess, processEnded } from './../../mock';
|
||||
|
@ -25,11 +25,12 @@ import {
|
||||
FormOutcomeModel,
|
||||
setupTestBed,
|
||||
BpmUserService,
|
||||
CommentProcessService, LogService,
|
||||
LogService,
|
||||
UserProcessModel,
|
||||
PeopleProcessService,
|
||||
CommentModel
|
||||
} from '@alfresco/adf-core';
|
||||
import { CommentProcessService } from '../../process-comments/services/comment-process.service';
|
||||
import { TaskDetailsModel } from '../models/task-details.model';
|
||||
import {
|
||||
noDataMock,
|
||||
|
Loading…
x
Reference in New Issue
Block a user