Skip to content

Commit

Permalink
[ACS-5373] - Remove code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikiwanekhyland committed Aug 28, 2023
1 parent 50bb125 commit c1d8f14
Showing 1 changed file with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ describe('ContentMetadataComponent', () => {
return fixture.debugElement.query(By.css('.adf-metadata-categories-title button')).nativeElement;
}

async function updateAspectProperty(newValue: string): Promise<void> {
component.editable = true;
const property = {key: 'properties.property-key', value: 'original-value'} as CardViewBaseItemModel;
const expectedNode = {...node, name: 'some-modified-value'};
spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode));

updateService.update(property, newValue);
tick(600);

fixture.detectChanges();
await fixture.whenStable();
clickOnSave();

await fixture.whenStable();
}

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
Expand Down Expand Up @@ -242,37 +258,15 @@ describe('ContentMetadataComponent', () => {
}));

it('should save changedProperties on save click', fakeAsync(async () => {
component.editable = true;
const property = { key: 'properties.property-key', value: 'original-value' } as CardViewBaseItemModel;
const expectedNode = { ...node, name: 'some-modified-value' };
spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode));

updateService.update(property, 'updated-value');
tick(600);

fixture.detectChanges();
await fixture.whenStable();
clickOnSave();

await fixture.whenStable();
await updateAspectProperty('updated-value');
expect(component.node).toEqual(expectedNode);
expect(nodesApiService.updateNode).toHaveBeenCalled();
}));

it('should save changedProperties which delete property and update node on save click', fakeAsync(async () => {
component.editable = true;
const property = {key: 'properties.property-key', value: 'original-value'} as CardViewBaseItemModel;
const expectedNode = {...node, name: 'some-modified-value'};
spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode));

updateService.update(property, '');
tick(600);

fixture.detectChanges();
await fixture.whenStable();
clickOnSave();

await fixture.whenStable();
await updateAspectProperty('');
expect(component.node).toEqual({...expectedNode, properties: {}});
expect(nodesApiService.updateNode).toHaveBeenCalled();
}));
Expand Down

0 comments on commit c1d8f14

Please sign in to comment.