[ADF-3918] Fix translation issue (#4169)

This commit is contained in:
Eugenio Romano 2019-01-20 23:40:07 +00:00 committed by GitHub
parent 9a70852985
commit 348bee9c6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 253 additions and 201 deletions

View File

@ -8,6 +8,9 @@ node_js:
# Use the explicit NodeJS LTS version 8.9.4 to avoid any automatic upgrade of the version. # Use the explicit NodeJS LTS version 8.9.4 to avoid any automatic upgrade of the version.
- '8.9.4' - '8.9.4'
install:
echo "no install"
branches: branches:
only: only:
- master - master

View File

@ -8,6 +8,7 @@
"providers": "ALL", "providers": "ALL",
"contextRootBpm": "activiti-app", "contextRootBpm": "activiti-app",
"authType" : "BASIC", "authType" : "BASIC",
"locale" : "en",
"oauth2": { "oauth2": {
"host": "{protocol}//{hostname}{:port}/auth/realms/alfresco", "host": "{protocol}//{hostname}{:port}/auth/realms/alfresco",
"clientId": "alfresco", "clientId": "alfresco",

View File

@ -112,7 +112,7 @@ describe('Document List Component', () => {
it('[C279925] Should display translated message when accessing a file without permissions if language is changed', () => { it('[C279925] Should display translated message when accessing a file without permissions if language is changed', () => {
loginPage.loginToContentServicesUsingUserModel(acsUser); loginPage.loginToContentServicesUsingUserModel(acsUser);
navBar.openLanguageMenu(); navBar.openLanguageMenu();
navBar.chooseLanguage('Italian'); navBar.chooseLanguage('Italiano');
browser.sleep(2000); browser.sleep(2000);
browser.get(TestConfig.adf.url + '/files/' + privateSite.entry.guid); browser.get(TestConfig.adf.url + '/files/' + privateSite.entry.guid);
expect(errorPage.getErrorDescription()).toBe('Accesso alla risorsa sul server non consentito.'); expect(errorPage.getErrorDescription()).toBe('Accesso alla risorsa sul server non consentito.');

View File

@ -24,9 +24,9 @@ import { ContentServicesPage } from '../../pages/adf/contentServicesPage';
import { ContentListPage } from '../../pages/adf/dialog/contentListPage'; import { ContentListPage } from '../../pages/adf/dialog/contentListPage';
import { ShareDialog } from '../../pages/adf/dialog/shareDialog'; import { ShareDialog } from '../../pages/adf/dialog/shareDialog';
import CONSTANTS = require('../../util/constants');
import resources = require('../../util/resources'); import resources = require('../../util/resources');
import { Util } from '../../util/util'; import { Util } from '../../util/util';
import CONSTANTS = require('../../util/constants');
import { FileModel } from '../../models/ACS/fileModel'; import { FileModel } from '../../models/ACS/fileModel';
import { FolderModel } from '../../models/ACS/folderModel'; import { FolderModel } from '../../models/ACS/folderModel';
@ -89,6 +89,11 @@ describe('Viewer', () => {
'location': resources.Files.ADF_DOCUMENTS.IMG_FOLDER.folder_location 'location': resources.Files.ADF_DOCUMENTS.IMG_FOLDER.folder_location
}); });
let imgRenditionFolderInfo = new FolderModel({
'name': resources.Files.ADF_DOCUMENTS.IMG_RENDITION_FOLDER.folder_name,
'location': resources.Files.ADF_DOCUMENTS.IMG_RENDITION_FOLDER.folder_location
});
beforeAll(async (done) => { beforeAll(async (done) => {
this.alfrescoJsApi = new AlfrescoApi({ this.alfrescoJsApi = new AlfrescoApi({
@ -340,14 +345,18 @@ describe('Viewer', () => {
describe('Image Folder Uploaded', () => { describe('Image Folder Uploaded', () => {
let uploadedImages; let uploadedImages, uploadedImgRenditionFolderInfo;
let imgFolderUploaded; let imgFolderUploaded, imgFolderRenditionUploaded;
beforeAll(async (done) => { beforeAll(async (done) => {
imgFolderUploaded = await uploadActions.createFolder(this.alfrescoJsApi, imgFolderInfo.name, '-my-'); imgFolderUploaded = await uploadActions.createFolder(this.alfrescoJsApi, imgFolderInfo.name, '-my-');
uploadedImages = await uploadActions.uploadFolder(this.alfrescoJsApi, imgFolderInfo.location, imgFolderUploaded.entry.id); uploadedImages = await uploadActions.uploadFolder(this.alfrescoJsApi, imgFolderInfo.location, imgFolderUploaded.entry.id);
imgFolderRenditionUploaded = await uploadActions.createFolder(this.alfrescoJsApi, imgRenditionFolderInfo.name, imgFolderUploaded.entry.id);
uploadedImgRenditionFolderInfo = await uploadActions.uploadFolder(this.alfrescoJsApi, imgRenditionFolderInfo.location, imgFolderRenditionUploaded.entry.id);
loginPage.loginToContentServicesUsingUserModel(acsUser); loginPage.loginToContentServicesUsingUserModel(acsUser);
contentServicesPage.goToDocumentList(); contentServicesPage.goToDocumentList();
@ -363,6 +372,16 @@ describe('Viewer', () => {
contentServicesPage.navigateToFolder('images'); contentServicesPage.navigateToFolder('images');
uploadedImages.forEach((currentFile) => { uploadedImages.forEach((currentFile) => {
if (currentFile.entry.name !== '.DS_Store') {
contentServicesPage.doubleClickRow(currentFile.entry.name);
viewerPage.checkImgViewerIsDisplayed();
viewerPage.clickCloseButton();
}
});
contentServicesPage.navigateToFolder('images-rendition');
uploadedImgRenditionFolderInfo.forEach((currentFile) => {
if (currentFile.entry.name !== '.DS_Store') { if (currentFile.entry.name !== '.DS_Store') {
contentServicesPage.doubleClickRow(currentFile.entry.name); contentServicesPage.doubleClickRow(currentFile.entry.name);
viewerPage.checkFileIsLoaded(); viewerPage.checkFileIsLoaded();

View File

@ -352,8 +352,8 @@ export class ContentServicesPage {
return this; return this;
} }
doubleClickRow(folder) { doubleClickRow(nodeName) {
this.contentList.doubleClickRow(folder); this.contentList.doubleClickRow(nodeName);
return this; return this;
} }

View File

@ -489,6 +489,10 @@ exports.Files = {
IMG_FOLDER: { IMG_FOLDER: {
folder_location: "/resources/adf/allFileTypes/images", folder_location: "/resources/adf/allFileTypes/images",
folder_name: "images" folder_name: "images"
},
IMG_RENDITION_FOLDER: {
folder_location: "/resources/adf/allFileTypes/images-rendition",
folder_name: "images-rendition"
} }
}, },

View File

@ -34,7 +34,9 @@ describe('AppConfigService', () => {
}, },
files: { files: {
'excluded': ['excluded'] 'excluded': ['excluded']
} },
logLevel: 'silent',
alfrescoRepositoryName: 'alfresco-1'
}; };
beforeEach(() => { beforeEach(() => {
@ -127,6 +129,7 @@ describe('AppConfigService', () => {
it('should load external settings', () => { it('should load external settings', () => {
appConfigService.load().then((config) => { appConfigService.load().then((config) => {
expect(config).toEqual(mockResponse); expect(config).toEqual(mockResponse);
}); });
}); });

View File

@ -38,6 +38,13 @@ export enum AppConfigValues {
LOGIN_ROUTE = 'loginRoute', LOGIN_ROUTE = 'loginRoute',
DISABLECSRF = 'disableCSRF' DISABLECSRF = 'disableCSRF'
} }
export enum Status {
INIT = 'init',
LOADING = 'loading',
LOADED = 'loaded'
}
/* spellchecker: enable */ /* spellchecker: enable */
@Injectable({ @Injectable({
@ -55,7 +62,8 @@ export class AppConfigService {
alfrescoRepositoryName: 'alfresco-1' alfrescoRepositoryName: 'alfresco-1'
}; };
private onLoadSubject: Subject<any>; status: Status = Status.INIT;
protected onLoadSubject: Subject<any>;
onLoad: Observable<any>; onLoad: Observable<any>;
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
@ -128,11 +136,14 @@ export class AppConfigService {
* @returns Notification when loading is complete * @returns Notification when loading is complete
*/ */
load(): Promise<any> { load(): Promise<any> {
return new Promise((resolve) => { return new Promise(async (resolve) => {
const configUrl = `app.config.json?v=${Date.now()}`; const configUrl = `app.config.json?v=${Date.now()}`;
this.http.get(configUrl).subscribe( if (this.status === Status.INIT) {
this.status = Status.LOADING;
await this.http.get(configUrl).subscribe(
(data: any) => { (data: any) => {
this.status = Status.LOADED;
this.config = Object.assign({}, this.config, data || {}); this.config = Object.assign({}, this.config, data || {});
this.onLoadSubject.next(this.config); this.onLoadSubject.next(this.config);
resolve(this.config); resolve(this.config);
@ -141,6 +152,13 @@ export class AppConfigService {
resolve(this.config); resolve(this.config);
} }
); );
} else if (this.status === Status.LOADED) {
resolve(this.config);
} else if (this.status === Status.LOADING) {
this.onLoad.subscribe(() => {
resolve(this.config);
});
}
}); });
} }

View File

@ -54,8 +54,7 @@ export abstract class DataTableSchema {
} }
public mergeJsonAndHtmlSchema(): any { public mergeJsonAndHtmlSchema(): any {
let customSchemaColumns = []; let customSchemaColumns = this.getSchemaFromConfig(this.presetColumn).concat(this.getSchemaFromHtml(this.columnList));
customSchemaColumns = this.getSchemaFromConfig(this.presetColumn).concat(this.getSchemaFromHtml(this.columnList));
if (customSchemaColumns.length === 0) { if (customSchemaColumns.length === 0) {
customSchemaColumns = this.getDefaultLayoutPreset(); customSchemaColumns = this.getDefaultLayoutPreset();
} }

View File

@ -36,6 +36,7 @@ export class AppConfigServiceMock extends AppConfigService {
load(): Promise<any> { load(): Promise<any> {
return new Promise((resolve) => { return new Promise((resolve) => {
this.onLoadSubject.next(this.config);
resolve(this.config); resolve(this.config);
}); });
} }

View File

@ -1,5 +1,4 @@
<div *ngIf="pagination?.hasMoreItems || isLoading" class="adf-infinite-pagination"> <div *ngIf="pagination?.hasMoreItems || isLoading" class="adf-infinite-pagination">
isLoading : {{isLoading}}
<button mat-button <button mat-button
*ngIf="!isLoading" *ngIf="!isLoading"
class="adf-infinite-pagination-load-more" class="adf-infinite-pagination-load-more"

View File

@ -27,7 +27,7 @@ import { PaginatedComponent } from './paginated-component.interface';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { PaginationComponentInterface } from './pagination-component.interface'; import { PaginationComponentInterface } from './pagination-component.interface';
import { PaginationModel } from '../models/pagination.model'; import { PaginationModel } from '../models/pagination.model';
import { UserPreferencesService } from '../services/user-preferences.service'; import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
@Component({ @Component({
selector: 'adf-infinite-pagination', selector: 'adf-infinite-pagination',
@ -73,11 +73,14 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio
this.paginationSubscription = this.target.pagination.subscribe((pagination) => { this.paginationSubscription = this.target.pagination.subscribe((pagination) => {
this.isLoading = false; this.isLoading = false;
this.pagination = pagination; this.pagination = pagination;
this.pageSize = this.pageSize || this.userPreferencesService.paginationSize;
this.cdr.detectChanges(); this.cdr.detectChanges();
}); });
} }
this.userPreferencesService.select(UserPreferenceValues.PaginationSize).subscribe((pagSize) => {
this.pageSize = this.pageSize || pagSize;
});
if (!this.pagination) { if (!this.pagination) {
this.pagination = InfinitePaginationComponent.DEFAULT_PAGINATION; this.pagination = InfinitePaginationComponent.DEFAULT_PAGINATION;
} }

View File

@ -95,7 +95,7 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
} }
if (!this.supportedPageSizes) { if (!this.supportedPageSizes) {
this.supportedPageSizes = this.userPreferencesService.getDefaultPageSizes(); this.supportedPageSizes = this.userPreferencesService.supportedPageSizes;
} }
if (this.target) { if (this.target) {

View File

@ -23,7 +23,7 @@ import {
SearchApi, SearchApi,
Node Node
} from '@alfresco/js-api'; } from '@alfresco/js-api';
import { AlfrescoApiCompatibility } from '@alfresco/js-api'; import { AlfrescoApiCompatibility, AlfrescoApiConfig } from '@alfresco/js-api';
import { AppConfigService, AppConfigValues } from '../app-config/app-config.service'; import { AppConfigService, AppConfigValues } from '../app-config/app-config.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
@ -42,6 +42,8 @@ export class AlfrescoApiService {
protected alfrescoApi: AlfrescoApiCompatibility; protected alfrescoApi: AlfrescoApiCompatibility;
lastConfig: AlfrescoApiConfig;
getInstance(): AlfrescoApiCompatibility { getInstance(): AlfrescoApiCompatibility {
return this.alfrescoApi; return this.alfrescoApi;
} }
@ -126,11 +128,16 @@ export class AlfrescoApiService {
oauth2: oauth oauth2: oauth
}; };
if (this.alfrescoApi) { if (this.alfrescoApi && this.isDifferentConfig(this.lastConfig, config)) {
this.lastConfig = config;
this.alfrescoApi.configureJsApi(config); this.alfrescoApi.configureJsApi(config);
} else { } else {
this.lastConfig = config;
this.alfrescoApi = new AlfrescoApiCompatibility(config); this.alfrescoApi = new AlfrescoApiCompatibility(config);
} }
} }
isDifferentConfig(lastConfig: AlfrescoApiConfig, newConfig: AlfrescoApiConfig) {
return JSON.stringify(lastConfig) !== JSON.stringify(newConfig);
}
} }

View File

@ -52,8 +52,11 @@ export class TranslationService {
} }
userPreferencesService.select(UserPreferenceValues.Locale).subscribe((locale) => { userPreferencesService.select(UserPreferenceValues.Locale).subscribe((locale) => {
if (locale) {
this.userLang = locale; this.userLang = locale;
this.use(this.userLang); }); this.use(this.userLang);
}
});
} }
/** /**

View File

@ -19,22 +19,25 @@ import { TestBed } from '@angular/core/testing';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { AppConfigService } from '../app-config/app-config.service'; import { AppConfigService } from '../app-config/app-config.service';
import { StorageService } from './storage.service'; import { StorageService } from './storage.service';
import { UserPreferencesService } from './user-preferences.service'; import { UserPreferencesService, UserPreferenceValues } from './user-preferences.service';
import { setupTestBed } from '../testing/setupTestBed'; import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module'; import { CoreTestingModule } from '../testing/core.testing.module';
import { AppConfigServiceMock } from '../mock/app-config.service.mock';
describe('UserPreferencesService', () => { describe('UserPreferencesService', () => {
const defaultPaginationSize: number = 25;
const supportedPaginationSize = [5, 10, 15, 20]; const supportedPaginationSize = [5, 10, 15, 20];
let preferences: UserPreferencesService; let preferences: UserPreferencesService;
let storage: StorageService; let storage: StorageService;
let appConfig: AppConfigService; let appConfig: AppConfigServiceMock;
let translate: TranslateService; let translate: TranslateService;
let changeDisposable: any; let changeDisposable: any;
setupTestBed({ setupTestBed({
imports: [CoreTestingModule] imports: [CoreTestingModule],
providers: [
{ provide: AppConfigService, useClass: AppConfigServiceMock }
]
}); });
beforeEach(() => { beforeEach(() => {
@ -56,13 +59,17 @@ describe('UserPreferencesService', () => {
} }
}); });
it('should get default pagination from app config', () => { it('should get default pagination from app config', (done) => {
appConfig.config.pagination.size = 0; appConfig.config.pagination.size = 0;
expect(preferences.defaults.paginationSize).toBe(defaultPaginationSize); appConfig.load().then(() => {
expect(preferences.paginationSize).toBe(0);
done();
});
}); });
it('should return supported page sizes defined in the app config', () => { it('should return supported page sizes defined in the app config', () => {
const supportedPages = preferences.getDefaultPageSizes(); const supportedPages = preferences.supportedPageSizes;
appConfig.load();
expect(supportedPages).toEqual(supportedPaginationSize); expect(supportedPages).toEqual(supportedPaginationSize);
}); });
@ -105,16 +112,6 @@ describe('UserPreferencesService', () => {
expect(storage.getItem(propertyKey)).toBe('valueA'); expect(storage.getItem(propertyKey)).toBe('valueA');
}); });
it('should store custom pagination settings for default prefix', () => {
preferences.paginationSize = 5;
expect(preferences.paginationSize).toBe(5);
});
it('should return default paginationSize value', () => {
preferences.set('PAGINATION_SIZE', 0);
expect(preferences.paginationSize).toBe(defaultPaginationSize);
});
it('should return as default locale the app.config locate as first', () => { it('should return as default locale the app.config locate as first', () => {
appConfig.config.locale = 'fake-locate-config'; appConfig.config.locale = 'fake-locate-config';
spyOn(translate, 'getBrowserCultureLang').and.returnValue('fake-locate-browser'); spyOn(translate, 'getBrowserCultureLang').and.returnValue('fake-locate-browser');
@ -141,7 +138,7 @@ describe('UserPreferencesService', () => {
it('should stream the page size value when is set', (done) => { it('should stream the page size value when is set', (done) => {
preferences.paginationSize = 5; preferences.paginationSize = 5;
changeDisposable = preferences.onChange.subscribe((userPreferenceStatus) => { changeDisposable = preferences.onChange.subscribe((userPreferenceStatus) => {
expect(userPreferenceStatus.PAGINATION_SIZE).toBe(5); expect(userPreferenceStatus[UserPreferenceValues.PaginationSize]).toBe(5);
done(); done();
}); });
}); });

View File

@ -23,8 +23,8 @@ import { StorageService } from './storage.service';
import { distinctUntilChanged, map } from 'rxjs/operators'; import { distinctUntilChanged, map } from 'rxjs/operators';
export enum UserPreferenceValues { export enum UserPreferenceValues {
PaginationSize = 'PAGINATION_SIZE', PaginationSize = 'paginationSize',
Locale = 'LOCALE', Locale = 'locale',
SupportedPageSizes = 'supportedPageSizes' SupportedPageSizes = 'supportedPageSizes'
} }
@ -52,9 +52,9 @@ export class UserPreferencesService {
} }
private initUserPreferenceStatus() { private initUserPreferenceStatus() {
this.userPreferenceStatus[UserPreferenceValues.Locale] = this.locale || this.getDefaultLocale(); this.set(UserPreferenceValues.Locale, (this.locale || this.getDefaultLocale()));
this.userPreferenceStatus[UserPreferenceValues.PaginationSize] = this.appConfig.get('pagination.size', this.defaults.paginationSize); this.set(UserPreferenceValues.PaginationSize, this.paginationSize);
this.userPreferenceStatus[UserPreferenceValues.SupportedPageSizes] = this.appConfig.get('pagination.supportedPageSizes', this.defaults.supportedPageSizes); this.set(UserPreferenceValues.SupportedPageSizes, JSON.stringify(this.supportedPageSizes));
} }
/** /**
@ -145,8 +145,18 @@ export class UserPreferencesService {
* Gets an array containing the available page sizes. * Gets an array containing the available page sizes.
* @returns Array of page size values * @returns Array of page size values
*/ */
getDefaultPageSizes(): number[] { get supportedPageSizes(): number[] {
return this.userPreferenceStatus[UserPreferenceValues.SupportedPageSizes]; let supportedPageSizes = this.get(UserPreferenceValues.SupportedPageSizes);
if (supportedPageSizes) {
return JSON.parse(supportedPageSizes);
} else {
return this.appConfig.get('pagination.supportedPageSizes', this.defaults.supportedPageSizes);
}
}
set supportedPageSizes(value: number[]) {
this.set(UserPreferenceValues.SupportedPageSizes, JSON.stringify(value));
} }
/** Pagination size. */ /** Pagination size. */
@ -155,12 +165,18 @@ export class UserPreferencesService {
} }
get paginationSize(): number { get paginationSize(): number {
return Number(this.get(UserPreferenceValues.PaginationSize, this.userPreferenceStatus[UserPreferenceValues.PaginationSize])) || this.defaults.paginationSize; let paginationSize = this.get(UserPreferenceValues.PaginationSize);
if (paginationSize) {
return Number(paginationSize);
} else {
return Number(this.appConfig.get('pagination.size', this.defaults.paginationSize));
}
} }
/** Current locale setting. */ /** Current locale setting. */
get locale(): string { get locale(): string {
return this.get(UserPreferenceValues.Locale, this.userPreferenceStatus[UserPreferenceValues.Locale]); return this.get(UserPreferenceValues.Locale);
} }
set locale(value: string) { set locale(value: string) {
@ -172,7 +188,7 @@ export class UserPreferencesService {
* @returns Default locale language code * @returns Default locale language code
*/ */
public getDefaultLocale(): string { public getDefaultLocale(): string {
return this.appConfig.get<string>('locale') || this.translate.getBrowserCultureLang() || 'en'; return this.appConfig.get<string>(UserPreferenceValues.Locale) || this.translate.getBrowserCultureLang() || 'en';
} }
} }

View File

@ -1,22 +0,0 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './components/process-list-cloud.component';
export * from './models/process-cloud-query-request.model';
export * from './models/process-cloud-preset.model';
export * from './models/process-list-sorting.model';
export * from './process-list-cloud.module';

View File

@ -6,7 +6,7 @@ const retry = require('protractor-retry').retry;
const AlfrescoApi = require('alfresco-js-api-node'); const AlfrescoApi = require('alfresco-js-api-node');
const TestConfig = require('./e2e/test.config'); const TestConfig = require('./e2e/test.config');
var argv = require('yargs').argv; let argv = require('yargs').argv;
const fs = require('fs'); const fs = require('fs');
const rimraf = require('rimraf'); const rimraf = require('rimraf');
@ -16,21 +16,22 @@ const projectRoot = path.resolve(__dirname);
const width = 1366; const width = 1366;
const height = 768; const height = 768;
var HOST = process.env.URL_HOST_ADF; let HOST = process.env.URL_HOST_ADF;
var BROWSER_RUN = process.env.BROWSER_RUN; let BROWSER_RUN = process.env.BROWSER_RUN;
var FOLDER = process.env.FOLDER || ''; let FOLDER = process.env.FOLDER || '';
var SELENIUM_SERVER = process.env.SELENIUM_SERVER || ''; let SELENIUM_SERVER = process.env.SELENIUM_SERVER || '';
var DIRECT_CONNECCT = SELENIUM_SERVER ? false : true; let DIRECT_CONNECCT = SELENIUM_SERVER ? false : true;
var MAXINSTANCES = process.env.MAXINSTANCES || 1; let MAXINSTANCES = process.env.MAXINSTANCES || 1;
var TIMEOUT = parseInt(process.env.TIMEOUT, 10); let TIMEOUT = parseInt(process.env.TIMEOUT, 10);
let SAVE_SCREENSHOT = (process.env.SAVE_SCREENSHOT == 'true');
var specsToRun = './**/' + FOLDER + '**/*.e2e.ts'; let specsToRun = './**/' + FOLDER + '**/*.e2e.ts';
if (process.env.NAME_TEST) { if (process.env.NAME_TEST) {
specsToRun = './e2e/**/' + process.env.NAME_TEST; specsToRun = './e2e/**/' + process.env.NAME_TEST;
} }
var args_options = []; let args_options = [];
if (BROWSER_RUN === 'true') { if (BROWSER_RUN === 'true') {
args_options = ['--incognito', '--window-size=1366,768', '--disable-gpu']; args_options = ['--incognito', '--window-size=1366,768', '--disable-gpu'];
@ -38,17 +39,112 @@ if (BROWSER_RUN === 'true') {
args_options = ['--incognito', '--headless', '--window-size=1366,768', '--disable-gpu']; args_options = ['--incognito', '--headless', '--window-size=1366,768', '--disable-gpu'];
} }
var downloadFolder = path.join(__dirname, 'e2e/downloads'); let downloadFolder = path.join(__dirname, 'e2e/downloads');
var buildNumber = () => { let buildNumber = () => {
let buildNumber = process.env.TRAVIS_BUILD_NUMBER; let buildNumber = process.env.TRAVIS_BUILD_NUMBER;
if (!buildNumber) { if (!buildNumber) {
process.env.TRAVIS_BUILD_NUMBER = Date.now(); process.env.TRAVIS_BUILD_NUMBER = Date.now();
} }
return process.env.TRAVIS_BUILD_NUMBER; return process.env.TRAVIS_BUILD_NUMBER;
};
saveScreenshots = async function (alfrescoJsApi, retryCount) {
let files = fs.readdirSync(path.join(__dirname, './e2e-output/screenshots'));
if (files && files.length > 0) {
let folder;
try {
folder = await alfrescoJsApi.nodes.addNode('-my-', {
'name': `retry-${retryCount}`,
'relativePath': `Builds/${buildNumber()}/screenshot`,
'nodeType': 'cm:folder'
}, {}, {
'overwrite': true
});
} catch (error) {
folder = await alfrescoJsApi.nodes.getNode('-my-', {
'relativePath': `Builds/${buildNumber()}/screenshot/retry-${retryCount}`,
'nodeType': 'cm:folder'
}, {}, {
'overwrite': true
});
} }
for (const fileName of files) {
let pathFile = path.join(__dirname, './e2e-output/screenshots', fileName);
let file = fs.createReadStream(pathFile);
let safeFileName = fileName.replace(new RegExp('"', 'g'), '');
try {
await alfrescoJsApi.upload.uploadFile(
file,
'',
folder.entry.id,
null,
{
'name': safeFileName,
'nodeType': 'cm:content',
'autoRename': true
}
);
}catch(error){
console.log(error);
}
}
}
};
saveReport = async function (filenameReport, alfrescoJsApi) {
let pathFile = path.join(__dirname, './e2e-output/junit-report/html', filenameReport + '.html');
let reportFile = fs.createReadStream(pathFile);
let reportFolder;
try {
reportFolder = await alfrescoJsApi.nodes.addNode('-my-', {
'name': 'report',
'relativePath': `Builds/${buildNumber()}`,
'nodeType': 'cm:folder'
}, {}, {
'overwrite': true
});
} catch (error) {
reportFolder = await alfrescoJsApi.nodes.getNode('-my-', {
'relativePath': `Builds/${buildNumber()}/report`,
'nodeType': 'cm:folder'
}, {}, {
'overwrite': true
});
}
try {
await
alfrescoJsApi.upload.uploadFile(
reportFile,
'',
reportFolder.entry.id,
null,
{
'name': reportFile.name,
'nodeType': 'cm:content',
'autoRename': true
}
);
} catch (error) {
console.log('error' + error);
}
};
exports.config = { exports.config = {
allScriptsTimeout: TIMEOUT, allScriptsTimeout: TIMEOUT,
@ -117,8 +213,8 @@ exports.config = {
browser.manage().window().setSize(width, height); browser.manage().window().setSize(width, height);
jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true}})); jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true}}));
var generatedSuiteName = Math.random().toString(36).substr(2, 5); let generatedSuiteName = Math.random().toString(36).substr(2, 5);
var junitReporter = new jasmineReporters.JUnitXmlReporter({ let junitReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: true, consolidateAll: true,
savePath: `${projectRoot}/e2e-output/junit-report`, savePath: `${projectRoot}/e2e-output/junit-report`,
filePrefix: 'results.xml-' + generatedSuiteName, filePrefix: 'results.xml-' + generatedSuiteName,
@ -128,7 +224,7 @@ exports.config = {
return browser.driver.executeScript(disableCSSAnimation); return browser.driver.executeScript(disableCSSAnimation);
function disableCSSAnimation() { function disableCSSAnimation() {
var css = '* {' + let css = '* {' +
'-webkit-transition-duration: 0s !important;' + '-webkit-transition-duration: 0s !important;' +
'transition-duration: 0s !important;' + 'transition-duration: 0s !important;' +
'-webkit-animation-duration: 0s !important;' + '-webkit-animation-duration: 0s !important;' +
@ -145,7 +241,7 @@ exports.config = {
}, },
beforeLaunch: function () { beforeLaunch: function () {
var reportsFolder = `${projectRoot}/e2e-output/junit-report/`; let reportsFolder = `${projectRoot}/e2e-output/junit-report/`;
fs.exists(reportsFolder, function (exists, error) { fs.exists(reportsFolder, function (exists, error) {
if (exists) { if (exists) {
@ -162,18 +258,14 @@ exports.config = {
afterLaunch: async function () { afterLaunch: async function () {
let saveScreenshot = process.env.SAVE_SCREENSHOT; if (SAVE_SCREENSHOT) {
let retryCount = 1;
if (saveScreenshot) {
var retryCount = 1;
if (argv.retry) { if (argv.retry) {
retryCount = ++argv.retry; retryCount = ++argv.retry;
} }
let filenameReport = `ProtractorTestReport-${FOLDER.replace('/', '')}-${retryCount}`; let filenameReport = `ProtractorTestReport-${FOLDER.replace('/', '')}-${retryCount}`;
console.log(filenameReport);
let output = ''; let output = '';
let savePath = `${projectRoot}/e2e-output/junit-report/`; let savePath = `${projectRoot}/e2e-output/junit-report/`;
let temporaryHtmlPath = savePath + 'html/temporaryHtml/'; let temporaryHtmlPath = savePath + 'html/temporaryHtml/';
@ -195,16 +287,14 @@ exports.config = {
lastFileName = testConfigReport.outputFilename; lastFileName = testConfigReport.outputFilename;
} }
} }
;
var lastHtmlFile = temporaryHtmlPath + lastFileName + '.html'; let lastHtmlFile = temporaryHtmlPath + lastFileName + '.html';
if (!(fs.lstatSync(lastHtmlFile).isDirectory())) { if (!(fs.lstatSync(lastHtmlFile).isDirectory())) {
output = output + fs.readFileSync(lastHtmlFile); output = output + fs.readFileSync(lastHtmlFile);
} }
;
var fileName = savePath + 'html/' + filenameReport + '.html'; let fileName = savePath + 'html/' + filenameReport + '.html';
fs.writeFileSync(fileName, output, 'utf8'); fs.writeFileSync(fileName, output, 'utf8');
@ -214,107 +304,18 @@ exports.config = {
}); });
alfrescoJsApi.login(TestConfig.adf.adminEmail, TestConfig.adf.adminPassword); alfrescoJsApi.login(TestConfig.adf.adminEmail, TestConfig.adf.adminPassword);
if (saveScreenshot === 'true') { await saveScreenshots(alfrescoJsApi, retryCount);
let files = fs.readdirSync(path.join(__dirname, './e2e-output/screenshots')); await saveReport(filenameReport, alfrescoJsApi);
if (files && files.length > 0) {
try {
folder = await
alfrescoJsApi.nodes.addNode('-my-', {
'name': `retry-${retryCount}`,
'relativePath': `Builds/${buildNumber()}/screenshot`,
'nodeType': 'cm:folder'
}, {}, {
'overwrite': true
});
} catch (error) {
folder = await
alfrescoJsApi.nodes.getNode('-my-', {
'relativePath': `Builds/${buildNumber()}/screenshot/retry-${retryCount}`,
'nodeType': 'cm:folder'
}, {}, {
'overwrite': true
});
}
for (const fileName of files) {
let pathFile = path.join(__dirname, './e2e-output/screenshots', fileName);
let file = fs.createReadStream(pathFile);
await
alfrescoJsApi.upload.uploadFile(
file,
'',
folder.entry.id,
null,
{
'name': file.name,
'nodeType': 'cm:content',
'autoRename': true
}
);
}
}
}
let pathFile = path.join(__dirname, './e2e-output/junit-report/html', filenameReport + '.html');
let reportFile = fs.createReadStream(pathFile);
let reportFolder;
try {
reportFolder = await
alfrescoJsApi.nodes.addNode('-my-', {
'name': 'report',
'relativePath': `Builds/${buildNumber()}`,
'nodeType': 'cm:folder'
}, {}, {
'overwrite': true
});
} catch (error) {
reportFolder = await
alfrescoJsApi.nodes.getNode('-my-', {
'relativePath': `Builds/${buildNumber()}/report`,
'nodeType': 'cm:folder'
}, {}, {
'overwrite': true
});
}
try {
await
alfrescoJsApi.upload.uploadFile(
reportFile,
'',
reportFolder.entry.id,
null,
{
'name': reportFile.name,
'nodeType': 'cm:content',
'autoRename': true
}
);
} catch (error) {
console.log('error' + error);
}
if (saveScreenshot === 'true') {
rimraf(`${projectRoot}/e2e-output/screenshots/`, function () { rimraf(`${projectRoot}/e2e-output/screenshots/`, function () {
console.log('done delete screenshot'); console.log('done delete screenshot');
}); });
}
} }
return retry.afterLaunch(3); return retry.afterLaunch(3);
} }
}; };