prepare tests for ng-12 upgrade (#7099)

* prepare tests for ng12 upgrade

* fix lint

* fix tests

* test fixes

* fix code and tests

* fix code and tests

* test fixes

* test fixes
This commit is contained in:
Denys Vuika
2021-06-11 07:36:32 +01:00
committed by GitHub
parent 558056b05c
commit eb71a79d1e
112 changed files with 982 additions and 1057 deletions

View File

@@ -58,7 +58,7 @@ export const aboutAPSMockDetails = {
minorVersion: '10'
};
export const mockModules = {
export const mockModules: any = {
edition: 'Enterprise',
version: {
major: '6',

View File

@@ -62,6 +62,7 @@ describe('CardViewTextItemComponent', () => {
editable: false
});
component.ngOnChanges({ property: new SimpleChange(null, null, true) });
fixture.detectChanges();
});
it('should render the label and value', async () => {
@@ -256,6 +257,7 @@ describe('CardViewTextItemComponent', () => {
editable: false
});
component.ngOnChanges({ property: new SimpleChange(null, null, true) });
fixture.detectChanges();
});
it('should render the default as value if the value is empty, clickable is false and displayEmpty is true', (done) => {
@@ -468,6 +470,7 @@ describe('CardViewTextItemComponent', () => {
editable: true
});
component.ngOnChanges({ property: new SimpleChange(null, null, true) });
fixture.detectChanges();
});
it('should call the isValid method with the edited value', fakeAsync((done) => {
@@ -563,7 +566,7 @@ describe('CardViewTextItemComponent', () => {
});
}));
it('should reset erros when exiting editable mode', fakeAsync((done) => {
it('should reset erros when exiting editable mode', fakeAsync(() => {
let errorMessage: string;
const expectedErrorMessages = [{ message: 'Something went wrong' } as CardViewItemValidator];
component.property.isValid = () => false;
@@ -584,7 +587,6 @@ describe('CardViewTextItemComponent', () => {
errorMessage = fixture.debugElement.nativeElement.querySelector('.adf-textitem-editable-error');
expect(errorMessage).toBe(null);
expect(component.errors).toEqual([]);
done();
});
});
}));
@@ -620,7 +622,7 @@ describe('CardViewTextItemComponent', () => {
inputField.nativeElement.click();
}));
it('should trigger an update event on the CardViewUpdateService [integration]', fakeAsync((done) => {
it('should trigger an update event on the CardViewUpdateService [integration]', (done) => {
component.property.isValid = () => true;
const cardViewUpdateService = TestBed.inject(CardViewUpdateService);
const expectedText = 'changed text';
@@ -639,7 +641,7 @@ describe('CardViewTextItemComponent', () => {
updateTextField(component.property.key, expectedText);
});
}));
});
it('should update the value using the updateItem$ subject', (async () => {
component.property.isValid = () => true;
@@ -664,7 +666,7 @@ describe('CardViewTextItemComponent', () => {
}));
it('should update multiline input the value on input updated', fakeAsync((done) => {
it('should update multiline input the value on input updated', (done) => {
component.property.isValid = () => true;
component.property.multiline = true;
const expectedText = 'changed text';
@@ -693,7 +695,7 @@ describe('CardViewTextItemComponent', () => {
expect(component.property.value).toBe(expectedText);
});
});
}));
});
});
describe('number', () => {
@@ -711,6 +713,7 @@ describe('CardViewTextItemComponent', () => {
component.editable = true;
component.property.validators.push(new CardViewItemIntValidator());
component.ngOnChanges({ property: new SimpleChange(null, null, true) });
fixture.detectChanges();
});
it('should show validation error when string passed', fakeAsync((done) => {
@@ -793,7 +796,7 @@ describe('CardViewTextItemComponent', () => {
});
}));
it('should update input the value on input updated', fakeAsync((done) => {
it('should update input the value on input updated', (done) => {
const expectedNumber = 2020;
spyOn(component, 'update').and.callThrough();
fixture.detectChanges();
@@ -817,7 +820,7 @@ describe('CardViewTextItemComponent', () => {
expect(component.property.value).toBe(expectedNumber.toString());
});
});
}));
});
});
describe('float', () => {
@@ -830,12 +833,13 @@ describe('CardViewTextItemComponent', () => {
label: 'Text label',
value: floatValue,
key: 'textkey',
default: 'FAKE-DEFAULT-KEY',
default: 1,
editable: true
});
component.editable = true;
component.property.validators.push(new CardViewItemFloatValidator());
component.ngOnChanges({ property: new SimpleChange(null, null, true) });
fixture.detectChanges();
});
it('should show validation error when string passed', fakeAsync((done) => {
@@ -854,7 +858,7 @@ describe('CardViewTextItemComponent', () => {
});
}));
it('should show validation error for empty string', fakeAsync((done) => {
it('should show validation error for empty string (float)', fakeAsync((done) => {
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -870,7 +874,7 @@ describe('CardViewTextItemComponent', () => {
});
}));
it('should update input the value on input updated', fakeAsync((done) => {
it('should update input the value on input updated', (done) => {
const expectedNumber = 88.44;
spyOn(component, 'update').and.callThrough();
fixture.detectChanges();
@@ -894,7 +898,7 @@ describe('CardViewTextItemComponent', () => {
expect(component.property.value).toBe(expectedNumber.toString());
});
});
}));
});
});
function updateTextField(key, value) {

View File

@@ -24,6 +24,7 @@ import { CommentContentService } from '../services/comment-content.service';
import { setupTestBed } from '../testing/setup-test-bed';
import { CoreTestingModule } from '../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { CommentModel } from '../models/comment.model';
describe('CommentsComponent', () => {
@@ -51,28 +52,28 @@ describe('CommentsComponent', () => {
commentProcessService = fixture.debugElement.injector.get(CommentProcessService);
commentContentService = fixture.debugElement.injector.get(CommentContentService);
addContentCommentSpy = spyOn(commentContentService, 'addNodeComment').and.returnValue(of({
addContentCommentSpy = spyOn(commentContentService, 'addNodeComment').and.returnValue(of(new CommentModel({
id: 123,
message: 'Test Comment',
createdBy: {id: '999'}
}));
})));
getContentCommentsSpy = spyOn(commentContentService, 'getNodeComments').and.returnValue(of([
{message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}},
{message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}},
{message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}
new CommentModel({message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}),
new CommentModel({message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}),
new CommentModel({message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}})
]));
getProcessCommentsSpy = spyOn(commentProcessService, 'getTaskComments').and.returnValue(of([
{message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}},
{message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}},
{message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}
new CommentModel({message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}),
new CommentModel({message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}),
new CommentModel({message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}})
]));
addProcessCommentSpy = spyOn(commentProcessService, 'addTaskComment').and.returnValue(of({
addProcessCommentSpy = spyOn(commentProcessService, 'addTaskComment').and.returnValue(of(new CommentModel({
id: 123,
message: 'Test Comment',
createdBy: {id: '999'}
}));
})));
});
afterEach(() => {

View File

@@ -41,7 +41,7 @@ describe('NodeDownloadDirective', () => {
let apiService: AlfrescoApiService;
let contentService;
let dialogSpy;
const mockOauth2Auth = {
const mockOauth2Auth: any = {
oauth2Auth: {
callCustomApi: () => Promise.resolve()
},
@@ -159,7 +159,7 @@ describe('NodeDownloadDirective', () => {
});
it('should create link element to download file node', () => {
const dummyLinkElement = {
const dummyLinkElement: any = {
download: null,
href: null,
click: () => null,

View File

@@ -72,7 +72,7 @@ describe('NodeFavoriteDirective', () => {
});
it('should reset favorites if selection is empty', fakeAsync(() => {
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve(null));
const selection = [
{ entry: { id: '1', name: 'name1' } }
@@ -97,7 +97,7 @@ describe('NodeFavoriteDirective', () => {
beforeEach(() => {
favoritesApiSpy = spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite')
.and.returnValue(Promise.resolve());
.and.returnValue(Promise.resolve(null));
});
it('should check each selected node if it is a favorite', fakeAsync(() => {
@@ -341,7 +341,7 @@ describe('NodeFavoriteDirective', () => {
}));
it('should process node as favorite', fakeAsync(() => {
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve(null));
const selection = [
{ entry: { id: '1', name: 'name1' } }

View File

@@ -110,7 +110,7 @@ describe('UploadDirective', () => {
it('should raise upload-files event on files drop', (done) => {
directive.enabled = true;
const event = jasmine.createSpyObj('event', ['preventDefault', 'stopPropagation']);
spyOn(directive, 'getDataTransfer').and.returnValue({});
spyOn(directive, 'getDataTransfer').and.returnValue({} as any);
spyOn(directive, 'getFilesDropped').and.returnValue(Promise.resolve([
<FileInfo> {},
<FileInfo> {}
@@ -127,7 +127,7 @@ describe('UploadDirective', () => {
<FileInfo> {}
];
const event = jasmine.createSpyObj('event', ['preventDefault', 'stopPropagation']);
spyOn(directive, 'getDataTransfer').and.returnValue({});
spyOn(directive, 'getDataTransfer').and.returnValue({} as any);
spyOn(directive, 'getFilesDropped').and.returnValue(Promise.resolve(files));
spyOn(nativeElement, 'dispatchEvent').and.callFake((e) => {

View File

@@ -22,6 +22,7 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
import { setupTestBed } from '../testing/setup-test-bed';
import { CoreTestingModule } from '../testing/core.testing.module';
import { VersionCompatibilityService } from '../services/version-compatibility.service';
import { VersionModel } from '../models/product-version.model';
@Component({
template: `
@@ -51,12 +52,12 @@ describe('VersionCompatibilityDirective', () => {
let fixture: ComponentFixture<TestComponent>;
let versionCompatibilityService: VersionCompatibilityService;
const acsResponceMock = {
const acsResponceMock = new VersionModel({
display: '7.0.1',
major: '7',
minor: '0',
patch: '1'
};
});
setupTestBed({
imports: [

View File

@@ -129,7 +129,7 @@ describe('RadioButtonsWidgetComponent', () => {
});
it('should update the field value when an option is selected', () => {
spyOn(widget, 'onFieldChanged').and.returnValue(of({}));
spyOn(widget, 'onFieldChanged').and.stub();
widget.onOptionClick('fake-opt');
expect(widget.field.value).toEqual('fake-opt');

View File

@@ -28,8 +28,9 @@ import { UploadWidgetComponent } from './upload.widget';
import { setupTestBed } from '../../../../testing/setup-test-bed';
import { CoreTestingModule } from '../../../../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { RelatedContentRepresentation } from '@alfresco/js-api';
const fakePngAnswer = {
const fakePngAnswer = new RelatedContentRepresentation({
'id': 1155,
'name': 'a_png_file.png',
'created': '2017-07-25T17:17:37.099Z',
@@ -41,7 +42,7 @@ const fakePngAnswer = {
'simpleType': 'image',
'previewStatus': 'queued',
'thumbnailStatus': 'queued'
};
});
const fakeJpgAnswer = {
'id': 1156,
@@ -211,7 +212,7 @@ describe('UploadWidgetComponent', () => {
return of(fakeJpgAnswer);
}
return of();
return of(null);
});
uploadWidgetComponent.field.params.multiple = true;
@@ -241,7 +242,7 @@ describe('UploadWidgetComponent', () => {
return of(fakeJpgAnswer);
}
return of();
return of(null);
});
uploadWidgetComponent.field.params.multiple = true;

View File

@@ -233,7 +233,7 @@ describe('Form service', () => {
activiti: {
processApi: processApiSpy
}
});
} as any);
processApiSpy.getProcessDefinitionStartForm.and.returnValue(Promise.resolve({ id: '1' }));
service.getStartFormDefinition('myprocess:1').subscribe(() => {

View File

@@ -228,13 +228,13 @@ describe('SidenavLayoutComponent', () => {
describe('Template transclusion', () => {
let fixture: ComponentFixture<any>,
mediaMatcher: MediaMatcher;
const mediaQueryList = {
let fixture: ComponentFixture<any>;
let mediaMatcher: MediaMatcher;
const mediaQueryList: any = {
matches: false,
addListener: () => {},
removeListener: () => {}
};
};
setupTestBed({
imports: [

View File

@@ -25,7 +25,7 @@ import { AuthenticationService } from '../../services/authentication.service';
import { LoginErrorEvent } from '../models/login-error.event';
import { LoginSuccessEvent } from '../models/login-success.event';
import { LoginComponent } from './login.component';
import { of, throwError, Observable } from 'rxjs';
import { of, throwError } from 'rxjs';
import { OauthConfigModel } from '../../models/oauth-config.model';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
@@ -177,12 +177,7 @@ describe('LoginComponent', () => {
it('should update user preferences upon login', async(() => {
spyOn(userPreferences, 'setStoragePrefix').and.callThrough();
spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => {
return new Observable((observer) => {
observer.next();
observer.complete();
});
});
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve());
component.success.subscribe(() => {
expect(userPreferences.setStoragePrefix).toHaveBeenCalledWith('fake-username');
@@ -202,10 +197,7 @@ describe('LoginComponent', () => {
});
it('should be changed to the "checking key" after a login attempt', () => {
spyOn(authService, 'login').and.returnValue({
subscribe: () => {
}
});
spyOn(authService, 'login').and.stub();
loginWithCredentials('fake-username', 'fake-password');
@@ -247,10 +239,7 @@ describe('LoginComponent', () => {
});
it('should be taken into consideration during login attempt', () => {
spyOn(authService, 'login').and.returnValue({
subscribe: () => {
}
});
spyOn(authService, 'login').and.stub();
component.rememberMe = false;
loginWithCredentials('fake-username', 'fake-password');
@@ -409,12 +398,7 @@ describe('LoginComponent', () => {
});
it('should return error with a wrong username', (done) => {
spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => {
return new Observable((observer) => {
observer.next();
observer.error();
});
});
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject());
component.error.subscribe(() => {
fixture.detectChanges();
@@ -429,12 +413,7 @@ describe('LoginComponent', () => {
});
it('should return error with a wrong password', (done) => {
spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => {
return new Observable((observer) => {
observer.next();
observer.error();
});
});
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject());
component.error.subscribe(() => {
fixture.detectChanges();
@@ -450,12 +429,7 @@ describe('LoginComponent', () => {
});
it('should return error with a wrong username and password', (done) => {
spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => {
return new Observable((observer) => {
observer.next();
observer.error();
});
});
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.reject());
component.error.subscribe(() => {
fixture.detectChanges();
@@ -623,12 +597,7 @@ describe('LoginComponent', () => {
});
it('should emit only the username and not the password as part of the executeSubmit', async(() => {
spyOn(alfrescoApiService.getInstance(), 'login').and.callFake(() => {
return new Observable((observer) => {
observer.next();
observer.complete();
});
});
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve());
component.executeSubmit.subscribe((res) => {
fixture.detectChanges();
@@ -668,7 +637,7 @@ describe('LoginComponent', () => {
spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2 = <OauthConfigModel> { implicitFlow: true, silentLogin: true };
spyOn(component, 'redirectToImplicitLogin').and.returnValue(Promise.resolve({}));
spyOn(component, 'redirectToImplicitLogin').and.stub();
component.ngOnInit();
fixture.detectChanges();

View File

@@ -15,6 +15,8 @@
* limitations under the License.
*/
import { BpmUserModel } from '../models';
export let fakeBpmUserNoImage = {
apps: [],
capabilities: 'fake-capability',
@@ -37,7 +39,7 @@ export let fakeBpmUserNoImage = {
type: 'fake-type'
};
export let fakeBpmUser = {
export let fakeBpmUser = new BpmUserModel({
apps: [],
capabilities: null,
company: 'fake-company',
@@ -57,7 +59,7 @@ export let fakeBpmUser = {
tenantName: 'fake-tenant-name',
tenantPictureId: 'fake-tenant-picture-id',
type: 'fake-type'
};
});
export let fakeBpmEditedUser = {
apps: [],

View File

@@ -16,7 +16,8 @@
*/
import { EcmCompanyModel } from '../models/ecm-company.model';
import { PersonEntry, Person } from '@alfresco/js-api';
import { PersonEntry, Person, PersonPaging } from '@alfresco/js-api';
import { EcmUserModel } from '../models';
export const fakeEcmCompany: EcmCompanyModel = {
organization: 'company-fake-name',
@@ -29,7 +30,7 @@ export const fakeEcmCompany: EcmCompanyModel = {
email: 'fakeCompany@fake.com'
};
export const fakeEcmUser = {
export const fakeEcmUser = new EcmUserModel({
id: 'fake-id',
firstName: 'fake-ecm-first-name',
lastName: 'fake-ecm-last-name',
@@ -48,7 +49,7 @@ export const fakeEcmUser = {
userStatus: 'active',
enabled: true,
emailNotificationsEnabled: true
};
});
export const fakeEcmUser2 = {
id: 'another-fake-id',
@@ -103,7 +104,7 @@ export const fakeEcmEditedUser = {
emailNotificationsEnabled: true
};
export const fakeEcmUserList = {
export const fakeEcmUserList = new PersonPaging({
list: {
pagination: {
count: 2,
@@ -121,7 +122,7 @@ export const fakeEcmUserList = {
}
]
}
};
});
export const createNewPersonMock = {
id: 'fake-id',

View File

@@ -50,7 +50,7 @@ export const roleMappingMock = [
{ id: 'role-id-1', name: 'role-name-1' }, { id: 'role-id-2', name: 'role-name-2' }
];
export const roleMappingApi = {
export const roleMappingApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve(roleMappingMock);
@@ -58,7 +58,7 @@ export const roleMappingApi = {
}
};
export const noRoleMappingApi = {
export const noRoleMappingApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve([]);
@@ -66,7 +66,7 @@ export const noRoleMappingApi = {
}
};
export const groupsMockApi = {
export const groupsMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve(mockIdentityGroups);
@@ -74,7 +74,7 @@ export const groupsMockApi = {
}
};
export const createGroupMappingApi = {
export const createGroupMappingApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
@@ -82,7 +82,7 @@ export const createGroupMappingApi = {
}
};
export const updateGroupMappingApi = {
export const updateGroupMappingApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
@@ -90,7 +90,7 @@ export const updateGroupMappingApi = {
}
};
export const deleteGroupMappingApi = {
export const deleteGroupMappingApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
@@ -98,7 +98,7 @@ export const deleteGroupMappingApi = {
}
};
export const applicationDetailsMockApi = {
export const applicationDetailsMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve([mockApplicationDetails]);
@@ -112,4 +112,7 @@ export const mockIdentityRoles = [
new IdentityRoleModel({id: 'mock-role-id', name: 'MOCK-ROLE-1'})
];
export const clientRoles = [ 'MOCK-ADMIN-ROLE', 'MOCK-USER-ROLE'];
export const clientRoles: IdentityRoleModel[] = [
new IdentityRoleModel({ name: 'MOCK-ADMIN-ROLE' }),
new IdentityRoleModel({ name: 'MOCK-USER-ROLE' })
];

View File

@@ -70,7 +70,7 @@ export const mockGroups = [
<IdentityGroupModel> { id: 'mock-group-id-2', name: 'Mock Group 2', path: '', subGroups: [] }
];
export const queryUsersMockApi = {
export const queryUsersMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve(mockIdentityUsers);
@@ -78,7 +78,7 @@ export const queryUsersMockApi = {
}
};
export const createUserMockApi = {
export const createUserMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
@@ -86,7 +86,7 @@ export const createUserMockApi = {
}
};
export const updateUserMockApi = {
export const updateUserMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
@@ -94,7 +94,7 @@ export const updateUserMockApi = {
}
};
export const deleteUserMockApi = {
export const deleteUserMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
@@ -102,7 +102,7 @@ export const deleteUserMockApi = {
}
};
export const getInvolvedGroupsMockApi = {
export const getInvolvedGroupsMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve(mockGroups);
@@ -110,7 +110,7 @@ export const getInvolvedGroupsMockApi = {
}
};
export const joinGroupMockApi = {
export const joinGroupMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
@@ -118,7 +118,7 @@ export const joinGroupMockApi = {
}
};
export const leaveGroupMockApi = {
export const leaveGroupMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
@@ -126,7 +126,7 @@ export const leaveGroupMockApi = {
}
};
export const getAvailableRolesMockApi = {
export const getAvailableRolesMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve(mockAvailableRoles);
@@ -134,7 +134,7 @@ export const getAvailableRolesMockApi = {
}
};
export const getAssignedRolesMockApi = {
export const getAssignedRolesMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve(mockAssignedRoles);
@@ -142,7 +142,7 @@ export const getAssignedRolesMockApi = {
}
};
export const getEffectiveRolesMockApi = {
export const getEffectiveRolesMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve(mockEffectiveRoles);
@@ -150,7 +150,7 @@ export const getEffectiveRolesMockApi = {
}
};
export const assignRolesMockApi = {
export const assignRolesMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();
@@ -158,7 +158,7 @@ export const assignRolesMockApi = {
}
};
export const removeRolesMockApi = {
export const removeRolesMockApi: any = {
oauth2Auth: {
callCustomApi: () => {
return Promise.resolve();

View File

@@ -54,7 +54,7 @@ export let mockError = {
}
};
export let searchMockApi = {
export let searchMockApi: any = {
core: {
queriesApi: {
findNodes: () => Promise.resolve(fakeSearch)

View File

@@ -22,11 +22,11 @@ import { AlfrescoApiService } from './alfresco-api.service';
import { AuthenticationService } from './authentication.service';
import { setupTestBed } from '../testing/setup-test-bed';
import { CoreTestingModule } from '../testing/core.testing.module';
import { SystemPropertiesRepresentation } from '@alfresco/js-api';
import { DiscoveryEntry, SystemPropertiesRepresentation } from '@alfresco/js-api';
import { TranslateModule } from '@ngx-translate/core';
import { of, throwError } from 'rxjs';
import { of } from 'rxjs';
const fakeEcmDiscoveryResponse: any = {
const fakeEcmDiscoveryResponse = new DiscoveryEntry({
entry: {
repository: {
edition: 'FAKE',
@@ -79,7 +79,7 @@ const fakeEcmDiscoveryResponse: any = {
]
}
}
};
});
const fakeBPMDiscoveryResponse: any = {
revisionVersion: '2',
@@ -89,7 +89,7 @@ const fakeBPMDiscoveryResponse: any = {
minorVersion: '6'
};
const fakeBPMDiscoverySystemPropertyResponse: any = {
const fakeBPMDiscoverySystemPropertyResponse = new SystemPropertiesRepresentation({
allowInvolveByEmail: true,
disableJavaScriptEventsInFormEditor: false,
logoutDisabled: false,
@@ -99,7 +99,7 @@ const fakeBPMDiscoverySystemPropertyResponse: any = {
clientId: 'fakeClient',
useBrowserLogout: true
}
};
});
describe('Discovery Api Service', () => {
let service: DiscoveryApiService;
@@ -119,7 +119,7 @@ describe('Discovery Api Service', () => {
describe('For ECM', () => {
it('Should retrieve the info about the product for ECM', done => {
spyOn(apiService.getInstance().discovery.discoveryApi, 'getRepositoryInformation')
.and.returnValue(of(fakeEcmDiscoveryResponse));
.and.returnValue(Promise.resolve(fakeEcmDiscoveryResponse));
service.getEcmProductInfo()
.subscribe((data: EcmProductVersionModel) => {
@@ -137,7 +137,7 @@ describe('Discovery Api Service', () => {
it('getEcmProductInfo catch errors call', done => {
spyOn(apiService.getInstance().discovery.discoveryApi, 'getRepositoryInformation')
.and.returnValue(throwError({ status: 403 }));
.and.returnValue(Promise.reject({ status: 403 }));
service.getEcmProductInfo().subscribe(
() => {},
@@ -151,7 +151,7 @@ describe('Discovery Api Service', () => {
describe('For BPM', () => {
it('Should retrieve the info about the product for BPM', done => {
spyOn(apiService.getInstance().activiti.aboutApi, 'getAppVersion')
.and.returnValue(of(fakeBPMDiscoveryResponse));
.and.returnValue(Promise.resolve(fakeBPMDiscoveryResponse));
service.getBpmProductInfo().subscribe((data: BpmProductVersionModel) => {
expect(data).not.toBeNull();
@@ -164,7 +164,7 @@ describe('Discovery Api Service', () => {
it('getBpmProductInfo catch errors call', done => {
spyOn(apiService.getInstance().activiti.aboutApi, 'getAppVersion')
.and.returnValue(throwError({ status: 403 }));
.and.returnValue(Promise.reject({ status: 403 }));
service.getBpmProductInfo().subscribe(
() => {},
@@ -176,7 +176,7 @@ describe('Discovery Api Service', () => {
it('Should retrieve the system properties for BPM', done => {
spyOn(apiService.getInstance().activiti.systemPropertiesApi, 'getProperties')
.and.returnValue(of(fakeBPMDiscoverySystemPropertyResponse));
.and.returnValue(Promise.resolve(fakeBPMDiscoverySystemPropertyResponse));
service.getBPMSystemProperties().subscribe((data: SystemPropertiesRepresentation) => {
expect(data).not.toBeNull();
@@ -196,7 +196,7 @@ describe('Discovery Api Service', () => {
apiService.getInstance().activiti.systemPropertiesApi,
'getProperties'
).and.returnValue(
throwError({
Promise.reject({
error: {
response: {
statusCode: 404,

View File

@@ -45,7 +45,7 @@ describe('LoginDialogService', () => {
componentInstance: {
error: new Subject<any>()
}
});
} as any);
});
it('should be able to open the dialog when node has permission', () => {

View File

@@ -38,7 +38,7 @@ describe('NodesApiService', () => {
}
}
};
const mockSpy = {
const mockSpy: any = {
core: {
nodesApi: {
getNode: jasmine.createSpy('getNode'),

View File

@@ -24,7 +24,7 @@ import { setupTestBed } from '../testing/setup-test-bed';
import { TranslateModule } from '@ngx-translate/core';
import { TestBed } from '@angular/core/testing';
import { LogService } from './log.service';
import { of } from 'rxjs';
import { PersonEntry } from '@alfresco/js-api';
describe('PeopleContentService', () => {
@@ -47,7 +47,7 @@ describe('PeopleContentService', () => {
});
it('should be able to fetch person details based on id', (done) => {
spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser }));
spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve(new PersonEntry({ entry: fakeEcmUser })));
service.getPerson('fake-id').subscribe((person) => {
expect(person.entry.id).toEqual('fake-id');
expect(person.entry.email).toEqual('fakeEcm@ecmUser.com');
@@ -56,7 +56,7 @@ describe('PeopleContentService', () => {
});
it('calls getPerson api method by an id', (done) => {
const getPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve({}));
const getPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve(null));
service.getPerson('fake-id').subscribe(() => {
expect(getPersonSpy).toHaveBeenCalledWith('fake-id');
done();
@@ -64,7 +64,7 @@ describe('PeopleContentService', () => {
});
it('calls getPerson api method with "-me-"', (done) => {
const getPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve({}));
const getPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve(null));
service.getPerson('-me-').subscribe(() => {
expect(getPersonSpy).toHaveBeenCalledWith('-me-');
done();
@@ -95,7 +95,7 @@ describe('PeopleContentService', () => {
});
it('should be able to create new person', (done) => {
spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser }));
spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve(new PersonEntry({ entry: fakeEcmUser })));
service.createPerson(createNewPersonMock).subscribe((person) => {
expect(person.id).toEqual('fake-id');
expect(person.email).toEqual('fakeEcm@ecmUser.com');
@@ -104,7 +104,7 @@ describe('PeopleContentService', () => {
});
it('should be able to call createPerson api with new person details', (done) => {
const createPersonSpy = spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve({ entry: fakeEcmUser }));
const createPersonSpy = spyOn(service.peopleApi, 'createPerson').and.returnValue(Promise.resolve(new PersonEntry({ entry: fakeEcmUser })));
service.createPerson(createNewPersonMock).subscribe((person) => {
expect(person.id).toEqual('fake-id');
expect(person.email).toEqual('fakeEcm@ecmUser.com');
@@ -127,7 +127,7 @@ describe('PeopleContentService', () => {
});
it('Should make the api call to check if the user is a content admin only once', async () => {
const getCurrentPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(of(getFakeUserWithContentAdminCapability()));
const getCurrentPersonSpy = spyOn(service.peopleApi, 'getPerson').and.returnValue(Promise.resolve(getFakeUserWithContentAdminCapability()));
expect(await service.isContentAdmin()).toBe(true);
expect(getCurrentPersonSpy.calls.count()).toEqual(1);

View File

@@ -105,7 +105,7 @@ describe('User info component', () => {
contentService = TestBed.inject(ContentService);
identityUserService = TestBed.inject(IdentityUserService);
spyOn(window, 'requestAnimationFrame').and.returnValue(true);
spyOn(window, 'requestAnimationFrame').and.returnValue(1);
spyOn(bpmUserService, 'getCurrentUserProfileImage').and.returnValue('app/rest/admin/profile-picture');
spyOn(contentService, 'getContentUrl').and.returnValue('alfresco-logo.svg');
}));
@@ -175,37 +175,36 @@ describe('User info component', () => {
});
it('should show the username when showName attribute is true', async () => {
await fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.showName).toBeTruthy();
expect(element.querySelector('#adf-userinfo-ecm-name-display')).not.toBeNull();
});
});
it('should hide the username when showName attribute is false', async () => {
component.showName = false;
it('should hide the username when showName attribute is false', async () => {
component.showName = false;
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('#adf-userinfo-ecm-name-display')).toBeNull();
});
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('#adf-userinfo-ecm-name-display')).toBeNull();
});
it('should have the defined class to show the name on the right side', async () => {
fixture.detectChanges();
it('should have the defined class to show the name on the right side', async () => {
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('#userinfo_container').classList).toContain('adf-userinfo-name-right');
});
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('#userinfo_container').classList).toContain('adf-userinfo-name-right');
});
it('should not have the defined class to show the name on the left side', async () => {
component.namePosition = 'left';
fixture.detectChanges();
it('should not have the defined class to show the name on the left side', async () => {
component.namePosition = 'left';
fixture.detectChanges();
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('#userinfo_container').classList).not.toContain('adf-userinfo-name-right');
});
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('#userinfo_container').classList).not.toContain('adf-userinfo-name-right');
});
describe('and has image', () => {

View File

@@ -22,7 +22,7 @@ import { setupTestBed } from '../../testing/setup-test-bed';
import { CoreTestingModule } from '../../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { AlfrescoApiService } from '../../services';
import { NodeEntry } from '@alfresco/js-api';
import { NodeEntry, RenditionPaging } from '@alfresco/js-api';
describe('Test Media player component ', () => {
@@ -52,13 +52,13 @@ describe('Test Media player component ', () => {
it('should generate tracks for media file when webvtt rendition exists', fakeAsync(() => {
const fakeRenditionUrl = 'http://fake.rendition.url';
spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValues(
spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValue(
Promise.resolve(new NodeEntry({ entry: { name: 'file1', content: {} } }))
);
spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValues(
{ list: { entries: [{ entry: { id: 'webvtt', status: 'CREATED' } }] } }
spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValue(
Promise.resolve(new RenditionPaging({ list: { entries: [{ entry: { id: 'webvtt', status: 'CREATED' } }] } }))
);
spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValues('http://iam-fake.url');
spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValue('http://iam-fake.url');
spyOn(alfrescoApiService.contentApi, 'getRenditionUrl').and.returnValue(fakeRenditionUrl);
component.ngOnChanges(change);
@@ -68,15 +68,15 @@ describe('Test Media player component ', () => {
}));
it('should not generate tracks for media file when webvtt rendition is not created', fakeAsync(() => {
spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValues(
spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValue(
Promise.resolve(new NodeEntry({ entry: { name: 'file1', content: {} } }))
);
spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValues(
{ list: { entries: [{ entry: { id: 'webvtt', status: 'NOT_CREATED' } }] } }
spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValue(
Promise.resolve(new RenditionPaging({ list: { entries: [{ entry: { id: 'webvtt', status: 'NOT_CREATED' } }] } }))
);
spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValues('http://iam-fake.url');
spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValue('http://iam-fake.url');
component.ngOnChanges(change);
tick();
@@ -85,15 +85,15 @@ describe('Test Media player component ', () => {
}));
it('should not generate tracks for media file when webvtt rendition does not exist', fakeAsync(() => {
spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValues(
spyOn(alfrescoApiService.nodesApi, 'getNode').and.returnValue(
Promise.resolve(new NodeEntry({ entry: { name: 'file1', content: {} } }))
);
spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValues(
{ list: { entries: [] } }
spyOn(alfrescoApiService.renditionsApi, 'getRenditions').and.returnValue(
Promise.resolve(new RenditionPaging({ list: { entries: [] } }))
);
spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValues('http://iam-fake.url');
spyOn(alfrescoApiService.contentApi, 'getContentUrl').and.returnValue('http://iam-fake.url');
component.ngOnChanges(change);
tick();

View File

@@ -337,13 +337,13 @@ describe('Test PdfViewer component', () => {
if (context.data.reason === pdfjsLib.PasswordResponses.NEED_PASSWORD) {
return {
afterClosed: () => of('wrong_password')
};
} as any;
}
if (context.data.reason === pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) {
return {
afterClosed: () => of('password')
};
} as any;
}
return undefined;
@@ -404,7 +404,7 @@ describe('Test PdfViewer component', () => {
done();
return of('');
}
};
} as any;
});
spyOn(componentUrlTestPasswordComponent.pdfViewerComponent.close, 'emit');

View File

@@ -293,7 +293,7 @@ describe('ViewerComponent', () => {
const displayName = 'the-name';
const nodeDetails = { name: displayName, id: '12' };
const contentUrl = '/content/url/path';
const alfrescoApiInstanceMock = {
const alfrescoApiInstanceMock: any = {
nodes: {
getNodeInfo: () => Promise.resolve(nodeDetails),
getNode: () => Promise.resolve({ id: 'fake-node', entry: { content: {} } })
@@ -687,7 +687,7 @@ describe('ViewerComponent', () => {
const node = new NodeEntry({ entry: { name: displayName, id: '12', content: { mimeType: 'txt' } } });
const nodeDetails = { name: displayName, id: '12', content: { mimeType: 'txt' } };
const contentUrl = '/content/url/path';
const alfrescoApiInstanceMock = {
const alfrescoApiInstanceMock: any = {
nodes: {
getNodeInfo: () => Promise.resolve(nodeDetails),
getNode: () => Promise.resolve(node)
@@ -1066,7 +1066,7 @@ describe('ViewerComponent', () => {
const displayName = 'the-name';
const nodeDetails = new NodeEntry({ entry: { name: displayName, id: '12', content: { mimeType: 'txt' } } });
const contentUrl = '/content/url/path';
const alfrescoApiInstanceMock = {
const alfrescoApiInstanceMock: any = {
nodes: {
getNode: () => Promise.resolve(nodeDetails)
},