[ADF-5422] remove deprecated "async()" from unit tests (#7109)

* remove angualar async from content services

* upgrade more tests

* upgrade core tests

* upgrade tests

* fix deprecated constant

* fix tests

* fix after rebase
This commit is contained in:
Denys Vuika
2021-06-15 16:16:15 +01:00
committed by GitHub
parent ba03c60adb
commit 3079aa48c3
121 changed files with 5316 additions and 4780 deletions

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { AppConfigService } from '../app-config/app-config.service';
import { AuthGuardBpm } from './auth-guard-bpm.service';
import { AuthenticationService } from './authentication.service';
@@ -51,7 +51,7 @@ describe('AuthGuardService BPM', () => {
appConfigService.config.oauth2 = {};
});
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async(async () => {
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async () => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
@@ -72,33 +72,33 @@ describe('AuthGuardService BPM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1);
}));
});
it('if the alfresco js api is logged in should canActivate be true', async(async () => {
it('if the alfresco js api is logged in should canActivate be true', async () => {
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
const route = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeTruthy();
}));
});
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(async () => {
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async () => {
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
appConfigService.config.auth.withCredentials = true;
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
const route = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeTruthy();
}));
});
it('if the alfresco js api is NOT logged in should canActivate be false', async(async () => {
it('if the alfresco js api is NOT logged in should canActivate be false', async () => {
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeFalsy();
}));
});
it('if the alfresco js api is NOT logged in should trigger a redirect event', async(async () => {
it('if the alfresco js api is NOT logged in should trigger a redirect event', async () => {
appConfigService.config.loginRoute = 'login';
spyOn(router, 'navigateByUrl');
@@ -107,31 +107,31 @@ describe('AuthGuardService BPM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url'));
}));
});
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(async () => {
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async () => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2.silentLogin = false;
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
const route = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalled();
}));
});
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(async () => {
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async () => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2.silentLogin = undefined;
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
const route = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalled();
}));
});
it('should set redirect url', async(() => {
it('should set redirect url', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
@@ -142,9 +142,9 @@ describe('AuthGuardService BPM', () => {
provider: 'BPM', url: 'some-url'
});
expect(authService.getRedirect()).toEqual('some-url');
}));
});
it('should set redirect navigation commands with query params', async(() => {
it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url;q=123' };
@@ -155,9 +155,9 @@ describe('AuthGuardService BPM', () => {
provider: 'BPM', url: 'some-url;q=123'
});
expect(authService.getRedirect()).toEqual('some-url;q=123');
}));
});
it('should set redirect navigation commands with query params', async(() => {
it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: '/' };
@@ -168,9 +168,9 @@ describe('AuthGuardService BPM', () => {
provider: 'BPM', url: '/'
});
expect(authService.getRedirect()).toEqual('/');
}));
});
it('should get redirect url from config if there is one configured', async(() => {
it('should get redirect url from config if there is one configured', () => {
appConfigService.config.loginRoute = 'fakeLoginRoute';
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
@@ -182,7 +182,7 @@ describe('AuthGuardService BPM', () => {
provider: 'BPM', url: 'some-url'
});
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
}));
});
it('should to close the material dialog if is redirect to the login', () => {
const materialDialog = TestBed.inject(MatDialog);

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { AppConfigService } from '../app-config/app-config.service';
import { AuthGuardEcm } from './auth-guard-ecm.service';
import { AuthenticationService } from './authentication.service';
@@ -51,31 +51,31 @@ describe('AuthGuardService ECM', () => {
appConfigService.config.oauth2 = {};
});
it('if the alfresco js api is logged in should canActivate be true', async(async() => {
it('if the alfresco js api is logged in should canActivate be true', async() => {
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
expect(await authGuard.canActivate(null, route)).toBeTruthy();
}));
});
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(async() => {
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async() => {
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
appConfigService.config.auth.withCredentials = true;
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
expect(await authGuard.canActivate(null, route)).toBeTruthy();
}));
});
it('if the alfresco js api is NOT logged in should canActivate be false', async(async() => {
it('if the alfresco js api is NOT logged in should canActivate be false', async() => {
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeFalsy();
}));
});
it('if the alfresco js api is NOT logged in should trigger a redirect event', async(async() => {
it('if the alfresco js api is NOT logged in should trigger a redirect event', async() => {
appConfigService.config.loginRoute = 'login';
spyOn(router, 'navigateByUrl');
@@ -84,9 +84,9 @@ describe('AuthGuardService ECM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url'));
}));
});
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(async() => {
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
@@ -95,9 +95,9 @@ describe('AuthGuardService ECM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalled();
}));
});
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async(async() => {
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async() => {
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
spyOn(authService, 'isPublicUrl').and.returnValue(false);
@@ -116,9 +116,9 @@ describe('AuthGuardService ECM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1);
}));
});
it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async(async() => {
it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
@@ -127,9 +127,9 @@ describe('AuthGuardService ECM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalled();
}));
});
it('should set redirect navigation commands', async(() => {
it('should set redirect navigation commands', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
@@ -140,9 +140,9 @@ describe('AuthGuardService ECM', () => {
provider: 'ECM', url: 'some-url'
});
expect(authService.getRedirect()).toEqual('some-url');
}));
});
it('should set redirect navigation commands with query params', async(() => {
it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url;q=123' };
@@ -153,9 +153,9 @@ describe('AuthGuardService ECM', () => {
provider: 'ECM', url: 'some-url;q=123'
});
expect(authService.getRedirect()).toEqual('some-url;q=123');
}));
});
it('should set redirect navigation commands with query params', async(() => {
it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: '/' };
@@ -166,9 +166,9 @@ describe('AuthGuardService ECM', () => {
provider: 'ECM', url: '/'
});
expect(authService.getRedirect()).toEqual('/');
}));
});
it('should get redirect url from config if there is one configured', async(() => {
it('should get redirect url from config if there is one configured', () => {
appConfigService.config.loginRoute = 'fakeLoginRoute';
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
@@ -180,7 +180,7 @@ describe('AuthGuardService ECM', () => {
provider: 'ECM', url: 'some-url'
});
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
}));
});
it('should to close the material dialog if is redirect to the login', () => {
const materialDialog = TestBed.inject(MatDialog);

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { CommentModel } from '../models/comment.model';
import { fakeProcessComment, fakeTasksComment, fakeUser1 } from '../mock/comment-process-service.mock';
import { CommentProcessService } from './comment-process.service';
@@ -65,37 +65,40 @@ describe('Comment ProcessService Service', () => {
.returnValue(Promise.resolve({data: [fakeProcessComment, fakeProcessComment]}));
});
it('should return the correct number of comments', async(() => {
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', async(() => {
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', async(() => {
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();
}
);
}));
});
});
@@ -117,25 +120,26 @@ describe('Comment ProcessService Service', () => {
}, processId);
});
it('should return the created comment', async(() => {
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', async(() => {
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();
}
);
}));
});
});
});

View File

@@ -16,7 +16,7 @@
*/
import { EventEmitter } from '@angular/core';
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { FileModel, FileUploadOptions, FileUploadStatus } from '../models/file.model';
import { AppConfigModule } from '../app-config/app-config.module';
import { UploadService } from './upload.service';
@@ -447,32 +447,32 @@ describe('UploadService', () => {
expect(result[0]).toBe(file2);
});
it('should call onUploadDeleted if file was deleted', async(() => {
it('should call onUploadDeleted if file was deleted', () => {
const file = <any> ({ status: FileUploadStatus.Deleted });
spyOn(service.fileUploadDeleted, 'next');
service.cancelUpload(file);
expect(service.fileUploadDeleted.next).toHaveBeenCalled();
}));
});
it('should call fileUploadError if file has error status', async(() => {
it('should call fileUploadError if file has error status', () => {
const file = <any> ({ status: FileUploadStatus.Error });
spyOn(service.fileUploadError, 'next');
service.cancelUpload(file);
expect(service.fileUploadError.next).toHaveBeenCalled();
}));
});
it('should call fileUploadCancelled if file is in pending', async(() => {
it('should call fileUploadCancelled if file is in pending', () => {
const file = <any> ({ status: FileUploadStatus.Pending });
spyOn(service.fileUploadCancelled, 'next');
service.cancelUpload(file);
expect(service.fileUploadCancelled.next).toHaveBeenCalled();
}));
});
it('Should not pass rendition if it is disabled', () => {
mockProductInfo.next({ status: { isThumbnailGenerationEnabled: false } } as EcmProductVersionModel);

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { TestBed, async } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
import { AppConfigService } from '../app-config/app-config.service';
import { StorageService } from './storage.service';
@@ -177,7 +177,7 @@ describe('UserPreferencesService', () => {
describe('with language config', () => {
it('should store default textOrientation based on language', async(() => {
it('should store default textOrientation based on language', () => {
appConfig.config.languages = [
{
key: 'fake-locale-config'
@@ -187,9 +187,9 @@ describe('UserPreferencesService', () => {
alfrescoApiService.initialize();
const textOrientation = preferences.getPropertyKey('textOrientation');
expect(storage.getItem(textOrientation)).toBe('ltr');
}));
});
it('should store textOrientation based on language config direction', async(() => {
it('should store textOrientation based on language config direction', () => {
appConfig.config.languages = [
{
key: 'fake-locale-config',
@@ -200,9 +200,9 @@ describe('UserPreferencesService', () => {
alfrescoApiService.initialize();
const textOrientation = preferences.getPropertyKey('textOrientation');
expect(storage.getItem(textOrientation)).toBe('rtl');
}));
});
it('should not store textOrientation based on language ', async(() => {
it('should not store textOrientation based on language ', () => {
appConfig.config.languages = [
{
key: 'fake-locale-browser'
@@ -212,7 +212,7 @@ describe('UserPreferencesService', () => {
const textOrientation = preferences.getPropertyKey('textOrientation');
expect(storage.getItem(textOrientation)).toBe(null);
}));
});
it('should default to browser locale for textOrientation when locale is not defined in configuration', (done) => {
appConfig.config.languages = [