mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[AAE-10315] fix karma 404 for images and certain errors in the Core unit tests (#8072)
* fix user info image warnings * fix login errors in unit tests * fix tooltip card warnings
This commit is contained in:
parent
bc7c052059
commit
310b04919e
@ -24,15 +24,17 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { TooltipCardComponent } from './tooltip-card.component';
|
||||
|
||||
const IMAGE_URL = 'alfresco-logo.svg';
|
||||
|
||||
@Component({
|
||||
template: `<span #span [adf-tooltip-card]="'Sample text'" [image]="'/assets/testImg.png'" [width]="'400'" [htmlContent]="'this is the <b>html</b> raw code'" class="test-component"></span>`
|
||||
template: `<span #span [adf-tooltip-card]="'Sample text'" [image]="'${IMAGE_URL}'" [width]="'400'" [htmlContent]="'this is the <b>html</b> raw code'" class="test-component"></span>`
|
||||
})
|
||||
class TestComponent {
|
||||
@ViewChild(TooltipCardDirective, { static: true })
|
||||
public directive: TooltipCardDirective;
|
||||
directive: TooltipCardDirective;
|
||||
|
||||
@ViewChild('span', { static: true })
|
||||
public span: ElementRef;
|
||||
span: ElementRef;
|
||||
}
|
||||
|
||||
describe('TooltipCardDirective', () => {
|
||||
@ -79,7 +81,7 @@ describe('TooltipCardDirective', () => {
|
||||
const div = tooltipCard.querySelector<HTMLElement>('div');
|
||||
expect(tooltipCard.getAttribute('style')).toBe('width: 400px;');
|
||||
expect(text.textContent.trim()).toEqual('Sample text');
|
||||
expect(img.getAttribute('src')).toEqual('/assets/testImg.png');
|
||||
expect(img.getAttribute('src')).toEqual(IMAGE_URL);
|
||||
expect(img.getAttribute('width')).toEqual('400');
|
||||
expect(div.innerHTML).toEqual('this is the <b>html</b> raw code');
|
||||
});
|
||||
|
@ -27,9 +27,9 @@ import { LoginSuccessEvent } from '../models/login-success.event';
|
||||
import { LoginComponent } from './login.component';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||
|
||||
import { setupTestBed } from '../../testing/setup-test-bed';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { LogService } from '../../services/log.service';
|
||||
|
||||
describe('LoginComponent', () => {
|
||||
let component: LoginComponent;
|
||||
@ -77,6 +77,9 @@ describe('LoginComponent', () => {
|
||||
appConfigService = TestBed.inject(AppConfigService);
|
||||
alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||
|
||||
const logService = TestBed.inject(LogService);
|
||||
spyOn(logService, 'error');
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
@ -173,6 +176,7 @@ describe('LoginComponent', () => {
|
||||
|
||||
it('should update user preferences upon login', async () => {
|
||||
spyOn(userPreferences, 'setStoragePrefix').and.callThrough();
|
||||
spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' }));
|
||||
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve());
|
||||
|
||||
component.success.subscribe(() => {
|
||||
@ -195,7 +199,7 @@ describe('LoginComponent', () => {
|
||||
});
|
||||
|
||||
it('should be changed to the "checking key" after a login attempt', () => {
|
||||
spyOn(authService, 'login').and.stub();
|
||||
spyOn(component, 'performLogin').and.stub();
|
||||
|
||||
loginWithCredentials('fake-username', 'fake-password');
|
||||
|
||||
@ -293,7 +297,7 @@ describe('LoginComponent', () => {
|
||||
});
|
||||
|
||||
it('should be taken into consideration during login attempt', fakeAsync(() => {
|
||||
spyOn(authService, 'login').and.stub();
|
||||
spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' }));
|
||||
component.rememberMe = false;
|
||||
|
||||
loginWithCredentials('fake-username', 'fake-password');
|
||||
|
@ -22,7 +22,6 @@ import {
|
||||
import { AbstractControl, UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
|
||||
import { Router, ActivatedRoute, Params } from '@angular/router';
|
||||
import { AuthenticationService } from '../../services/authentication.service';
|
||||
import { LogService } from '../../services/log.service';
|
||||
import { TranslationService } from '../../services/translation.service';
|
||||
import { UserPreferencesService } from '../../services/user-preferences.service';
|
||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||
@ -134,7 +133,6 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||
private _fb: UntypedFormBuilder,
|
||||
private authService: AuthenticationService,
|
||||
private translateService: TranslationService,
|
||||
private logService: LogService,
|
||||
private router: Router,
|
||||
private appConfig: AppConfigService,
|
||||
private userPreferences: UserPreferencesService,
|
||||
@ -209,6 +207,7 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||
this.executeSubmit.emit(args);
|
||||
|
||||
if (!args.defaultPrevented) {
|
||||
this.actualLoginStep = LoginSteps.Checking;
|
||||
this.performLogin(values);
|
||||
}
|
||||
}
|
||||
@ -249,8 +248,7 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
private performLogin(values: any) {
|
||||
this.actualLoginStep = LoginSteps.Checking;
|
||||
performLogin(values: { username: string; password: string }) {
|
||||
this.authService
|
||||
.login(values.username, values.password, this.rememberMe)
|
||||
.subscribe(
|
||||
@ -276,8 +274,7 @@ export class LoginComponent implements OnInit, OnDestroy {
|
||||
this.displayErrorMessage(err);
|
||||
this.isError = true;
|
||||
this.error.emit(new LoginErrorEvent(err));
|
||||
},
|
||||
() => this.logService.info('Login done')
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,7 @@ class FakeSanitizer extends DomSanitizer {
|
||||
}
|
||||
|
||||
describe('User info component', () => {
|
||||
const profilePictureUrl = 'alfresco-logo.svg';
|
||||
|
||||
let component: UserInfoComponent;
|
||||
let fixture: ComponentFixture<UserInfoComponent>;
|
||||
@ -111,8 +112,8 @@ describe('User info component', () => {
|
||||
identityUserService = TestBed.inject(IdentityUserService);
|
||||
|
||||
spyOn(window, 'requestAnimationFrame').and.returnValue(1);
|
||||
spyOn(bpmUserService, 'getCurrentUserProfileImage').and.returnValue('app/rest/admin/profile-picture');
|
||||
spyOn(contentService, 'getContentUrl').and.returnValue('alfresco-logo.svg');
|
||||
spyOn(bpmUserService, 'getCurrentUserProfileImage').and.returnValue(profilePictureUrl);
|
||||
spyOn(contentService, 'getContentUrl').and.returnValue(profilePictureUrl);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -215,7 +216,7 @@ describe('User info component', () => {
|
||||
|
||||
expect(element.querySelector('#userinfo_container')).not.toBeNull();
|
||||
expect(loggedImage).not.toBeNull();
|
||||
expect(loggedImage.properties.src).toContain('alfresco-logo.svg');
|
||||
expect(loggedImage.properties.src).toContain(profilePictureUrl);
|
||||
});
|
||||
|
||||
it('should display the current user image if user has avatarId', (done) => {
|
||||
@ -228,7 +229,7 @@ describe('User info component', () => {
|
||||
});
|
||||
expect(element.querySelector('#userinfo_container')).not.toBeNull();
|
||||
expect(loggedImage).not.toBeNull();
|
||||
expect(loggedImage.properties.src).toContain('alfresco-logo.svg');
|
||||
expect(loggedImage.properties.src).toContain(profilePictureUrl);
|
||||
});
|
||||
|
||||
it('should get the ecm user information from the service', async () => {
|
||||
@ -240,7 +241,7 @@ describe('User info component', () => {
|
||||
expect(element.querySelector('#userinfo_container')).not.toBeNull();
|
||||
expect(fixture.debugElement.query(By.css('#ecm-username'))).not.toBeNull();
|
||||
expect(ecmImage).not.toBeNull();
|
||||
expect(ecmImage.properties.src).toContain('alfresco-logo.svg');
|
||||
expect(ecmImage.properties.src).toContain(profilePictureUrl);
|
||||
expect(ecmFullName.nativeElement.textContent).toContain('fake-ecm-first-name fake-ecm-last-name');
|
||||
expect(ecmJobTitle.nativeElement.textContent).toContain('USER_PROFILE.LABELS.ECM.JOB_TITLE');
|
||||
});
|
||||
@ -335,8 +336,7 @@ describe('User info component', () => {
|
||||
await whenFixtureReady();
|
||||
expect(element.querySelector('#userinfo_container')).not.toBeNull();
|
||||
expect(element.querySelector('#logged-user-img')).not.toBeNull();
|
||||
expect(element.querySelector('#logged-user-img').getAttribute('src'))
|
||||
.toContain('app/rest/admin/profile-picture');
|
||||
expect(element.querySelector('#logged-user-img').getAttribute('src')).toContain(profilePictureUrl);
|
||||
});
|
||||
|
||||
it('should show last name if first name is null', async () => {
|
||||
@ -387,7 +387,7 @@ describe('User info component', () => {
|
||||
expect(element.querySelector('#userinfo_container')).not.toBeNull();
|
||||
expect(bpmUsername).not.toBeNull();
|
||||
expect(bpmImage).not.toBeNull();
|
||||
expect(bpmImage.properties.src).toContain('app/rest/admin/profile-picture');
|
||||
expect(bpmImage.properties.src).toContain(profilePictureUrl);
|
||||
expect(bpmUsername.nativeElement.textContent).toContain('fake-bpm-first-name fake-bpm-last-name');
|
||||
expect(fixture.debugElement.query(By.css('#bpm-tenant')).nativeElement.textContent).toContain('fake-tenant-name');
|
||||
});
|
||||
@ -403,7 +403,7 @@ describe('User info component', () => {
|
||||
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||
expect(ecmUsername).not.toBeNull();
|
||||
expect(ecmImage).not.toBeNull();
|
||||
expect(ecmImage.properties.src).toContain('alfresco-logo.svg');
|
||||
expect(ecmImage.properties.src).toContain(profilePictureUrl);
|
||||
expect(fixture.debugElement.query(By.css('#ecm-full-name')).nativeElement.textContent).toContain('fake-ecm-first-name fake-ecm-last-name');
|
||||
expect(fixture.debugElement.query(By.css('#ecm-job-title')).nativeElement.textContent).toContain('job-ecm-test');
|
||||
});
|
||||
@ -413,7 +413,7 @@ describe('User info component', () => {
|
||||
openUserInfo();
|
||||
expect(element.querySelector('#userinfo_container')).toBeDefined();
|
||||
expect(element.querySelector('#logged-user-img')).toBeDefined();
|
||||
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual('alfresco-logo.svg');
|
||||
expect(element.querySelector('#logged-user-img').getAttribute('src')).toEqual(profilePictureUrl);
|
||||
});
|
||||
|
||||
it('should show the ecm initials if the ecm user has no image', async () => {
|
||||
@ -572,7 +572,7 @@ describe('User info component', () => {
|
||||
await fixture.whenStable();
|
||||
const bpmUsername = fixture.debugElement.query(By.css('#bpm-username'));
|
||||
const bpmImage = fixture.debugElement.query(By.css('#bpm-user-detail-image'));
|
||||
expect(bpmImage.properties.src).toContain('app/rest/admin/profile-picture');
|
||||
expect(bpmImage.properties.src).toContain(profilePictureUrl);
|
||||
expect(bpmUsername.nativeElement.textContent).toContain('fake-bpm-first-name fake-bpm-last-name');
|
||||
expect(fixture.debugElement.query(By.css('#bpm-tenant')).nativeElement.textContent).toContain('fake-tenant-name');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user