Skip to content
Snippets Groups Projects
Commit 7b337acc authored by Samuel's avatar Samuel
Browse files

PR-530 repair tests

parent 4f57d7ae
No related merge requests found
...@@ -36,7 +36,16 @@ let entityType; ...@@ -36,7 +36,16 @@ let entityType;
let relatedEntityType; let relatedEntityType;
describe('EditRelationshipListComponent', () => { describe('EditRelationshipListComponent', () => {
beforeEach(async(() => {
beforeEach(() => {
entityType = Object.assign(new ItemType(), {
id: 'entityType',
});
relatedEntityType = Object.assign(new ItemType(), {
id: 'relatedEntityType',
});
relationshipType = Object.assign(new RelationshipType(), { relationshipType = Object.assign(new RelationshipType(), {
id: '1', id: '1',
...@@ -82,14 +91,6 @@ describe('EditRelationshipListComponent', () => { ...@@ -82,14 +91,6 @@ describe('EditRelationshipListComponent', () => {
)) ))
}); });
entityType = Object.assign(new ItemType(), {
id: 'entityType',
});
relatedEntityType = Object.assign(new ItemType(), {
id: 'relatedEntityType',
});
author1 = Object.assign(new Item(), { author1 = Object.assign(new Item(), {
id: 'author1', id: 'author1',
uuid: 'author1' uuid: 'author1'
...@@ -145,24 +146,23 @@ describe('EditRelationshipListComponent', () => { ...@@ -145,24 +146,23 @@ describe('EditRelationshipListComponent', () => {
NO_ERRORS_SCHEMA NO_ERRORS_SCHEMA
] ]
}).compileComponents(); }).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditRelationshipListComponent); fixture = TestBed.createComponent(EditRelationshipListComponent);
comp = fixture.componentInstance; comp = fixture.componentInstance;
de = fixture.debugElement; de = fixture.debugElement;
comp.item = item; comp.item = item;
comp.itemType = entityType;
comp.url = url; comp.url = url;
comp.relationshipType = relationshipType; comp.relationshipType = relationshipType;
fixture.detectChanges(); fixture.detectChanges();
}); });
describe('changeType is REMOVE', () => { describe('changeType is REMOVE', () => {
beforeEach(() => {
fieldUpdate1.changeType = FieldChangeType.REMOVE;
fixture.detectChanges();
});
it('the div should have class alert-danger', () => { it('the div should have class alert-danger', () => {
fieldUpdate1.changeType = FieldChangeType.REMOVE;
const element = de.queryAll(By.css('.relationship-row'))[1].nativeElement; const element = de.queryAll(By.css('.relationship-row'))[1].nativeElement;
expect(element.classList).toContain('alert-danger'); expect(element.classList).toContain('alert-danger');
}); });
......
...@@ -31,7 +31,9 @@ let de; ...@@ -31,7 +31,9 @@ let de;
let el; let el;
describe('EditRelationshipComponent', () => { describe('EditRelationshipComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
relationshipType = Object.assign(new RelationshipType(), { relationshipType = Object.assign(new RelationshipType(), {
id: '1', id: '1',
uuid: '1', uuid: '1',
...@@ -95,8 +97,8 @@ describe('EditRelationshipComponent', () => { ...@@ -95,8 +97,8 @@ describe('EditRelationshipComponent', () => {
objectUpdatesService = { objectUpdatesService = {
isSelectedVirtualMetadata: () => null, isSelectedVirtualMetadata: () => null,
removeSingleFieldUpdate: () => null, removeSingleFieldUpdate: jasmine.createSpy('removeSingleFieldUpdate'),
saveRemoveFieldUpdate: () => null, saveRemoveFieldUpdate: jasmine.createSpy('saveRemoveFieldUpdate'),
}; };
spyOn(objectUpdatesService, 'isSelectedVirtualMetadata').and.callFake((a, b, uuid) => observableOf(itemSelection[uuid])); spyOn(objectUpdatesService, 'isSelectedVirtualMetadata').and.callFake((a, b, uuid) => observableOf(itemSelection[uuid]));
...@@ -118,6 +120,7 @@ describe('EditRelationshipComponent', () => { ...@@ -118,6 +120,7 @@ describe('EditRelationshipComponent', () => {
})); }));
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(EditRelationshipComponent); fixture = TestBed.createComponent(EditRelationshipComponent);
comp = fixture.componentInstance; comp = fixture.componentInstance;
de = fixture.debugElement; de = fixture.debugElement;
...@@ -170,37 +173,30 @@ describe('EditRelationshipComponent', () => { ...@@ -170,37 +173,30 @@ describe('EditRelationshipComponent', () => {
}); });
describe('remove', () => { describe('remove', () => {
beforeEach(() => { beforeEach(() => {
spyOn(comp, 'closeVirtualMetadataModal'); spyOn(comp, 'closeVirtualMetadataModal');
spyOn(objectUpdatesService, 'saveRemoveFieldUpdate');
comp.ngOnChanges(); comp.ngOnChanges();
comp.remove(); comp.remove();
}); });
it('should close the virtual metadata modal and call saveRemoveFieldUpdate with the correct arguments', () => { it('should close the virtual metadata modal and call saveRemoveFieldUpdate with the correct arguments', () => {
fixture.whenStable(() => { expect(comp.closeVirtualMetadataModal).toHaveBeenCalled();
expect(comp.closeVirtualMetadataModal).toHaveBeenCalled(); expect(objectUpdatesService.saveRemoveFieldUpdate).toHaveBeenCalledWith(
expect(objectUpdatesService.saveRemoveFieldUpdate).toHaveBeenCalledWith(url, Object.assign({}, fieldUpdate1.field, { url,
Object.assign({}, fieldUpdate1.field, {
keepLeftVirtualMetadata: false, keepLeftVirtualMetadata: false,
keepRightVirtualMetadata: true, keepRightVirtualMetadata: true,
})); }),
}); );
}); });
}); });
describe('undo', () => { describe('undo', () => {
beforeEach(() => {
comp.undo();
comp.ngOnChanges();
});
it('should call removeSingleFieldUpdate with the correct arguments', () => { it('should call removeSingleFieldUpdate with the correct arguments', () => {
comp.undo();
fixture.whenStable().then(() => { expect(objectUpdatesService.removeSingleFieldUpdate).toHaveBeenCalledWith(url, relationships[0].uuid);
expect(spyOn(objectUpdatesService, 'removeSingleFieldUpdate'))
.toHaveBeenCalledWith(url, fieldUpdate1[0]);
})
}); });
}); });
}); });
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<ng-container *ngFor="let item of items; trackBy: trackItem"> <ng-container *ngFor="let item of items; trackBy: trackItem">
<div *ngVar="(isSelectedVirtualMetadataItem(item) | async) as selected" <div *ngVar="(isSelectedVirtualMetadataItem(item) | async) as selected"
(click)="setSelectedVirtualMetadataItem(item, !selected)" (click)="setSelectedVirtualMetadataItem(item, !selected)"
class="d-flex flex-row"> class="item d-flex flex-row">
<div class="m-2"> <div class="m-2">
<label> <label>
<input class="select" type="checkbox" [checked]="selected"> <input class="select" type="checkbox" [checked]="selected">
......
...@@ -87,16 +87,15 @@ describe('VirtualMetadataComponent', () => { ...@@ -87,16 +87,15 @@ describe('VirtualMetadataComponent', () => {
describe('when selecting an item', () => { describe('when selecting an item', () => {
it('should call the updates service setSelectedVirtualMetadata method', () => { it('should call the updates service setSelectedVirtualMetadata method', () => {
fixture.debugElement fixture.debugElement
.query(By.css('input.select')) .query(By.css('div.item'))
.triggerEventHandler('click', null); .triggerEventHandler('click', null);
fixture.whenStable().then(() => expect(objectUpdatesService.setSelectedVirtualMetadata).toHaveBeenCalledWith(
expect(objectUpdatesService.setSelectedVirtualMetadata).toHaveBeenCalledWith( url,
url, relationshipId,
relationshipId, item.uuid,
item.uuid, true
true
)
); );
}); });
}) })
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment