[ADF-3384] Create automated tests for Version Component (#3631)

* fix version component restore and delete event

* version manager actions

* fix test

* fix unit test

* remove fdescribe

* fix tslint

* fix screenshot rewrite problem

* remove fdescribe

* multi instance try

* remove fdescribe

* try uncomment some test

* error page

* fix user preferences pagiantion

* search page test include

* fix type tslint e2e

* restore code

* default lang momentadapter

* fix test

* [ADF-3384] removed console log from test

* [ADF-3384] adding some fixes for tests and code

* [ADF-3384] fixed some test and code
This commit is contained in:
Eugenio Romano
2018-08-03 18:12:03 +01:00
committed by Eugenio Romano
parent 17074478e2
commit a12662e7e2
101 changed files with 2047 additions and 718 deletions

View File

@@ -18,7 +18,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ObjectUtils } from '../utils/object-utils';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Subject } from 'rxjs/Subject';
import { Observable } from 'rxjs/Observable';
export enum AppConfigValues {
@@ -49,11 +49,11 @@ export class AppConfigService {
alfrescoRepositoryName: 'alfresco-1'
};
private onLoadSubject: BehaviorSubject<any>;
private onLoadSubject: Subject<any>;
onLoad: Observable<any>;
constructor(private http: HttpClient) {
this.onLoadSubject = new BehaviorSubject(this.config);
this.onLoadSubject = new Subject();
this.onLoad = this.onLoadSubject.asObservable();
}

View File

@@ -21,6 +21,7 @@ import { Component, HostListener, Input, OnDestroy, OnInit, Renderer2, ViewChild
import { MatMenuTrigger } from '@angular/material';
import { Subscription } from 'rxjs/Subscription';
import { ContextMenuService } from './context-menu.service';
/**
* @deprecated: context-menu-holder is deprecated, use adf-context-menu-holder instead.
*/
@@ -31,9 +32,9 @@ import { ContextMenuService } from './context-menu.service';
<mat-menu #contextMenu="matMenu" class="context-menu">
<ng-container *ngFor="let link of links">
<button *ngIf="link.model?.visible"
mat-menu-item
[disabled]="link.model?.disabled"
(click)="onMenuItemClick($event, link)">
mat-menu-item
[disabled]="link.model?.disabled"
(click)="onMenuItemClick($event, link)">
<mat-icon *ngIf="showIcons && link.model?.icon">{{ link.model.icon }}</mat-icon>
{{ (link.title || link.model?.title) | translate }}
</button>
@@ -44,7 +45,7 @@ import { ContextMenuService } from './context-menu.service';
export class ContextMenuHolderComponent implements OnInit, OnDestroy {
links = [];
private mouseLocation: { left: number, top: number } = {left: 0, top: 0};
private mouseLocation: { left: number, top: number } = { left: 0, top: 0 };
private menuElement = null;
private subscriptions: Subscription[] = [];
private contextMenuListenerFn: () => void;
@@ -70,11 +71,12 @@ export class ContextMenuHolderComponent implements OnInit, OnDestroy {
}
constructor(
private viewport: ViewportRuler,
private overlayContainer: OverlayContainer,
private contextMenuService: ContextMenuService,
private renderer: Renderer2
) {}
private viewport: ViewportRuler,
private overlayContainer: OverlayContainer,
private contextMenuService: ContextMenuService,
private renderer: Renderer2
) {
}
ngOnInit() {
this.subscriptions.push(
@@ -149,20 +151,22 @@ export class ContextMenuHolderComponent implements OnInit, OnDestroy {
private updatePosition() {
setTimeout(() => {
if (this.mdMenuElement.clientWidth + this.mouseLocation.left > this.viewport.getViewportRect().width) {
this.menuTrigger.menu.xPosition = 'before';
this.mdMenuElement.parentElement.style.left = this.mouseLocation.left - this.mdMenuElement.clientWidth + 'px';
} else {
this.menuTrigger.menu.xPosition = 'after';
this.mdMenuElement.parentElement.style.left = this.locationCss().left;
}
if (this.mdMenuElement.parentElement) {
if (this.mdMenuElement.clientWidth + this.mouseLocation.left > this.viewport.getViewportRect().width) {
this.menuTrigger.menu.xPosition = 'before';
this.mdMenuElement.parentElement.style.left = this.mouseLocation.left - this.mdMenuElement.clientWidth + 'px';
} else {
this.menuTrigger.menu.xPosition = 'after';
this.mdMenuElement.parentElement.style.left = this.locationCss().left;
}
if (this.mdMenuElement.clientHeight + this.mouseLocation.top > this.viewport.getViewportRect().height) {
this.menuTrigger.menu.yPosition = 'above';
this.mdMenuElement.parentElement.style.top = this.mouseLocation.top - this.mdMenuElement.clientHeight + 'px';
} else {
this.menuTrigger.menu.yPosition = 'below';
this.mdMenuElement.parentElement.style.top = this.locationCss().top;
if (this.mdMenuElement.clientHeight + this.mouseLocation.top > this.viewport.getViewportRect().height) {
this.menuTrigger.menu.yPosition = 'above';
this.mdMenuElement.parentElement.style.top = this.mouseLocation.top - this.mdMenuElement.clientHeight + 'px';
} else {
this.menuTrigger.menu.yPosition = 'below';
this.mdMenuElement.parentElement.style.top = this.locationCss().top;
}
}
}, 0);
}

View File

@@ -232,6 +232,8 @@ describe('PaginationComponent', () => {
describe('Without pagination input', () => {
it('has defaults', () => {
component.ngOnInit();
const {
current, lastPage, isFirstPage, isLastPage,
next, previous, range, pages

View File

@@ -15,14 +15,17 @@
* limitations under the License.
*/
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation,
ChangeDetectorRef, OnDestroy, HostBinding } from '@angular/core';
import {
ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation,
ChangeDetectorRef, OnDestroy, HostBinding
} from '@angular/core';
import { Pagination } from 'alfresco-js-api';
import { PaginatedComponent } from './paginated-component.interface';
import { PaginationComponentInterface } from './pagination-component.interface';
import { Subscription } from 'rxjs/Subscription';
import { PaginationModel } from '../models/pagination.model';
import { UserPreferencesService } from '../services/user-preferences.service';
@Component({
selector: 'adf-pagination',
@@ -53,11 +56,11 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
/** An array of page sizes. */
@Input()
supportedPageSizes: number[] = [5, 25, 50, 100];
supportedPageSizes: number[];
/** Pagination object. */
@Input()
pagination: PaginationModel = PaginationComponent.DEFAULT_PAGINATION;
pagination: PaginationModel;
/** Emitted when pagination changes in any way. */
@Output()
@@ -81,10 +84,20 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
private paginationSubscription: Subscription;
constructor(private cdr: ChangeDetectorRef) {
constructor(private cdr: ChangeDetectorRef, private userPreferencesService: UserPreferencesService) {
}
ngOnInit() {
if (!this.pagination) {
let defaultPagination = PaginationComponent.DEFAULT_PAGINATION;
defaultPagination.maxItems = this.userPreferencesService.paginationSize;
this.pagination = defaultPagination;
}
if (!this.supportedPageSizes) {
this.supportedPageSizes = this.userPreferencesService.getDefaultPageSizes();
}
if (this.target) {
this.paginationSubscription = this.target.pagination.subscribe((pagination: PaginationModel) => {

View File

@@ -56,7 +56,7 @@ export class TranslationService {
}
}
userPreference.locale$.subscribe( (locale) => {
userPreference.locale$.subscribe((locale) => {
this.userLang = locale;
this.use(this.userLang);
});
@@ -70,22 +70,18 @@ export class TranslationService {
addTranslationFolder(name: string = '', path: string = '') {
if (!this.customLoader.providerRegistered(name)) {
this.customLoader.registerProvider(name, path);
if (this.userLang !== this.defaultLang) {
this.translate.getTranslation(this.defaultLang).subscribe(() => {
this.translate.getTranslation(this.userLang).subscribe(
() => {
this.translate.use(this.userLang);
this.onTranslationChanged(this.userLang);
}
);
});
} else {
this.translate.getTranslation(this.userLang).subscribe(
() => {
if (this.userLang) {
this.translate.getTranslation(this.userLang).subscribe(() => {
this.translate.use(this.userLang);
this.onTranslationChanged(this.userLang);
}
);
} else {
this.translate.getTranslation(this.defaultLang).subscribe(() => {
this.translate.use(this.defaultLang);
this.onTranslationChanged(this.defaultLang);
}
);
}
}
}
@@ -117,7 +113,7 @@ export class TranslationService {
* @param interpolateParams String(s) to be interpolated into the main message
* @returns Translated text
*/
get(key: string|Array<string>, interpolateParams?: Object): Observable<string|any> {
get(key: string | Array<string>, interpolateParams?: Object): Observable<string | any> {
return this.translate.get(key, interpolateParams);
}

View File

@@ -53,7 +53,7 @@ export class UserPreferencesService {
private appConfig: AppConfigService,
private storage: StorageService) {
this.appConfig.onLoad.subscribe(this.initUserPreferenceStatus.bind(this));
this.localeSubject = new BehaviorSubject(this.userPreferenceStatus[UserPreferenceValues.Locale]);
this.localeSubject = new BehaviorSubject(this.get(UserPreferenceValues.Locale, this.getDefaultLocale()));
this.locale$ = this.localeSubject.asObservable();
this.onChangeSubject = new BehaviorSubject(this.userPreferenceStatus);
this.onChange = this.onChangeSubject.asObservable();
@@ -61,8 +61,7 @@ export class UserPreferencesService {
private initUserPreferenceStatus() {
this.userPreferenceStatus[UserPreferenceValues.Locale] = this.locale || this.getDefaultLocale();
this.userPreferenceStatus[UserPreferenceValues.PaginationSize] = this.paginationSize ?
this.paginationSize : this.appConfig.get('pagination.size', this.defaults.paginationSize);
this.userPreferenceStatus[UserPreferenceValues.PaginationSize] = this.appConfig.get('pagination.size', this.defaults.paginationSize);
this.userPreferenceStatus[UserPreferenceValues.SupportedPageSizes] = this.appConfig.get('pagination.supportedPageSizes', this.defaults.supportedPageSizes);
}
@@ -150,27 +149,27 @@ export class UserPreferencesService {
* @returns Array of page size values
*/
getDefaultPageSizes(): number[] {
return this.defaults.supportedPageSizes;
return this.userPreferenceStatus[UserPreferenceValues.SupportedPageSizes];
}
/** Pagination size. */
set paginationSize(value: number) {
this.set('PAGINATION_SIZE', value);
this.set(UserPreferenceValues.PaginationSize, value);
}
get paginationSize(): number {
return Number(this.get('PAGINATION_SIZE')) || this.defaults.paginationSize;
return Number(this.get(UserPreferenceValues.PaginationSize, this.userPreferenceStatus[UserPreferenceValues.PaginationSize])) || this.defaults.paginationSize;
}
/** Current locale setting. */
get locale(): string {
const locale = this.get('LOCALE');
const locale = this.get(UserPreferenceValues.Locale, this.userPreferenceStatus[UserPreferenceValues.Locale]);
return locale;
}
set locale(value: string) {
this.localeSubject.next(value);
this.set('LOCALE', value);
this.set(UserPreferenceValues.Locale, value);
}
/**

View File

@@ -10,12 +10,12 @@
{{ 'ERROR_CONTENT.' + errorCode + '.DESCRIPTION' | translate }}
</p>
<div class="adf-error-content-buttons">
<a mat-raised-button color="primary"
<a a id="adf-secondary-button" mat-raised-button color="primary"
*ngIf="secondaryButtonText" (click)="onSecondButton()"
class="adf-error-content-description-link">
class="adf-error-content-description-link">
{{ 'ERROR_CONTENT.' + errorCode + '.SECONDARY_BUTTON.TEXT' | translate | uppercase }}
</a>
<a mat-raised-button color="primary" (click)="onReturnButton()">
<a id="adf-return-button" mat-raised-button color="primary" (click)="onReturnButton()">
{{ 'ERROR_CONTENT.' + this.errorCode + '.RETURN_BUTTON.TEXT' | translate | uppercase }}
</a>
</div>

View File

@@ -89,7 +89,8 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
}
clone(date: Moment): Moment {
return date.clone().locale(this.locale);
let locale = this.locale || 'en';
return date.clone().locale(locale);
}
createDate(year: number, month: number, date: number): Moment {
@@ -97,16 +98,18 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
}
today(): Moment {
return moment().locale(this.locale);
let locale = this.locale || 'en';
return moment().locale(locale);
}
parse(value: any, parseFormat: any): Moment {
let locale = this.locale || 'en';
if (value && typeof value === 'string') {
let m = moment(value, parseFormat, this.locale, true);
let m = moment(value, parseFormat, locale, true);
if (!m.isValid()) {
// use strict parsing because Moment's parser is very forgiving, and this can lead to undesired behavior.
m = moment(value, this.overrideDisplyaFormat, this.locale, true);
m = moment(value, this.overrideDisplyaFormat, locale, true);
}
if (m.isValid()) {
// if user omits year, it defaults to 2001, so check for that issue.
@@ -123,7 +126,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
return m;
}
return value ? moment(value).locale(this.locale) : null;
return value ? moment(value).locale(locale) : null;
}
format(date: Moment, displayFormat: any): string {
@@ -204,7 +207,8 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
}
fromIso8601(iso8601String: string): Moment | null {
let d = moment(iso8601String, moment.ISO_8601).locale(this.locale);
let locale = this.locale || 'en';
let d = moment(iso8601String, moment.ISO_8601).locale(locale);
return this.isValid(d) ? d : null;
}