alfresco-ng2-components/lib/core/services/card-view-update.service.spec.ts
Popovics András 4b76e6b4a9 [ADF-1841] Content Metadata first iteration (#2666)
* First try

* Small layout changes

* Add pipe support for CardViewTextItemModel

* property service

* Additional stuff

* Make CardViewUpdateService smarter

* Content metadata saving

* Rebase fix

* CardView Style fixes

* Fix core and content-services tests

* Fix CardView text item update UX
2017-11-18 10:43:39 +00:00

95 lines
3.2 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 { async, TestBed } from '@angular/core/testing';
import { CardViewBaseItemModel } from '../models/card-view-baseitem.model';
import { CardViewUpdateService, transformKeyToObject } from './card-view-update.service';
describe('CardViewUpdateService', () => {
describe('transformKeyToObject', () => {
it('should return the proper constructed value object for "dotless" keys', () => {
const valueObject = transformKeyToObject('property-key', 'property-value');
expect(valueObject).toEqual({
'property-key': 'property-value'
});
});
it('should return the proper constructed value object for dot contained keys', () => {
const valueObject = transformKeyToObject('level:0.level:1.level:2.level:3', 'property-value');
expect(valueObject).toEqual({
'level:0': {
'level:1': {
'level:2': {
'level:3': 'property-value'
}
}
}
});
});
});
describe('Service', () => {
let cardViewUpdateService: CardViewUpdateService;
const property: CardViewBaseItemModel = <CardViewBaseItemModel> {
label: 'property-label',
value: 'property-value',
key: 'property-key',
default: 'property-default',
editable: false,
clickable: false
};
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
CardViewUpdateService
]
}).compileComponents();
}));
beforeEach(() => {
cardViewUpdateService = TestBed.get(CardViewUpdateService);
});
it('should send updated message with proper parameters', async(() => {
cardViewUpdateService.itemUpdated$.subscribe(
( { target, changed } ) => {
expect(target).toBe(property);
expect(changed).toEqual({ 'property-key': 'changed-property-value' });
}
);
cardViewUpdateService.update(property, 'changed-property-value');
}));
it('should send clicked message with proper parameters', async(() => {
cardViewUpdateService.itemClicked$.subscribe(
( { target } ) => {
expect(target).toBe(property);
}
);
cardViewUpdateService.clicked(property);
}));
});
});