mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3442] create library dialog (#4018)
* library dialog * integrate with demo shell * update resources * fix license * auto focus for the first input * update e2e tests * try close the dialog between tests * fix afterEach * Revert "try close the dialog between tests" This reverts commit 63464f2b03c226c606d09b18c7d2782e3bb52c0a. * update code due to css lint issues * csslint settings for vs code * missing import lint fix remove not used import convert errorPage js to ts convert tasklistpage js to ts fix redirection creation folder in root fix lint issue fix e2e * e2e fix * fix PS tests * navigation import * fix tests tooltip convert paginapage to ts * fix lint * fix lock files e2e filterspage to ts * fix lint * fix cs cre git dept 3 and not 50 as default in travis * quiet log git download * add some delay and change the delete lock * fix node entry * convert searchDialog to typescript parallel protractor * disable browser execute * restote test * change search tests * move search in a separate e2e folder * experiment fix e2e * change util presence change protractor conf * fix unshare test * improve query viewerPage using css over xpath * waitForAngularEnabled before browser redirect * convert util to ts and more * convert other files to ts * convert to ts other files * trigger build * function fixes use arrow function * process service fixes * lint fix review timeout default * fix failing tests * restore timeout * share dialog fix * remove * use configuration admin * fix APS 2 login sso
This commit is contained in:
committed by
Eugenio Romano
parent
9fd564a78e
commit
058d23d57f
198
lib/content-services/dialogs/library/library.dialog.spec.ts
Normal file
198
lib/content-services/dialogs/library/library.dialog.spec.ts
Normal file
@@ -0,0 +1,198 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { CoreModule } from '@alfresco/adf-core';
|
||||
import { LibraryDialogComponent } from './library.dialog';
|
||||
import { TestBed, fakeAsync, tick, flush } from '@angular/core/testing';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { MatDialogRef } from '@angular/material';
|
||||
import {
|
||||
AlfrescoApiService,
|
||||
AlfrescoApiServiceMock,
|
||||
setupTestBed
|
||||
} from '@alfresco/adf-core';
|
||||
|
||||
describe('LibraryDialogComponent', () => {
|
||||
let fixture;
|
||||
let component;
|
||||
let alfrescoApi;
|
||||
const dialogRef = {
|
||||
close: jasmine.createSpy('close')
|
||||
};
|
||||
|
||||
setupTestBed({
|
||||
imports: [NoopAnimationsModule, CoreModule, ReactiveFormsModule],
|
||||
declarations: [LibraryDialogComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: AlfrescoApiService,
|
||||
useClass: AlfrescoApiServiceMock
|
||||
},
|
||||
{ provide: MatDialogRef, useValue: dialogRef }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(LibraryDialogComponent);
|
||||
component = fixture.componentInstance;
|
||||
alfrescoApi = TestBed.get(AlfrescoApiService);
|
||||
|
||||
spyOn(
|
||||
alfrescoApi.getInstance().core.queriesApi,
|
||||
'findSites'
|
||||
).and.returnValue(
|
||||
Promise.resolve({
|
||||
list: { entries: [] }
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('should set library id automatically on title input', fakeAsync(() => {
|
||||
spyOn(alfrescoApi.sitesApi, 'getSite').and.callFake(() => {
|
||||
return new Promise((resolve, reject) => reject());
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
component.form.controls.title.setValue('libraryTitle');
|
||||
tick(500);
|
||||
flush();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.form.controls.id.value).toBe('libraryTitle');
|
||||
}));
|
||||
|
||||
it('should translate library title space character to dash for library id', fakeAsync(() => {
|
||||
spyOn(alfrescoApi.sitesApi, 'getSite').and.callFake(() => {
|
||||
return new Promise((resolve, reject) => reject());
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
component.form.controls.title.setValue('library title');
|
||||
tick(500);
|
||||
flush();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.form.controls.id.value).toBe('library-title');
|
||||
}));
|
||||
|
||||
it('should not change custom library id on title input', fakeAsync(() => {
|
||||
spyOn(alfrescoApi.sitesApi, 'getSite').and.callFake(() => {
|
||||
return new Promise((resolve, reject) => reject());
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
component.form.controls.id.setValue('custom-id');
|
||||
component.form.controls.id.markAsDirty();
|
||||
tick(500);
|
||||
flush();
|
||||
fixture.detectChanges();
|
||||
|
||||
component.form.controls.title.setValue('library title');
|
||||
tick(500);
|
||||
flush();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.form.controls.id.value).toBe('custom-id');
|
||||
}));
|
||||
|
||||
it('should invalidate form when library id already exists', fakeAsync(() => {
|
||||
spyOn(alfrescoApi.sitesApi, 'getSite').and.returnValue(Promise.resolve());
|
||||
|
||||
fixture.detectChanges();
|
||||
component.form.controls.id.setValue('existingLibrary');
|
||||
tick(500);
|
||||
flush();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.form.controls.id.errors).toEqual({
|
||||
message: 'LIBRARY.ERRORS.EXISTENT_SITE'
|
||||
});
|
||||
expect(component.form.valid).toBe(false);
|
||||
}));
|
||||
|
||||
it('should create site when form is valid', fakeAsync(() => {
|
||||
spyOn(alfrescoApi.sitesApi, 'createSite').and.returnValue(
|
||||
Promise.resolve()
|
||||
);
|
||||
spyOn(alfrescoApi.sitesApi, 'getSite').and.callFake(() => {
|
||||
return new Promise((resolve, reject) => reject());
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
component.form.controls.title.setValue('library title');
|
||||
tick(500);
|
||||
flush();
|
||||
fixture.detectChanges();
|
||||
|
||||
component.submit();
|
||||
fixture.detectChanges();
|
||||
flush();
|
||||
|
||||
expect(alfrescoApi.sitesApi.createSite).toHaveBeenCalledWith({
|
||||
id: 'library-title',
|
||||
title: 'library title',
|
||||
description: '',
|
||||
visibility: 'PUBLIC'
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not create site when form is invalid', fakeAsync(() => {
|
||||
spyOn(alfrescoApi.sitesApi, 'createSite').and.returnValue(
|
||||
Promise.resolve({})
|
||||
);
|
||||
spyOn(alfrescoApi.sitesApi, 'getSite').and.returnValue(Promise.resolve());
|
||||
|
||||
fixture.detectChanges();
|
||||
component.form.controls.title.setValue('existingLibrary');
|
||||
tick(500);
|
||||
flush();
|
||||
fixture.detectChanges();
|
||||
|
||||
component.submit();
|
||||
fixture.detectChanges();
|
||||
flush();
|
||||
|
||||
expect(alfrescoApi.sitesApi.createSite).not.toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should notify on 409 conflict error (might be in trash)', fakeAsync(() => {
|
||||
const error = { message: '{ "error": { "statusCode": 409 } }' };
|
||||
spyOn(alfrescoApi.sitesApi, 'createSite').and.callFake(() => {
|
||||
return new Promise((resolve, reject) => reject(error));
|
||||
});
|
||||
spyOn(alfrescoApi.sitesApi, 'getSite').and.callFake(() => {
|
||||
return new Promise((resolve, reject) => reject());
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
component.form.controls.title.setValue('test');
|
||||
tick(500);
|
||||
flush();
|
||||
fixture.detectChanges();
|
||||
|
||||
component.submit();
|
||||
fixture.detectChanges();
|
||||
flush();
|
||||
|
||||
expect(component.form.controls.id.errors).toEqual({
|
||||
message: 'LIBRARY.ERRORS.CONFLICT'
|
||||
});
|
||||
}));
|
||||
});
|
Reference in New Issue
Block a user