mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 11:33:04 +00:00
CST-12498 Tests added, need to check TODOs in ldn-services-directory.component.spec.ts
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing';
|
import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
|
||||||
import { ChangeDetectorRef, EventEmitter, TemplateRef, ViewChild } from '@angular/core';
|
import {ChangeDetectorRef, EventEmitter} from '@angular/core';
|
||||||
import {NotificationsService} from '../../../shared/notifications/notifications.service';
|
import {NotificationsService} from '../../../shared/notifications/notifications.service';
|
||||||
import {NotificationsServiceStub} from '../../../shared/testing/notifications-service.stub';
|
import {NotificationsServiceStub} from '../../../shared/testing/notifications-service.stub';
|
||||||
import {TranslateModule, TranslateService} from '@ngx-translate/core';
|
import {TranslateModule, TranslateService} from '@ngx-translate/core';
|
||||||
@@ -36,7 +36,12 @@ describe('LdnServicesOverviewComponent', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
{provide: LdnServicesService, useValue: jasmine.createSpyObj('LdnServicesService', ['findAll', 'delete', 'patch'])},
|
{provide: LdnServicesService, useValue: jasmine.createSpyObj('LdnServicesService', ['findAll', 'delete', 'patch'])},
|
||||||
{provide: PaginationService, useValue: new PaginationServiceStub()},
|
{provide: PaginationService, useValue: new PaginationServiceStub()},
|
||||||
{ provide: NgbModal, useValue: { open: () => { /*comment*/ } } },
|
{
|
||||||
|
provide: NgbModal, useValue: {
|
||||||
|
open: () => { /*comment*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{provide: ChangeDetectorRef, useValue: {}},
|
{provide: ChangeDetectorRef, useValue: {}},
|
||||||
{provide: NotificationsService, useValue: NotificationsServiceStub},
|
{provide: NotificationsService, useValue: NotificationsServiceStub},
|
||||||
{provide: TranslateService, useValue: translateServiceStub},
|
{provide: TranslateService, useValue: translateServiceStub},
|
||||||
@@ -54,7 +59,7 @@ describe('LdnServicesOverviewComponent', () => {
|
|||||||
translateService = TestBed.inject(TranslateService);
|
translateService = TestBed.inject(TranslateService);
|
||||||
component.modalRef = jasmine.createSpyObj({close: null});
|
component.modalRef = jasmine.createSpyObj({close: null});
|
||||||
component.isProcessingSub = jasmine.createSpyObj({unsubscribe: null});
|
component.isProcessingSub = jasmine.createSpyObj({unsubscribe: null});
|
||||||
component.ldnServicesRD$ = of({} as RemoteData<PaginatedList<LdnService>>); // You can adjust the mock data as needed
|
component.ldnServicesRD$ = of({} as RemoteData<PaginatedList<LdnService>>);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -72,12 +77,30 @@ describe('LdnServicesOverviewComponent', () => {
|
|||||||
|
|
||||||
it('should set ldnServicesRD$ with mock data', fakeAsync(() => {
|
it('should set ldnServicesRD$ with mock data', fakeAsync(() => {
|
||||||
spyOn(component, 'setLdnServices').and.callThrough();
|
spyOn(component, 'setLdnServices').and.callThrough();
|
||||||
const mockData = { /* your mock data here */ };
|
const mockData = {
|
||||||
|
payload: {
|
||||||
|
page: [
|
||||||
|
{id: 1, name: 'Service 1', description: 'Description 1', enabled: true},
|
||||||
|
{id: 2, name: 'Service 2', description: 'Description 2', enabled: false},
|
||||||
|
{id: 3, name: 'Service 3', description: 'Description 3', enabled: true},
|
||||||
|
],
|
||||||
|
totalElements: 3
|
||||||
|
}
|
||||||
|
} as RemoteData<PaginatedList<LdnService>>;
|
||||||
component.ldnServicesRD$ = of(mockData as RemoteData<PaginatedList<LdnService>>);
|
component.ldnServicesRD$ = of(mockData as RemoteData<PaginatedList<LdnService>>);
|
||||||
component.ngOnInit();
|
component.ngOnInit();
|
||||||
tick();
|
tick();
|
||||||
expect(component.setLdnServices).toHaveBeenCalled();
|
expect(component.setLdnServices).toHaveBeenCalled();
|
||||||
// Add more expectations based on your mock data and component behavior
|
fixture.detectChanges();
|
||||||
|
console.log(fixture.nativeElement.innerHTML);
|
||||||
|
console.log('Mock Data:', mockData);
|
||||||
|
const tableRows = fixture.nativeElement.querySelectorAll('tbody tr');
|
||||||
|
console.log('Table Rows:', tableRows);
|
||||||
|
//TODO: check why the tbody tr length table rows is 0 when i sjhould be 3 accordingly to the mock
|
||||||
|
expect(tableRows.length).toBe(mockData.payload.page.length);
|
||||||
|
const firstRowContent = tableRows[0].textContent;
|
||||||
|
expect(firstRowContent).toContain('Service 1');
|
||||||
|
expect(firstRowContent).toContain('Description 1');
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -112,6 +135,7 @@ describe('LdnServicesOverviewComponent', () => {
|
|||||||
describe('deleteSelected', () => {
|
describe('deleteSelected', () => {
|
||||||
it('should delete selected service and update data', fakeAsync(() => {
|
it('should delete selected service and update data', fakeAsync(() => {
|
||||||
const serviceId = '123';
|
const serviceId = '123';
|
||||||
|
//TODO: finish up this test to use a mockdata containing something
|
||||||
const mockRemoteData = { /* insert mock data with service id 123 */};
|
const mockRemoteData = { /* insert mock data with service id 123 */};
|
||||||
spyOn(component, 'setLdnServices').and.callThrough();
|
spyOn(component, 'setLdnServices').and.callThrough();
|
||||||
const deleteSpy = spyOn(ldnServicesService, 'delete').and.returnValue(of(mockRemoteData as RemoteData<PaginatedList<LdnService>>));
|
const deleteSpy = spyOn(ldnServicesService, 'delete').and.returnValue(of(mockRemoteData as RemoteData<PaginatedList<LdnService>>));
|
||||||
@@ -119,7 +143,6 @@ describe('LdnServicesOverviewComponent', () => {
|
|||||||
component.deleteSelected(serviceId, ldnServicesService);
|
component.deleteSelected(serviceId, ldnServicesService);
|
||||||
tick();
|
tick();
|
||||||
expect(deleteSpy).toHaveBeenCalledWith(serviceId);
|
expect(deleteSpy).toHaveBeenCalledWith(serviceId);
|
||||||
expect(mockRemoteData)
|
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user