[ADF-4522] Metadata value is not rolled back upon error (#5550)

* * initial commit

* * removed breaking change

* * fixed ts

* * fixed minor changes

* * fixed changes

* * minor changes

* * fixed unit test

* * docs added

* * fixed date clear problem

* * fixed unit test
This commit is contained in:
dhrn
2020-03-17 16:17:08 +05:30
committed by GitHub
parent becf45d150
commit d720d36670
18 changed files with 191 additions and 65 deletions

View File

@@ -265,7 +265,7 @@ describe('CardViewTextItemComponent', () => {
fixture.detectChanges();
const disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe((updateNotification) => {
expect(updateNotification.target).toBe(component.property);
expect(updateNotification.target).toEqual({ ...component.property });
expect(updateNotification.changed).toEqual({ textkey: expectedText });
disposableUpdate.unsubscribe();
});
@@ -309,10 +309,11 @@ describe('CardViewTextItemComponent', () => {
const cardViewUpdateService = TestBed.get(CardViewUpdateService);
spyOn(cardViewUpdateService, 'update');
component.editedValue = 'updated-value';
const property = { ...component.property };
component.update(event);
expect(cardViewUpdateService.update).toHaveBeenCalledWith(component.property, 'updated-value');
expect(cardViewUpdateService.update).toHaveBeenCalledWith(property, 'updated-value');
});
it('should NOT trigger the update event if the editedValue is invalid', () => {
@@ -384,7 +385,7 @@ describe('CardViewTextItemComponent', () => {
const disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe(
(updateNotification) => {
expect(updateNotification.target).toBe(component.property);
expect(updateNotification.target).toEqual({ ...component.property });
expect(updateNotification.changed).toEqual({ textkey: expectedText });
disposableUpdate.unsubscribe();
done();
@@ -413,7 +414,7 @@ describe('CardViewTextItemComponent', () => {
const disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe(
(updateNotification) => {
expect(updateNotification.target).toBe(component.property);
expect(updateNotification.target).toEqual({ ...component.property });
expect(updateNotification.changed).toEqual({ textkey: expectedText });
disposableUpdate.unsubscribe();
}
@@ -437,6 +438,24 @@ describe('CardViewTextItemComponent', () => {
expect(component.property.value).toBe(expectedText);
}));
it('should update the value using the updateItem$ subject', async(() => {
component.inEdit = false;
component.property.isValid = () => true;
const cardViewUpdateService = TestBed.get(CardViewUpdateService);
const expectedText = 'changed text';
fixture.detectChanges();
const textItemReadOnly = fixture.debugElement.query(By.css(`[data-automation-id="card-textitem-value-${component.property.key}"]`));
expect(textItemReadOnly.nativeElement.textContent).toEqual('Lorem ipsum');
expect(component.property.value).toBe('Lorem ipsum');
cardViewUpdateService.updateElement({ key: component.property.key, value: expectedText });
fixture.detectChanges();
expect(textItemReadOnly.nativeElement.textContent).toEqual(expectedText);
expect(component.property.value).toBe(expectedText);
}));
it('should reset the value using the escape key', async(() => {
component.inEdit = false;
component.property.isValid = () => true;
@@ -488,7 +507,7 @@ describe('CardViewTextItemComponent', () => {
fixture.detectChanges();
const disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe((updateNotification) => {
expect(updateNotification.target).toBe(component.property);
expect(updateNotification.target).toEqual({ ...component.property });
expect(updateNotification.changed).toEqual({ textkey: expectedText });
disposableUpdate.unsubscribe();
});
@@ -625,7 +644,7 @@ describe('CardViewTextItemComponent', () => {
expect(component.property.value).not.toEqual(expectedNumber);
const disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe((updateNotification) => {
expect(updateNotification.target).toBe(component.property);
expect(updateNotification.target).toEqual({ ...component.property });
expect(updateNotification.changed).toEqual({ textkey: expectedNumber.toString() });
disposableUpdate.unsubscribe();
});
@@ -699,7 +718,7 @@ describe('CardViewTextItemComponent', () => {
fixture.detectChanges();
const disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe((updateNotification) => {
expect(updateNotification.target).toBe(component.property);
expect(updateNotification.target).toEqual({ ...component.property });
expect(updateNotification.changed).toEqual({ textkey: expectedFloat.toString() });
disposableUpdate.unsubscribe();
});

View File

@@ -19,19 +19,17 @@ import { Component, Input, OnChanges, ViewChild } from '@angular/core';
import { CardViewTextItemModel } from '../../models/card-view-textitem.model';
import { CardViewUpdateService } from '../../services/card-view-update.service';
import { AppConfigService } from '../../../app-config/app-config.service';
import { BaseCardView } from '../base-card-view';
@Component({
selector: 'adf-card-view-textitem',
templateUrl: './card-view-textitem.component.html',
styleUrls: ['./card-view-textitem.component.scss']
})
export class CardViewTextItemComponent implements OnChanges {
export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemModel> implements OnChanges {
static DEFAULT_SEPARATOR = ', ';
@Input()
property: CardViewTextItemModel;
@Input()
editable: boolean = false;
@@ -46,8 +44,9 @@ export class CardViewTextItemComponent implements OnChanges {
errorMessages: string[];
valueSeparator: string;
constructor(private cardViewUpdateService: CardViewUpdateService,
constructor(cardViewUpdateService: CardViewUpdateService,
private appConfig: AppConfigService) {
super(cardViewUpdateService);
this.valueSeparator = this.appConfig.get<string>('content-metadata.multi-value-pipe-separator') || CardViewTextItemComponent.DEFAULT_SEPARATOR;
}
@@ -105,7 +104,7 @@ export class CardViewTextItemComponent implements OnChanges {
if (this.property.isValid(this.editedValue)) {
const updatedValue = this.prepareValueForUpload(this.property, this.editedValue);
this.cardViewUpdateService.update(this.property, updatedValue);
this.cardViewUpdateService.update(<CardViewTextItemModel> { ...this.property }, updatedValue);
this.property.value = updatedValue;
this.setEditMode(false);
this.resetErrorMessages();