Popovics András 783f7f0497 [ADF-1986] Content matadata editing phase II. (#2796)
* Aspects collection

* Fetch only those metadata aspects which are defined in the application config

* Aspect property filtering first round

* Addig wildcard support for preset, default preset fallback to wildcard, and logging

* Add white list service

* Renaming services

* ContentMetadataService and CardViewItemDispatcherComponent update

* Observables... Observables everywhere...

* Propers CardViewAspect

* Defining more interfaces

* Dummy data and expansions panels

* Fix build attempt & proper panel expansion

* Folder restructuring

* Add different type mappings

* Restructuring Card view component

* Fix build

* More ECM types supported

* Validators first phase, extraction of interfaces, world domination preparation

* Validators phase II.

* Integer and float validators

* Hide empty text items and validation message foundation

* Validation error messages for text item view, small style changes

* Update date item

* bool item component

* Datetimepicker npm module

* Datetime model

* Add mapping for datetime

* Small fixes

* Passing down preset

* Adding forgotten package.json entry

* Adding some tests for wrapper card component

* content-metadata.component tests

* Covering some edge cases, adding some tests

* Fix cardview component's test

* Add datetimepicker to demoshell

* card view component show empty values by default

* displayEmpty dependency injection

* remove table like design from cardview

* Using alfresco-js-api instead of spike

* Remove spike folder and contents

* Fix test

* Cardview updated docs

* Content metadata md

* Fix review issues

* Fix the packagr issue
2018-01-11 12:31:22 +00:00

244 lines
9.5 KiB
TypeScript

/*!
* @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 { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { MaterialModule } from '../../../material.module';
import { MatCheckboxChange, MatCheckbox } from '@angular/material';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { AppConfigService } from '../../../app-config/app-config.service';
import { CardViewUpdateService } from '../../services/card-view-update.service';
import { LogService } from '../../../services/log.service';
import { TranslateLoaderService } from '../../../services/translate-loader.service';
import { CardViewBoolItemComponent } from './card-view-boolitem.component';
import { CardViewBoolItemModel } from '../../models/card-view-boolitem.model';
describe('CardViewBoolItemComponent', () => {
let fixture: ComponentFixture<CardViewBoolItemComponent>;
let component: CardViewBoolItemComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
FormsModule,
NoopAnimationsModule,
MaterialModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
declarations: [
CardViewBoolItemComponent
],
providers: [
AppConfigService,
CardViewUpdateService,
LogService
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CardViewBoolItemComponent);
component = fixture.componentInstance;
component.property = new CardViewBoolItemModel({
label: 'Boolean label',
value: true,
key: 'boolkey',
default: false,
editable: false
});
});
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
describe('Rendering', () => {
it('should render the label and value if the property is editable', () => {
component.editable = true;
component.property.editable = true;
fixture.detectChanges();
let label = fixture.debugElement.query(By.css('.adf-property-label'));
expect(label).not.toBeNull();
expect(label.nativeElement.innerText).toBe('Boolean label');
let value = fixture.debugElement.query(By.css('.adf-property-value'));
expect(value).not.toBeNull();
});
it('should NOT render the label and value if the property is NOT editable and doesn\'t have a proper boolean value set' , () => {
component.editable = true;
component.property.value = undefined;
component.property.editable = false;
fixture.detectChanges();
let label = fixture.debugElement.query(By.css('.adf-property-label'));
expect(label).toBeNull();
let value = fixture.debugElement.query(By.css('.adf-property-value'));
expect(value).toBeNull();
});
it('should render the label and value if the property is NOT editable but has a proper boolean value set' , () => {
component.editable = true;
component.property.value = false;
component.property.editable = false;
fixture.detectChanges();
let label = fixture.debugElement.query(By.css('.adf-property-label'));
expect(label).not.toBeNull();
let value = fixture.debugElement.query(By.css('.adf-property-value'));
expect(value).not.toBeNull();
});
it('should render ticked checkbox if property\'s value is true', () => {
component.property.value = true;
fixture.detectChanges();
let value = fixture.debugElement.query(By.css('.adf-property-value input[type="checkbox"]'));
expect(value).not.toBeNull();
expect(value.nativeElement.checked).toBe(true);
});
it('should render ticked checkbox if property\'s value is not set but default is true and editable', () => {
component.editable = true;
component.property.editable = true;
component.property.value = undefined;
component.property.default = true;
fixture.detectChanges();
let value = fixture.debugElement.query(By.css('.adf-property-value input[type="checkbox"]'));
expect(value).not.toBeNull();
expect(value.nativeElement.checked).toBe(true);
});
it('should render unticked checkbox if property\'s value is false', () => {
component.property.value = false;
fixture.detectChanges();
let value = fixture.debugElement.query(By.css('.adf-property-value input[type="checkbox"]'));
expect(value).not.toBeNull();
expect(value.nativeElement.checked).toBe(false);
});
it('should render unticked checkbox if property\'s value is not set but default is false and editable', () => {
component.editable = true;
component.property.editable = true;
component.property.value = undefined;
component.property.default = false;
fixture.detectChanges();
let value = fixture.debugElement.query(By.css('.adf-property-value input[type="checkbox"]'));
expect(value).not.toBeNull();
expect(value.nativeElement.checked).toBe(false);
});
it('should render enabled checkbox if property and component are both editable', () => {
component.editable = true;
component.property.editable = true;
component.property.value = true;
fixture.detectChanges();
let value = fixture.debugElement.query(By.css('.adf-property-value input[type="checkbox"]'));
expect(value).not.toBeNull();
expect(value.nativeElement.hasAttribute('disabled')).toBe(false);
});
it('should render disabled checkbox if property is not editable', () => {
component.editable = true;
component.property.editable = false;
component.property.value = true;
fixture.detectChanges();
let value = fixture.debugElement.query(By.css('.adf-property-value input[type="checkbox"]'));
expect(value).not.toBeNull();
expect(value.nativeElement.hasAttribute('disabled')).toBe(true);
});
it('should render disabled checkbox if component is not editable', () => {
component.editable = false;
component.property.editable = true;
component.property.value = true;
fixture.detectChanges();
let value = fixture.debugElement.query(By.css('.adf-property-value input[type="checkbox"]'));
expect(value).not.toBeNull();
expect(value.nativeElement.hasAttribute('disabled')).toBe(true);
});
});
describe('Update', () => {
beforeEach(() => {
component.editable = true;
component.property.editable = true;
component.property.value = undefined;
fixture.detectChanges();
});
it('should trigger the update event when changing the checkbox', () => {
const cardViewUpdateService = TestBed.get(CardViewUpdateService);
spyOn(cardViewUpdateService, 'update');
component.changed(<MatCheckboxChange> {checked: true});
expect(cardViewUpdateService.update).toHaveBeenCalledWith(component.property, true);
});
it('should update the propery\'s value after a changed', async(() => {
component.property.value = true;
component.changed(<MatCheckboxChange> {checked: false});
fixture.whenStable().then(() => {
expect(component.property.value).toBe(false);
});
}));
it('should trigger an update event on the CardViewUpdateService [integration]', (done) => {
const cardViewUpdateService = TestBed.get(CardViewUpdateService);
component.property.value = false;
fixture.detectChanges();
cardViewUpdateService.itemUpdated$.subscribe(
(updateNotification) => {
expect(updateNotification.target).toBe(component.property);
expect(updateNotification.changed).toEqual({ boolkey: true });
done();
}
);
const labelElement = fixture.debugElement.query(By.directive(MatCheckbox)).nativeElement.querySelector('label');
labelElement.click();
});
});
});