mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-6196] await-thenable rule for ESLint, fix issues (#9027)
* fix issues for core lib * fix content services lib * fix and cleanup process services * [ci:force] process services cloud * [ci:force] align coverage with all libs * [ci:force] fix the insights
This commit is contained in:
@@ -61,7 +61,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||
router.data = { roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'] };
|
||||
|
||||
expect(await authGuard.canActivate(router)).toBeTruthy();
|
||||
expect(authGuard.canActivate(router)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('Should canActivate be true if case of empty roles to check', async () => {
|
||||
@@ -69,7 +69,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||
router.data = { roles: [] };
|
||||
|
||||
expect(await authGuard.canActivate(router)).toBeTruthy();
|
||||
expect(authGuard.canActivate(router)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('Should canActivate be false if the Role is not present int the JWT token', async () => {
|
||||
@@ -77,7 +77,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||
router.data = { roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'] };
|
||||
|
||||
expect(await authGuard.canActivate(router)).toBeFalsy();
|
||||
expect(authGuard.canActivate(router)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('Should not redirect if canActivate is', async () => {
|
||||
@@ -87,7 +87,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||
router.data = { roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'] };
|
||||
|
||||
expect(await authGuard.canActivate(router)).toBeTruthy();
|
||||
expect(authGuard.canActivate(router)).toBeTruthy();
|
||||
expect(routerService.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -95,7 +95,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
spyUserAccess(['MOCK_USER_ROLE', 'MOCK_ROOT_USER_ROLE'], {});
|
||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||
|
||||
expect(await authGuard.canActivate(router)).toBeFalsy();
|
||||
expect(authGuard.canActivate(router)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('Should redirect to the redirectURL if canActivate is false and redirectUrl is in data', async () => {
|
||||
@@ -105,7 +105,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||
router.data = { roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'], redirectUrl: 'no-role-url' };
|
||||
|
||||
expect(await authGuard.canActivate(router)).toBeFalsy();
|
||||
expect(authGuard.canActivate(router)).toBeFalsy();
|
||||
expect(routerService.navigate).toHaveBeenCalledWith(['/no-role-url']);
|
||||
});
|
||||
|
||||
@@ -116,7 +116,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||
router.data = { roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'] };
|
||||
|
||||
expect(await authGuard.canActivate(router)).toBeFalsy();
|
||||
expect(authGuard.canActivate(router)).toBeFalsy();
|
||||
expect(routerService.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -127,7 +127,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
route.params = { appName: 'mockApp' };
|
||||
route.data = { clientRoles: ['appName'], roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'] };
|
||||
|
||||
expect(await authGuard.canActivate(route)).toBeFalsy();
|
||||
expect(authGuard.canActivate(route)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('Should canActivate be false if hasRealm is false and hasClientRole is true', async () => {
|
||||
@@ -137,7 +137,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
route.params = { appName: 'mockApp' };
|
||||
route.data = { clientRoles: ['mockApp'], roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'] };
|
||||
|
||||
expect(await authGuard.canActivate(route)).toBeFalsy();
|
||||
expect(authGuard.canActivate(route)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('Should canActivate be true if both Real Role and Client Role are present int the JWT token', async () => {
|
||||
@@ -147,7 +147,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
route.params = { appName: 'mockApp' };
|
||||
route.data = { clientRoles: ['appName'], roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'] };
|
||||
|
||||
expect(await authGuard.canActivate(route)).toBeTruthy();
|
||||
expect(authGuard.canActivate(route)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('Should canActivate be false if the Client Role is not present int the JWT token with the correct role', async () => {
|
||||
@@ -157,7 +157,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
route.params = { appName: 'mockApp' };
|
||||
route.data = { clientRoles: ['appName'], roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'] };
|
||||
|
||||
expect(await authGuard.canActivate(route)).toBeFalsy();
|
||||
expect(authGuard.canActivate(route)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('Should canActivate be false hasRealm is true and hasClientRole is false', async () => {
|
||||
@@ -171,7 +171,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
route.params = { appName: 'mockApp' };
|
||||
route.data = { clientRoles: ['appName'], roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'] };
|
||||
|
||||
expect(await authGuard.canActivate(route)).toBeFalsy();
|
||||
expect(authGuard.canActivate(route)).toBeFalsy();
|
||||
expect(materialDialog.closeAll).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -182,7 +182,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||
router.data = { roles: ['MOCK_ANOTHER_ROLE'], excludedRoles: ['MOCK_USER_ROLE'] };
|
||||
|
||||
expect(await authGuard.canActivate(router)).toBe(false);
|
||||
expect(authGuard.canActivate(router)).toBe(false);
|
||||
});
|
||||
|
||||
it('Should canActivate be true when the user has none of the excluded roles', async () => {
|
||||
@@ -190,8 +190,7 @@ describe('Auth Guard SSO role service', () => {
|
||||
|
||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||
router.data = { roles: ['MOCK_USER_ROLE', 'MOCK_ADMIN_ROLE'], excludedRoles: ['MOCK_ROOT_USER_ROLE'] };
|
||||
const result = await authGuard.canActivate(router);
|
||||
expect(result).toBeTruthy();
|
||||
expect(authGuard.canActivate(router)).toBeTruthy();
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -22,6 +22,7 @@ import { WidgetComponent } from './widget.component';
|
||||
import { CoreTestingModule } from '../../../testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { FormRulesEvent } from '../../events/form-rules.event';
|
||||
|
||||
describe('WidgetComponent', () => {
|
||||
|
||||
@@ -69,40 +70,43 @@ describe('WidgetComponent', () => {
|
||||
expect(widget.hasField()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should send an event after view init', async () => {
|
||||
it('should send an event after view init', () => {
|
||||
const fakeForm = new FormModel();
|
||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' });
|
||||
widget.field = fakeField;
|
||||
|
||||
await widget.fieldChanged.subscribe((field) => {
|
||||
expect(field).not.toBe(null);
|
||||
expect(field.id).toBe('fakeField');
|
||||
expect(field.value).toBe('fakeValue');
|
||||
});
|
||||
let lastValue: FormFieldModel;
|
||||
|
||||
widget.fieldChanged.subscribe((field) => lastValue = field);
|
||||
widget.ngAfterViewInit();
|
||||
|
||||
expect(lastValue).not.toBe(null);
|
||||
expect(lastValue.id).toBe('fakeField');
|
||||
expect(lastValue.value).toBe('fakeValue');
|
||||
});
|
||||
|
||||
it('should send an event when a field is changed', async () => {
|
||||
it('should send an event when a field is changed', () => {
|
||||
const fakeForm = new FormModel();
|
||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' });
|
||||
await widget.fieldChanged.subscribe((field) => {
|
||||
expect(field).not.toBe(null);
|
||||
expect(field.id).toBe('fakeField');
|
||||
expect(field.value).toBe('fakeValue');
|
||||
});
|
||||
|
||||
let lastValue: FormFieldModel;
|
||||
widget.fieldChanged.subscribe((field) => lastValue = field);
|
||||
widget.onFieldChanged(fakeField);
|
||||
|
||||
expect(lastValue).not.toBe(null);
|
||||
expect(lastValue.id).toBe('fakeField');
|
||||
expect(lastValue.value).toBe('fakeValue');
|
||||
});
|
||||
|
||||
it('should send a rule event when a field is changed', async () => {
|
||||
it('should send a rule event when a field is changed', () => {
|
||||
const fakeForm = new FormModel();
|
||||
const fakeField = new FormFieldModel(fakeForm, { id: 'fakeField', value: 'fakeValue' });
|
||||
await widget.formService.formRulesEvent.subscribe((event) => {
|
||||
expect(event.type).toEqual('fieldValueChanged');
|
||||
});
|
||||
|
||||
let lastValue: FormRulesEvent;
|
||||
widget.formService.formRulesEvent.subscribe((event) => lastValue = event);
|
||||
|
||||
widget.onFieldChanged(fakeField);
|
||||
expect(lastValue.type).toEqual('fieldValueChanged');
|
||||
});
|
||||
|
||||
it('should eval isRequired state of the field', () => {
|
||||
|
@@ -53,7 +53,7 @@ describe('DownloadPromptDialogComponent', () => {
|
||||
const waitButton = getButton('#waitButton');
|
||||
waitButton.dispatchEvent(new Event('click'));
|
||||
|
||||
await fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(matDialogRef.close).toHaveBeenCalledWith(DownloadPromptActions.WAIT);
|
||||
@@ -63,7 +63,7 @@ describe('DownloadPromptDialogComponent', () => {
|
||||
const waitButton = getButton('#downloadButton');
|
||||
waitButton.dispatchEvent(new Event('click'));
|
||||
|
||||
await fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(matDialogRef.close).toHaveBeenCalledWith(DownloadPromptActions.DOWNLOAD);
|
||||
|
@@ -92,7 +92,7 @@ describe('ViewerComponent', () => {
|
||||
it('should not reload the content of all the viewer after type change', async () => {
|
||||
const fixtureDouble = TestBed.createComponent(DoubleViewerComponent);
|
||||
|
||||
await fixtureDouble.detectChanges();
|
||||
fixtureDouble.detectChanges();
|
||||
await fixtureDouble.whenStable();
|
||||
|
||||
fixtureDouble.componentInstance.urlFileViewer1 = 'fake-test-file.pdf';
|
||||
@@ -101,7 +101,7 @@ describe('ViewerComponent', () => {
|
||||
fixtureDouble.componentInstance.viewer1.ngOnChanges();
|
||||
fixtureDouble.componentInstance.viewer2.ngOnChanges();
|
||||
|
||||
await fixtureDouble.detectChanges();
|
||||
fixtureDouble.detectChanges();
|
||||
await fixtureDouble.whenStable();
|
||||
|
||||
expect(fixtureDouble.componentInstance.viewer1.viewerType).toBe('pdf');
|
||||
@@ -110,7 +110,7 @@ describe('ViewerComponent', () => {
|
||||
fixtureDouble.componentInstance.urlFileViewer1 = 'fake-test-file.pdf';
|
||||
fixtureDouble.componentInstance.urlFileViewer2 = 'fake-test-file-two.png';
|
||||
|
||||
await fixtureDouble.detectChanges();
|
||||
fixtureDouble.detectChanges();
|
||||
await fixtureDouble.whenStable();
|
||||
|
||||
fixtureDouble.componentInstance.viewer1.ngOnChanges();
|
||||
|
Reference in New Issue
Block a user