mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
[AAE-1950] and [AAE-1882] more unit test (#5521)
* [AAE-1882] Custom action unit test * [AAE-1950] Filter E2E Community Unit test
This commit is contained in:
parent
9d8479c259
commit
b5d443f2a8
@ -384,7 +384,7 @@ describe('DocumentList', () => {
|
|||||||
new ContentActionModel({
|
new ContentActionModel({
|
||||||
target: 'document',
|
target: 'document',
|
||||||
title: 'Action1',
|
title: 'Action1',
|
||||||
disabled: (): boolean => true
|
disabled: (node): boolean => node.entry.name === 'custom'
|
||||||
}),
|
}),
|
||||||
new ContentActionModel({
|
new ContentActionModel({
|
||||||
target: 'document',
|
target: 'document',
|
||||||
@ -393,12 +393,17 @@ describe('DocumentList', () => {
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
const nodeFile = { entry: { isFile: true, name: 'xyz' } };
|
let actions = documentList.getNodeActions({ entry: { id: 1, isFile: true, name: 'xyz' } });
|
||||||
const actions = documentList.getNodeActions(nodeFile);
|
|
||||||
|
|
||||||
expect(actions.length).toBe(2);
|
expect(actions.length).toBe(2);
|
||||||
expect(actions[0].disabled).toBeTruthy();
|
expect(actions[0].disabled).toBe(false);
|
||||||
expect(actions[1].disabled).toBeFalsy();
|
expect(actions[1].disabled).toBe(false);
|
||||||
|
|
||||||
|
actions = documentList.getNodeActions({ entry: { id: 2, isFile: true, name: 'custom' } });
|
||||||
|
|
||||||
|
expect(actions.length).toBe(2);
|
||||||
|
expect(actions[0].disabled).toBe(true);
|
||||||
|
expect(actions[1].disabled).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not disable the action if there is copy permission', () => {
|
it('should not disable the action if there is copy permission', () => {
|
||||||
|
@ -14,21 +14,33 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { async, TestBed } from '@angular/core/testing';
|
|
||||||
import { setupTestBed, CoreModule, IdentityUserService } from '@alfresco/adf-core';
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import {
|
||||||
|
AlfrescoApiService,
|
||||||
|
AlfrescoApiServiceMock,
|
||||||
|
AppConfigService,
|
||||||
|
AppConfigServiceMock,
|
||||||
|
IdentityUserService,
|
||||||
|
JwtHelperService,
|
||||||
|
LogService,
|
||||||
|
setupTestBed,
|
||||||
|
StorageService
|
||||||
|
} from '@alfresco/adf-core';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service';
|
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service';
|
||||||
import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service';
|
import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service';
|
||||||
import { TaskFilterCloudService } from './task-filter-cloud.service';
|
import { TaskFilterCloudService } from './task-filter-cloud.service';
|
||||||
import {
|
import {
|
||||||
fakeTaskCloudPreferenceList,
|
|
||||||
fakeTaskCloudFilters,
|
|
||||||
fakeEmptyTaskCloudPreferenceList,
|
fakeEmptyTaskCloudPreferenceList,
|
||||||
fakePreferenceWithNoTaskFilterPreference,
|
fakePreferenceWithNoTaskFilterPreference,
|
||||||
|
fakeTaskCloudFilters,
|
||||||
|
fakeTaskCloudPreferenceList,
|
||||||
fakeTaskFilter
|
fakeTaskFilter
|
||||||
} from '../mock/task-filters-cloud.mock';
|
} from '../mock/task-filters-cloud.mock';
|
||||||
import { UserPreferenceCloudService } from '../../../services/user-preference-cloud.service';
|
import { UserPreferenceCloudService } from '../../../services/user-preference-cloud.service';
|
||||||
import { PreferenceCloudServiceInterface } from '../../../services/preference-cloud.interface';
|
import { PreferenceCloudServiceInterface } from '../../../services/preference-cloud.interface';
|
||||||
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||||
|
|
||||||
describe('TaskFilterCloudService', () => {
|
describe('TaskFilterCloudService', () => {
|
||||||
let service: TaskFilterCloudService;
|
let service: TaskFilterCloudService;
|
||||||
@ -44,17 +56,21 @@ describe('TaskFilterCloudService', () => {
|
|||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [
|
imports: [
|
||||||
CoreModule.forRoot()
|
HttpClientTestingModule
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
TaskFilterCloudService,
|
TaskFilterCloudService,
|
||||||
LocalPreferenceCloudService,
|
IdentityUserService,
|
||||||
{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService },
|
LogService,
|
||||||
IdentityUserService
|
JwtHelperService,
|
||||||
|
StorageService,
|
||||||
|
{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: UserPreferenceCloudService },
|
||||||
|
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
|
||||||
|
{ provide: AppConfigService, useClass: AppConfigServiceMock }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(() => {
|
||||||
service = TestBed.get(TaskFilterCloudService);
|
service = TestBed.get(TaskFilterCloudService);
|
||||||
preferenceCloudService = service.preferenceService;
|
preferenceCloudService = service.preferenceService;
|
||||||
identityUserService = TestBed.get(IdentityUserService);
|
identityUserService = TestBed.get(IdentityUserService);
|
||||||
@ -63,14 +79,10 @@ describe('TaskFilterCloudService', () => {
|
|||||||
getPreferencesSpy = spyOn(preferenceCloudService, 'getPreferences').and.returnValue(of(fakeTaskCloudPreferenceList));
|
getPreferencesSpy = spyOn(preferenceCloudService, 'getPreferences').and.returnValue(of(fakeTaskCloudPreferenceList));
|
||||||
getPreferenceByKeySpy = spyOn(preferenceCloudService, 'getPreferenceByKey').and.returnValue(of(fakeTaskCloudFilters));
|
getPreferenceByKeySpy = spyOn(preferenceCloudService, 'getPreferenceByKey').and.returnValue(of(fakeTaskCloudFilters));
|
||||||
getCurrentUserInfoSpy = spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(identityUserMock);
|
getCurrentUserInfoSpy = spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(identityUserMock);
|
||||||
}));
|
|
||||||
|
|
||||||
it('should create TaskFilterCloudService instance', () => {
|
|
||||||
expect(service).toBeDefined();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to use LocalPreferenceCloudService', () => {
|
it('should be able to use UserPreferenceCloudService', () => {
|
||||||
expect(preferenceCloudService instanceof LocalPreferenceCloudService).toBeTruthy();
|
expect(preferenceCloudService instanceof UserPreferenceCloudService).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create task filter key by using appName and the username', (done) => {
|
it('should create task filter key by using appName and the username', (done) => {
|
||||||
@ -221,37 +233,73 @@ describe('TaskFilterCloudService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Inject [UserPreferenceCloudService] into the TaskFilterCloudService', () => {
|
describe('Inject [LocalPreferenceCloudService] into the TaskFilterCloudService', () => {
|
||||||
let service: TaskFilterCloudService;
|
let service: TaskFilterCloudService;
|
||||||
let preferenceCloudService: PreferenceCloudServiceInterface;
|
let preferenceCloudService: PreferenceCloudServiceInterface;
|
||||||
let identityUserService: IdentityUserService;
|
let identityUserService: IdentityUserService;
|
||||||
|
let getPreferencesSpy: jasmine.Spy;
|
||||||
|
|
||||||
const identityUserMock = { username: 'fakeusername', firstName: 'fake-identity-first-name', lastName: 'fake-identity-last-name', email: 'fakeIdentity@email.com' };
|
const identityUserMock = { username: 'fakeusername', firstName: 'fake-identity-first-name', lastName: 'fake-identity-last-name', email: 'fakeIdentity@email.com' };
|
||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [
|
imports: [
|
||||||
CoreModule.forRoot()
|
HttpClientTestingModule
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
TaskFilterCloudService,
|
TaskFilterCloudService,
|
||||||
LocalPreferenceCloudService,
|
IdentityUserService,
|
||||||
{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: UserPreferenceCloudService },
|
StorageService,
|
||||||
IdentityUserService
|
{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(() => {
|
||||||
service = TestBed.get(TaskFilterCloudService);
|
service = TestBed.get(TaskFilterCloudService);
|
||||||
preferenceCloudService = service.preferenceService;
|
preferenceCloudService = service.preferenceService;
|
||||||
identityUserService = TestBed.get(IdentityUserService);
|
identityUserService = TestBed.get(IdentityUserService);
|
||||||
|
getPreferencesSpy = spyOn(preferenceCloudService, 'getPreferences').and.returnValue(of([]));
|
||||||
spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(identityUserMock);
|
spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(identityUserMock);
|
||||||
}));
|
|
||||||
|
|
||||||
it('should create TaskFilterCloudService instance', () => {
|
|
||||||
expect(service).toBeDefined();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to inject UserPreferenceCloudService when you override with user preferece service', () => {
|
it('should be able to inject LocalPreferenceCloudService when you override with user preference service', () => {
|
||||||
expect(preferenceCloudService instanceof UserPreferenceCloudService).toBeTruthy();
|
expect(preferenceCloudService instanceof LocalPreferenceCloudService).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create default task filters if there are no task filter preferences', (done) => {
|
||||||
|
const appName = 'fakeAppName';
|
||||||
|
service.getTaskListFilters(appName).subscribe((res) => {
|
||||||
|
expect(res.length).toEqual(2);
|
||||||
|
|
||||||
|
expect(res[0].name).toEqual('ADF_CLOUD_TASK_FILTERS.MY_TASKS');
|
||||||
|
expect(res[0].key).toEqual('my-tasks');
|
||||||
|
expect(res[0].appName).toEqual(appName);
|
||||||
|
expect(res[0].icon).toEqual('inbox');
|
||||||
|
expect(res[0].status).toEqual('ASSIGNED');
|
||||||
|
expect(res[0].assignee).toEqual(identityUserMock.username);
|
||||||
|
|
||||||
|
expect(res[1].name).toEqual('ADF_CLOUD_TASK_FILTERS.COMPLETED_TASKS');
|
||||||
|
expect(res[1].key).toEqual('completed-tasks');
|
||||||
|
expect(res[1].appName).toEqual(appName);
|
||||||
|
expect(res[1].icon).toEqual('done');
|
||||||
|
expect(res[1].status).toEqual('COMPLETED');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
expect(getPreferencesSpy).toHaveBeenCalled();
|
||||||
|
|
||||||
|
const localData = JSON.parse(localStorage.getItem(`task-filters-${appName}-${identityUserMock.username}`));
|
||||||
|
expect(localData.length).toEqual(2);
|
||||||
|
|
||||||
|
expect(localData[0].name).toEqual('ADF_CLOUD_TASK_FILTERS.MY_TASKS');
|
||||||
|
expect(localData[0].key).toEqual('my-tasks');
|
||||||
|
expect(localData[0].appName).toEqual(appName);
|
||||||
|
expect(localData[0].icon).toEqual('inbox');
|
||||||
|
expect(localData[0].status).toEqual('ASSIGNED');
|
||||||
|
expect(localData[0].assignee).toEqual(identityUserMock.username);
|
||||||
|
|
||||||
|
expect(localData[1].name).toEqual('ADF_CLOUD_TASK_FILTERS.COMPLETED_TASKS');
|
||||||
|
expect(localData[1].key).toEqual('completed-tasks');
|
||||||
|
expect(localData[1].appName).toEqual(appName);
|
||||||
|
expect(localData[1].icon).toEqual('done');
|
||||||
|
expect(localData[1].status).toEqual('COMPLETED');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user