mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
[ACA-1956] Library - metadata info (#760)
* library metadata panel * add infoDrawer component to Library * set infoDrawer state to false onDestroy * infoDrawer action * update actions index * infoDrawer set state reducer * register Library metadata component to extensions * filter infoDrawer tabs * update library api * library actions and effects * refresh library view on update event * infoDrawer tests * refactor * check permission on update * check permission on update * lint * reference selection library * add parameter type * full width
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { LibraryMetadataFormComponent } from './library-metadata-form.component';
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { UpdateLibraryAction } from '../../../store/actions';
|
||||
import { AppTestingModule } from '../../../testing/app-testing.module';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { Site, SiteBody } from 'alfresco-js-api';
|
||||
|
||||
describe('LibraryMetadataFormComponent', () => {
|
||||
let fixture: ComponentFixture<LibraryMetadataFormComponent>;
|
||||
let component: LibraryMetadataFormComponent;
|
||||
const storeMock = {
|
||||
dispatch: jasmine.createSpy('dispatch')
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [AppTestingModule],
|
||||
declarations: [LibraryMetadataFormComponent],
|
||||
providers: [{ provide: Store, useValue: storeMock }],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(LibraryMetadataFormComponent);
|
||||
component = fixture.componentInstance;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
storeMock.dispatch.calls.reset();
|
||||
});
|
||||
|
||||
it('should initialize form with node data', () => {
|
||||
const siteEntryModel = {
|
||||
title: 'libraryTitle',
|
||||
description: 'description',
|
||||
visibility: 'PRIVATE'
|
||||
};
|
||||
component.node = {
|
||||
entry: <Site>{
|
||||
id: 'libraryId',
|
||||
...siteEntryModel
|
||||
}
|
||||
};
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.form.value).toEqual(siteEntryModel);
|
||||
});
|
||||
|
||||
it('should update form data when node data changes', () => {
|
||||
const siteEntryModel = {
|
||||
title: 'libraryTitle',
|
||||
description: 'description',
|
||||
visibility: 'PRIVATE'
|
||||
};
|
||||
|
||||
const newSiteEntryModel = {
|
||||
title: 'libraryTitle2',
|
||||
description: 'description2',
|
||||
visibility: 'PUBLIC'
|
||||
};
|
||||
|
||||
component.node = {
|
||||
entry: <Site>{
|
||||
id: 'libraryId',
|
||||
...siteEntryModel
|
||||
}
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.form.value).toEqual(siteEntryModel);
|
||||
|
||||
component.node = {
|
||||
entry: <Site>{
|
||||
id: 'libraryId',
|
||||
...newSiteEntryModel
|
||||
}
|
||||
};
|
||||
|
||||
component.ngOnChanges();
|
||||
|
||||
expect(component.form.value).toEqual(newSiteEntryModel);
|
||||
});
|
||||
|
||||
it('should update library node if form is valid', () => {
|
||||
const siteEntryModel = {
|
||||
title: 'libraryTitle',
|
||||
description: 'description',
|
||||
visibility: 'PRIVATE'
|
||||
};
|
||||
component.node = {
|
||||
entry: <Site>{
|
||||
id: 'libraryId',
|
||||
role: 'SiteManager',
|
||||
...siteEntryModel
|
||||
}
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
component.update();
|
||||
|
||||
expect(storeMock.dispatch).toHaveBeenCalledWith(
|
||||
new UpdateLibraryAction(<SiteBody>siteEntryModel)
|
||||
);
|
||||
});
|
||||
|
||||
it('should not update library node if it has no permission', () => {
|
||||
const siteEntryModel = {
|
||||
title: 'libraryTitle',
|
||||
description: 'description',
|
||||
visibility: 'PRIVATE'
|
||||
};
|
||||
component.node = {
|
||||
entry: <Site>{
|
||||
id: 'libraryId',
|
||||
role: 'Consumer',
|
||||
...siteEntryModel
|
||||
}
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
component.update();
|
||||
|
||||
expect(storeMock.dispatch).not.toHaveBeenCalledWith(
|
||||
new UpdateLibraryAction(<SiteBody>siteEntryModel)
|
||||
);
|
||||
});
|
||||
|
||||
it('should not update library node if form is invalid', () => {
|
||||
const siteEntryModel = {
|
||||
title: 'libraryTitle',
|
||||
description: 'description',
|
||||
visibility: 'PRIVATE'
|
||||
};
|
||||
component.node = {
|
||||
entry: <Site>{
|
||||
id: 'libraryId',
|
||||
role: 'SiteManager',
|
||||
...siteEntryModel
|
||||
}
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
component.form.controls['title'].setErrors({ maxlength: true });
|
||||
|
||||
component.update();
|
||||
|
||||
expect(storeMock.dispatch).not.toHaveBeenCalledWith(
|
||||
new UpdateLibraryAction(<SiteBody>siteEntryModel)
|
||||
);
|
||||
});
|
||||
|
||||
it('should toggle edit mode', () => {
|
||||
component.edit = false;
|
||||
|
||||
component.toggleEdit();
|
||||
expect(component.edit).toBe(true);
|
||||
|
||||
component.toggleEdit();
|
||||
expect(component.edit).toBe(false);
|
||||
});
|
||||
|
||||
it('should cancel from changes', () => {
|
||||
const siteEntryModel = {
|
||||
title: 'libraryTitle',
|
||||
description: 'description',
|
||||
visibility: 'PRIVATE'
|
||||
};
|
||||
component.node = {
|
||||
entry: <Site>{
|
||||
id: 'libraryId',
|
||||
...siteEntryModel
|
||||
}
|
||||
};
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.form.value).toEqual(siteEntryModel);
|
||||
|
||||
component.form.controls.title.setValue('libraryTitle-edit');
|
||||
|
||||
expect(component.form.value.title).toBe('libraryTitle-edit');
|
||||
|
||||
component.cancel();
|
||||
|
||||
expect(component.form.value).toEqual(siteEntryModel);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user