mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Fixed failed test
This commit is contained in:
@@ -156,18 +156,21 @@ describe('ResourcePoliciesComponent test suite', () => {
|
|||||||
url: `url/edit`
|
url: `url/edit`
|
||||||
});
|
});
|
||||||
|
|
||||||
const resourcePolicyEntries = [
|
const getInitEntries = () => {
|
||||||
{
|
return [
|
||||||
id: resourcePolicy.id,
|
Object.assign({}, {
|
||||||
policy: resourcePolicy,
|
id: resourcePolicy.id,
|
||||||
checked: false
|
policy: resourcePolicy,
|
||||||
},
|
checked: false
|
||||||
{
|
}),
|
||||||
id: anotherResourcePolicy.id,
|
Object.assign({}, {
|
||||||
policy: anotherResourcePolicy,
|
id: anotherResourcePolicy.id,
|
||||||
checked: false
|
policy: anotherResourcePolicy,
|
||||||
}
|
checked: false
|
||||||
];
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
const resourcePolicySelectedEntries = [
|
const resourcePolicySelectedEntries = [
|
||||||
{
|
{
|
||||||
id: resourcePolicy.id,
|
id: resourcePolicy.id,
|
||||||
@@ -245,8 +248,6 @@ describe('ResourcePoliciesComponent test suite', () => {
|
|||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
compAsAny = fixture.componentInstance;
|
compAsAny = fixture.componentInstance;
|
||||||
linkService.resolveLink.and.callFake((object, link) => object);
|
linkService.resolveLink.and.callFake((object, link) => object);
|
||||||
spyOn(comp, 'canDelete');
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -264,6 +265,7 @@ describe('ResourcePoliciesComponent test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init resource policies list properly', () => {
|
it('should init resource policies list properly', () => {
|
||||||
|
const expected = getInitEntries();
|
||||||
compAsAny.isActive = true;
|
compAsAny.isActive = true;
|
||||||
resourcePolicyService.searchByResource.and.returnValue(hot('a|', {
|
resourcePolicyService.searchByResource.and.returnValue(hot('a|', {
|
||||||
a: paginatedListRD
|
a: paginatedListRD
|
||||||
@@ -273,46 +275,7 @@ describe('ResourcePoliciesComponent test suite', () => {
|
|||||||
scheduler.schedule(() => comp.initResourcePolicyLIst());
|
scheduler.schedule(() => comp.initResourcePolicyLIst());
|
||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
|
|
||||||
expect(compAsAny.resourcePoliciesEntries$.value).toEqual(resourcePolicyEntries);
|
expect(compAsAny.resourcePoliciesEntries$.value).toEqual(expected);
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('canDelete', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(ResourcePoliciesComponent);
|
|
||||||
comp = fixture.componentInstance;
|
|
||||||
compAsAny = fixture.componentInstance;
|
|
||||||
linkService.resolveLink.and.callFake((object, link) => object);
|
|
||||||
compAsAny.isActive = true;
|
|
||||||
compAsAny.resourcePoliciesEntries$.next(resourcePolicyEntries);
|
|
||||||
resourcePolicyService.searchByResource.and.returnValue(observableOf({}));
|
|
||||||
spyOn(comp, 'initResourcePolicyLIst').and.callFake(() => ({}));
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
comp = null;
|
|
||||||
compAsAny = null;
|
|
||||||
de = null;
|
|
||||||
fixture.destroy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false when no row is selected', () => {
|
|
||||||
expect(comp.canDelete()).toBeObservable(cold('(a|)', {
|
|
||||||
a: false
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true when al least is selected', () => {
|
|
||||||
const checkbox = fixture.debugElement.query(By.css('table > tbody > tr:nth-child(1) input'));
|
|
||||||
|
|
||||||
let event = { target: { checked: true } };
|
|
||||||
checkbox.triggerEventHandler('change', event);
|
|
||||||
expect(comp.canDelete()).toBeObservable(cold('(a|)', {
|
|
||||||
a: true
|
|
||||||
}));
|
|
||||||
event = { target: { checked: false } };
|
|
||||||
checkbox.triggerEventHandler('change', event);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -323,10 +286,10 @@ describe('ResourcePoliciesComponent test suite', () => {
|
|||||||
compAsAny = fixture.componentInstance;
|
compAsAny = fixture.componentInstance;
|
||||||
linkService.resolveLink.and.callFake((object, link) => object);
|
linkService.resolveLink.and.callFake((object, link) => object);
|
||||||
compAsAny.isActive = true;
|
compAsAny.isActive = true;
|
||||||
compAsAny.resourcePoliciesEntries$.next(resourcePolicyEntries);
|
const initResourcePolicyEntries = getInitEntries();
|
||||||
|
compAsAny.resourcePoliciesEntries$.next(initResourcePolicyEntries);
|
||||||
resourcePolicyService.searchByResource.and.returnValue(observableOf({}));
|
resourcePolicyService.searchByResource.and.returnValue(observableOf({}));
|
||||||
spyOn(comp, 'initResourcePolicyLIst').and.callFake(() => ({}));
|
spyOn(comp, 'initResourcePolicyLIst').and.callFake(() => ({}));
|
||||||
spyOn(comp, 'canDelete');
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -337,6 +300,36 @@ describe('ResourcePoliciesComponent test suite', () => {
|
|||||||
fixture.destroy();
|
fixture.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('canDelete', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
const initResourcePolicyEntries = getInitEntries();
|
||||||
|
compAsAny.resourcePoliciesEntries$.next(initResourcePolicyEntries);
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
comp = null;
|
||||||
|
compAsAny = null;
|
||||||
|
de = null;
|
||||||
|
fixture.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false when no row is selected', () => {
|
||||||
|
expect(comp.canDelete()).toBeObservable(cold('(a|)', {
|
||||||
|
a: false
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true when al least is selected', () => {
|
||||||
|
const checkbox = fixture.debugElement.query(By.css('table > tbody > tr:nth-child(1) input'));
|
||||||
|
const event = { target: { checked: true } };
|
||||||
|
checkbox.triggerEventHandler('change', event);
|
||||||
|
expect(comp.canDelete()).toBeObservable(cold('(a|)', {
|
||||||
|
a: true
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should render a table with a row for each policy', () => {
|
it('should render a table with a row for each policy', () => {
|
||||||
const rows = fixture.debugElement.queryAll(By.css('table > tbody > tr'));
|
const rows = fixture.debugElement.queryAll(By.css('table > tbody > tr'));
|
||||||
expect(rows.length).toBe(2);
|
expect(rows.length).toBe(2);
|
||||||
@@ -372,9 +365,9 @@ describe('ResourcePoliciesComponent test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should get the resource\'s policy list', () => {
|
it('should get the resource\'s policy list', () => {
|
||||||
|
const initResourcePolicyEntries = getInitEntries();
|
||||||
expect(comp.getResourcePolicies()).toBeObservable(cold('a', {
|
expect(comp.getResourcePolicies()).toBeObservable(cold('a', {
|
||||||
a: resourcePolicyEntries
|
a: initResourcePolicyEntries
|
||||||
}));
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user