mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
fix unit test
This commit is contained in:
@@ -157,37 +157,18 @@ describe('CardViewTextItemComponent', () => {
|
|||||||
expect(value.nativeElement.innerText.trim()).toBe('FAKE-DEFAULT-KEY');
|
expect(value.nativeElement.innerText.trim()).toBe('FAKE-DEFAULT-KEY');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render the edit icon in case of clickable true and editable true', () => {
|
it('should not render the edit icon in case of clickable true but edit false', () => {
|
||||||
component.property = new CardViewTextItemModel({
|
component.property = new CardViewTextItemModel({
|
||||||
label: 'Text label',
|
label: 'Text label',
|
||||||
value: '',
|
value: '',
|
||||||
key: 'textkey',
|
key: 'textkey',
|
||||||
default: 'FAKE-DEFAULT-KEY',
|
default: 'FAKE-DEFAULT-KEY',
|
||||||
clickable: true,
|
clickable: true
|
||||||
editable: true,
|
|
||||||
icon: 'FAKE-ICON'
|
|
||||||
});
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
const value = fixture.debugElement.query(By.css(`[data-automation-id="card-textitem-edit-icon-${component.property.icon}"]`));
|
|
||||||
expect(value).not.toBeNull();
|
|
||||||
expect(value.nativeElement.innerText.trim()).toBe('FAKE-ICON');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not render the edit icon in case of clickable true and icon defined', () => {
|
|
||||||
component.property = new CardViewTextItemModel({
|
|
||||||
label: 'Text label',
|
|
||||||
value: '',
|
|
||||||
key: 'textkey',
|
|
||||||
default: 'FAKE-DEFAULT-KEY',
|
|
||||||
clickable: true,
|
|
||||||
icon: 'FAKE-ICON'
|
|
||||||
});
|
});
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const value = fixture.debugElement.query(By.css(`[data-automation-id="card-textitem-edit-icon-${component.property.icon}"]`));
|
const value = fixture.debugElement.query(By.css(`[data-automation-id="card-textitem-edit-icon-${component.property.icon}"]`));
|
||||||
expect(value).toBeNull();
|
expect(value).toBeNull();
|
||||||
expect(value.nativeElement.innerText.trim()).toBe('FAKE-ICON');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not render the edit icon in case of clickable true and icon undefined', () => {
|
it('should not render the edit icon in case of clickable true and icon undefined', () => {
|
||||||
|
@@ -68,7 +68,7 @@ describe('Auth Guard SSO role service', () => {
|
|||||||
spyOn(routerService, 'navigate').and.stub();
|
spyOn(routerService, 'navigate').and.stub();
|
||||||
|
|
||||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||||
router.data = { 'roles': ['role1', 'role2']};
|
router.data = { 'roles': ['role1', 'role2'] };
|
||||||
|
|
||||||
expect(authGuard.canActivate(router, null)).toBeTruthy();
|
expect(authGuard.canActivate(router, null)).toBeTruthy();
|
||||||
expect(routerService.navigate).not.toHaveBeenCalled();
|
expect(routerService.navigate).not.toHaveBeenCalled();
|
||||||
@@ -85,7 +85,7 @@ describe('Auth Guard SSO role service', () => {
|
|||||||
|
|
||||||
it('Should canActivate return false if the realm_access is not present', async(() => {
|
it('Should canActivate return false if the realm_access is not present', async(() => {
|
||||||
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
||||||
spyOn(jwtHelperService, 'decodeToken').and.returnValue({ });
|
spyOn(jwtHelperService, 'decodeToken').and.returnValue({});
|
||||||
|
|
||||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||||
|
|
||||||
@@ -94,11 +94,11 @@ describe('Auth Guard SSO role service', () => {
|
|||||||
|
|
||||||
it('Should redirect to the redirectURL if canActivate is false and redirectUrl is in data', async(() => {
|
it('Should redirect to the redirectURL if canActivate is false and redirectUrl is in data', async(() => {
|
||||||
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
||||||
spyOn(jwtHelperService, 'decodeToken').and.returnValue({ });
|
spyOn(jwtHelperService, 'decodeToken').and.returnValue({});
|
||||||
spyOn(routerService, 'navigate').and.stub();
|
spyOn(routerService, 'navigate').and.stub();
|
||||||
|
|
||||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||||
router.data = { 'roles': ['role1', 'role2'], 'redirectUrl': 'no-role-url'};
|
router.data = { 'roles': ['role1', 'role2'], 'redirectUrl': 'no-role-url' };
|
||||||
|
|
||||||
expect(authGuard.canActivate(router, null)).toBeFalsy();
|
expect(authGuard.canActivate(router, null)).toBeFalsy();
|
||||||
expect(routerService.navigate).toHaveBeenCalledWith(['/no-role-url']);
|
expect(routerService.navigate).toHaveBeenCalledWith(['/no-role-url']);
|
||||||
@@ -106,32 +106,34 @@ describe('Auth Guard SSO role service', () => {
|
|||||||
|
|
||||||
it('Should not redirect if canActivate is false and redirectUrl is not in data', async(() => {
|
it('Should not redirect if canActivate is false and redirectUrl is not in data', async(() => {
|
||||||
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
||||||
spyOn(jwtHelperService, 'decodeToken').and.returnValue({ });
|
spyOn(jwtHelperService, 'decodeToken').and.returnValue({});
|
||||||
spyOn(routerService, 'navigate').and.stub();
|
spyOn(routerService, 'navigate').and.stub();
|
||||||
|
|
||||||
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
const router: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||||
router.data = { 'roles': ['role1', 'role2']};
|
router.data = { 'roles': ['role1', 'role2'] };
|
||||||
|
|
||||||
expect(authGuard.canActivate(router, null)).toBeFalsy();
|
expect(authGuard.canActivate(router, null)).toBeFalsy();
|
||||||
expect(routerService.navigate).not.toHaveBeenCalled();
|
expect(routerService.navigate).not.toHaveBeenCalled();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('Should canActivate be false hasRealm is true and hasClientRol is false', () => {
|
it('Should canActivate be false hasRealm is true and hasClientRole is false', () => {
|
||||||
const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||||
spyOn(this, 'hasRealmRoles').and.returnValue(true);
|
spyOn(authGuard, 'hasRealmRoles').and.returnValue(true);
|
||||||
spyOn(this, 'hasRealmRolesForClientRole').and.returnValue(false);
|
spyOn(authGuard, 'hasRealmRolesForClientRole').and.returnValue(false);
|
||||||
|
|
||||||
|
route.params = { appName: 'fakeapp' };
|
||||||
route.data = { 'clientRoles': ['appName'], 'roles': ['role1', 'role2'] };
|
route.data = { 'clientRoles': ['appName'], 'roles': ['role1', 'role2'] };
|
||||||
|
|
||||||
expect(authGuard.canActivate(route, null)).toBeFalsy();
|
expect(authGuard.canActivate(route, null)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should canActivate be false hasRealm is false and hasClientRol is true', () => {
|
it('Should canActivate be false if hasRealm is false and hasClientRole is true', () => {
|
||||||
const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
const route: ActivatedRouteSnapshot = new ActivatedRouteSnapshot();
|
||||||
spyOn(this, 'hasRealmRoles').and.returnValue(false);
|
spyOn(authGuard, 'hasRealmRoles').and.returnValue(false);
|
||||||
spyOn(this, 'hasRealmRolesForClientRole').and.returnValue(true);
|
spyOn(authGuard, 'hasRealmRolesForClientRole').and.returnValue(true);
|
||||||
|
|
||||||
route.data = { 'clientRoles': ['appName'], 'roles': ['role1', 'role2'] };
|
route.params = { appName: 'fakeapp' };
|
||||||
|
route.data = { 'clientRoles': ['fakeapp'], 'roles': ['role1', 'role2'] };
|
||||||
|
|
||||||
expect(authGuard.canActivate(route, null)).toBeFalsy();
|
expect(authGuard.canActivate(route, null)).toBeFalsy();
|
||||||
});
|
});
|
||||||
@@ -142,10 +144,10 @@ describe('Auth Guard SSO role service', () => {
|
|||||||
|
|
||||||
spyOn(jwtHelperService, 'decodeToken').and.returnValue({
|
spyOn(jwtHelperService, 'decodeToken').and.returnValue({
|
||||||
'realm_access': { roles: ['role1'] },
|
'realm_access': { roles: ['role1'] },
|
||||||
'resource_access': { fakeapp: { roles: ['role2'] }}
|
'resource_access': { fakeapp: { roles: ['role2'] } }
|
||||||
});
|
});
|
||||||
|
|
||||||
route.params = {appName: 'fakeapp'};
|
route.params = { appName: 'fakeapp' };
|
||||||
route.data = { 'clientRoles': ['appName'], 'roles': ['role1', 'role2'] };
|
route.data = { 'clientRoles': ['appName'], 'roles': ['role1', 'role2'] };
|
||||||
|
|
||||||
expect(authGuard.canActivate(route, null)).toBeTruthy();
|
expect(authGuard.canActivate(route, null)).toBeTruthy();
|
||||||
@@ -157,10 +159,10 @@ describe('Auth Guard SSO role service', () => {
|
|||||||
|
|
||||||
spyOn(jwtHelperService, 'decodeToken').and.returnValue({
|
spyOn(jwtHelperService, 'decodeToken').and.returnValue({
|
||||||
'realm_access': { roles: ['role1'] },
|
'realm_access': { roles: ['role1'] },
|
||||||
'resource_access': { fakeapp: { roles: ['role3'] }}
|
'resource_access': { fakeapp: { roles: ['role3'] } }
|
||||||
});
|
});
|
||||||
|
|
||||||
route.params = {appName: 'fakeapp'};
|
route.params = { appName: 'fakeapp' };
|
||||||
route.data = { 'clientRoles': ['appName'], 'roles': ['role1', 'role2'] };
|
route.data = { 'clientRoles': ['appName'], 'roles': ['role1', 'role2'] };
|
||||||
|
|
||||||
expect(authGuard.canActivate(route, null)).toBeFalsy();
|
expect(authGuard.canActivate(route, null)).toBeFalsy();
|
||||||
@@ -172,10 +174,11 @@ describe('Auth Guard SSO role service', () => {
|
|||||||
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
||||||
|
|
||||||
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
|
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
|
||||||
{'resource_access': { fakeapp: { roles: ['role1'] } }
|
{
|
||||||
});
|
'resource_access': { fakeapp: { roles: ['role1'] } }
|
||||||
|
});
|
||||||
|
|
||||||
const result = authGuard.hasRealmRolesForClientRole('fakeapp', ['role1'] );
|
const result = authGuard.hasRealmRolesForClientRole('fakeapp', ['role1']);
|
||||||
expect(result).toBeTruthy();
|
expect(result).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -183,18 +186,20 @@ describe('Auth Guard SSO role service', () => {
|
|||||||
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
||||||
|
|
||||||
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
|
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
|
||||||
{'resource_access': { fakeapp: { roles: ['role1'] } }
|
{
|
||||||
});
|
'resource_access': { fakeapp: { roles: ['role1'] } }
|
||||||
|
});
|
||||||
|
|
||||||
const result = authGuard.hasRealmRolesForClientRole('fakeapp', ['role1', 'role2'] );
|
const result = authGuard.hasRealmRolesForClientRole('fakeapp', ['role1', 'role2']);
|
||||||
expect(result).toBeTruthy();
|
expect(result).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be false if the resource_access does not contain the role', () => {
|
it('Should be false if the resource_access does not contain the role', () => {
|
||||||
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
||||||
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
|
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
|
||||||
{'resource_access': { fakeapp: { roles: ['role3'] } }
|
{
|
||||||
});
|
'resource_access': { fakeapp: { roles: ['role3'] } }
|
||||||
|
});
|
||||||
const result = authGuard.hasRealmRolesForClientRole('fakeapp', ['role1', 'role2']);
|
const result = authGuard.hasRealmRolesForClientRole('fakeapp', ['role1', 'role2']);
|
||||||
expect(result).toBeFalsy();
|
expect(result).toBeFalsy();
|
||||||
});
|
});
|
||||||
@@ -202,8 +207,9 @@ describe('Auth Guard SSO role service', () => {
|
|||||||
it('Should be false if the resource_access does not contain the client role related to the app', () => {
|
it('Should be false if the resource_access does not contain the client role related to the app', () => {
|
||||||
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
spyOn(storageService, 'getItem').and.returnValue('my-access_token');
|
||||||
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
|
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
|
||||||
{'resource_access': { anotherfakeapp: { roles: ['role1'] } }
|
{
|
||||||
});
|
'resource_access': { anotherfakeapp: { roles: ['role1'] } }
|
||||||
|
});
|
||||||
const result = authGuard.hasRealmRolesForClientRole('fakeapp', ['role1', 'role2']);
|
const result = authGuard.hasRealmRolesForClientRole('fakeapp', ['role1', 'role2']);
|
||||||
expect(result).toBeFalsy();
|
expect(result).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
@@ -323,6 +323,73 @@ describe('Test PdfViewer component', () => {
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Password protection dialog', () => {
|
||||||
|
|
||||||
|
let fixtureUrlTestPasswordComponent: ComponentFixture<UrlTestPasswordComponent>;
|
||||||
|
let componentUrlTestPasswordComponent: UrlTestPasswordComponent;
|
||||||
|
|
||||||
|
beforeEach((done) => {
|
||||||
|
fixtureUrlTestPasswordComponent = TestBed.createComponent(UrlTestPasswordComponent);
|
||||||
|
componentUrlTestPasswordComponent = fixtureUrlTestPasswordComponent.componentInstance;
|
||||||
|
|
||||||
|
spyOn(dialog, 'open').and.callFake((comp, context) => {
|
||||||
|
if (context.data.reason === pdfjsLib.PasswordResponses.NEED_PASSWORD) {
|
||||||
|
return {
|
||||||
|
afterClosed: () => of('wrong_password')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.data.reason === pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) {
|
||||||
|
return {
|
||||||
|
afterClosed: () => of('password')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fixtureUrlTestPasswordComponent.detectChanges();
|
||||||
|
|
||||||
|
componentUrlTestPasswordComponent.pdfViewerComponent.rendered.subscribe(() => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
document.body.removeChild(fixtureUrlTestPasswordComponent.nativeElement);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should try to access protected pdf', (done) => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(dialog.open).toHaveBeenCalledTimes(2);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should raise dialog asking for password', (done) => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(dialog.open['calls'].all()[0].args[1].data).toEqual({
|
||||||
|
reason: pdfjsLib.PasswordResponses.NEED_PASSWORD
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('it should raise dialog with incorrect password', (done) => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(dialog.open['calls'].all()[1].args[1].data).toEqual({
|
||||||
|
reason: pdfjsLib.PasswordResponses.INCORRECT_PASSWORD
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('User interaction', () => {
|
describe('User interaction', () => {
|
||||||
|
|
||||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||||
@@ -432,72 +499,36 @@ describe('Test PdfViewer component', () => {
|
|||||||
});
|
});
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
describe('Zoom', () => {
|
|
||||||
|
|
||||||
it('should zoom in increment the scale value', fakeAsync(() => {
|
|
||||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
|
||||||
});
|
|
||||||
|
|
||||||
const zoomInButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-in-button');
|
|
||||||
|
|
||||||
tick(250);
|
|
||||||
|
|
||||||
const zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
|
||||||
zoomInButton.click();
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
|
||||||
const currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
|
||||||
expect(zoomBefore < currentZoom).toBe(true);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should zoom out decrement the scale value', fakeAsync(() => {
|
|
||||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
|
||||||
});
|
|
||||||
const zoomOutButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-out-button');
|
|
||||||
|
|
||||||
tick(250);
|
|
||||||
|
|
||||||
const zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
|
||||||
zoomOutButton.click();
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
|
||||||
const currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
|
||||||
expect(zoomBefore > currentZoom).toBe(true);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should it-in button toggle page-fit and auto scale mode', fakeAsync(() => {
|
|
||||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
|
||||||
});
|
|
||||||
|
|
||||||
const itPage: any = elementUrlTestComponent.querySelector('#viewer-scale-page-button');
|
|
||||||
|
|
||||||
tick(250);
|
|
||||||
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
|
||||||
itPage.click();
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('page-fit');
|
|
||||||
itPage.click();
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Resize interaction', () => {
|
describe('Resize interaction', () => {
|
||||||
|
|
||||||
it('should resize event trigger setScaleUpdatePages', () => {
|
it('should resize event trigger setScaleUpdatePages', (done) => {
|
||||||
spyOn(componentUrlTestComponent.pdfViewerComponent, 'onResize');
|
spyOn(componentUrlTestComponent.pdfViewerComponent, 'onResize');
|
||||||
EventMock.resizeMobileView();
|
EventMock.resizeMobileView();
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.onResize).toHaveBeenCalled();
|
|
||||||
|
fixtureUrlTestComponent.whenStable().then(() => {
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.onResize).toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
}, 5000);
|
}, 5000);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Thumbnails', () => {
|
describe('Thumbnails', () => {
|
||||||
|
|
||||||
it('should have own context', () => {
|
it('should have own context', (done) => {
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.pdfThumbnailsContext.viewer).not.toBeNull();
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.whenStable().then(() => {
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.pdfThumbnailsContext.viewer).not.toBeNull();
|
||||||
|
done();
|
||||||
|
});
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
it('should open thumbnails panel', (done) => {
|
it('should open thumbnails panel', (done) => {
|
||||||
expect(elementUrlTestComponent.querySelector('.adf-pdf-viewer__thumbnails')).toBeNull();
|
expect(elementUrlTestComponent.querySelector('.adf-pdf-viewer__thumbnails')).toBeNull();
|
||||||
|
|
||||||
componentUrlTestComponent.pdfViewerComponent.toggleThumbnails();
|
componentUrlTestComponent.pdfViewerComponent.toggleThumbnails();
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
fixtureUrlTestComponent.whenStable().then(() => {
|
||||||
@@ -556,72 +587,53 @@ describe('Test PdfViewer component', () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Zoom', () => {
|
||||||
|
|
||||||
|
it('should zoom in increment the scale value', fakeAsync(() => {
|
||||||
|
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
||||||
|
});
|
||||||
|
|
||||||
|
const zoomInButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-in-button');
|
||||||
|
|
||||||
|
tick(250);
|
||||||
|
|
||||||
|
const zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||||
|
zoomInButton.click();
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||||
|
const currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||||
|
expect(zoomBefore < currentZoom).toBe(true);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should zoom out decrement the scale value', fakeAsync(() => {
|
||||||
|
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
||||||
|
});
|
||||||
|
const zoomOutButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-out-button');
|
||||||
|
|
||||||
|
tick(250);
|
||||||
|
|
||||||
|
const zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||||
|
zoomOutButton.click();
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||||
|
const currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||||
|
expect(zoomBefore > currentZoom).toBe(true);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should it-in button toggle page-fit and auto scale mode', fakeAsync(() => {
|
||||||
|
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {
|
||||||
|
});
|
||||||
|
|
||||||
|
const itPage: any = elementUrlTestComponent.querySelector('#viewer-scale-page-button');
|
||||||
|
|
||||||
|
tick(250);
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||||
|
itPage.click();
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('page-fit');
|
||||||
|
itPage.click();
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Password protection dialog', () => {
|
|
||||||
|
|
||||||
let fixtureUrlTestPasswordComponent: ComponentFixture<UrlTestPasswordComponent>;
|
|
||||||
let componentUrlTestPasswordComponent: UrlTestPasswordComponent;
|
|
||||||
|
|
||||||
beforeEach((done) => {
|
|
||||||
fixtureUrlTestPasswordComponent = TestBed.createComponent(UrlTestPasswordComponent);
|
|
||||||
componentUrlTestPasswordComponent = fixtureUrlTestPasswordComponent.componentInstance;
|
|
||||||
|
|
||||||
spyOn(dialog, 'open').and.callFake((comp, context) => {
|
|
||||||
if (context.data.reason === pdfjsLib.PasswordResponses.NEED_PASSWORD) {
|
|
||||||
return {
|
|
||||||
afterClosed: () => of('wrong_password')
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context.data.reason === pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) {
|
|
||||||
return {
|
|
||||||
afterClosed: () => of('password')
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
fixtureUrlTestPasswordComponent.detectChanges();
|
|
||||||
|
|
||||||
componentUrlTestPasswordComponent.pdfViewerComponent.rendered.subscribe(() => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
document.body.removeChild(fixtureUrlTestPasswordComponent.nativeElement);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should try to access protected pdf', (done) => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
expect(dialog.open).toHaveBeenCalledTimes(2);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should raise dialog asking for password', (done) => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
expect(dialog.open['calls'].all()[0].args[1].data).toEqual({
|
|
||||||
reason: pdfjsLib.PasswordResponses.NEED_PASSWORD
|
|
||||||
});
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('it should raise dialog with incorrect password', (done) => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
expect(dialog.open['calls'].all()[1].args[1].data).toEqual({
|
|
||||||
reason: pdfjsLib.PasswordResponses.INCORRECT_PASSWORD
|
|
||||||
});
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@@ -88,20 +88,6 @@ describe('TaskHeaderComponent', () => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should display clickable edit icon', async(() => {
|
|
||||||
component.refreshData();
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
const formNameEl = fixture.debugElement.query(By.css('[data-automation-id="header-assignee"] .adf-textitem-clickable-value'));
|
|
||||||
const iconE = fixture.debugElement.query(By.css(`[data-automation-id="card-textitem-edit-icon-create"]`));
|
|
||||||
expect(formNameEl).not.toBeNull();
|
|
||||||
expect(iconE).not.toBeNull();
|
|
||||||
expect(formNameEl.nativeElement.innerText).toBe('Wilbur Adams');
|
|
||||||
expect(iconE.nativeElement.innerText.trim()).toBe('create');
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should display placeholder if no assignee', async(() => {
|
it('should display placeholder if no assignee', async(() => {
|
||||||
component.taskDetails.assignee = null;
|
component.taskDetails.assignee = null;
|
||||||
component.refreshData();
|
component.refreshData();
|
||||||
|
Reference in New Issue
Block a user