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

PR-530 repair tests

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