mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
CST-12498 Fixed tests for directory, no more failing ones
This commit is contained in:
@@ -19,7 +19,10 @@ import {PaginationComponentOptions} from '../../../shared/pagination/pagination-
|
||||
import {LdnItemfiltersService} from '../ldn-services-data/ldn-itemfilters-data.service';
|
||||
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
|
||||
/**
|
||||
* Angular component representing the form for creating or editing LDN services.
|
||||
* This component handles the creation, validation, and submission of LDN service data.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ds-ldn-service-form',
|
||||
templateUrl: './ldn-service-form.component.html',
|
||||
@@ -100,23 +103,43 @@ export class LdnServiceFormComponent implements OnInit {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the item filters by fetching and observing the paginated list of item filters.
|
||||
*/
|
||||
setItemfilters() {
|
||||
this.itemfiltersRD$ = this.ldnItemfiltersService.findAll().pipe(
|
||||
getFirstCompletedRemoteData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the form submission by opening the confirmation modal.
|
||||
*/
|
||||
onSubmit() {
|
||||
this.openConfirmModal(this.confirmModal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the confirmation modal.
|
||||
*
|
||||
* @param {any} content - The content of the modal.
|
||||
*/
|
||||
openConfirmModal(content) {
|
||||
this.modalRef = this.modalService.open(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the reset form modal.
|
||||
*
|
||||
* @param {any} content - The content of the modal.
|
||||
*/
|
||||
openResetFormModal(content) {
|
||||
this.modalRef = this.modalService.open(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the creation of an LDN service by validating form fields,
|
||||
* and submitting the form data to the LDN services endpoint.
|
||||
*/
|
||||
createService() {
|
||||
this.formModel.get('name').markAsTouched();
|
||||
this.formModel.get('score').markAsTouched();
|
||||
@@ -175,6 +198,12 @@ export class LdnServiceFormComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if at least one pattern in the specified form array has a value.
|
||||
*
|
||||
* @param {FormArray} formArray - The form array containing patterns to check.
|
||||
* @returns {boolean} - True if at least one pattern has a value, otherwise false.
|
||||
*/
|
||||
checkPatterns(formArray: FormArray): boolean {
|
||||
for (let i = 0; i < formArray.length; i++) {
|
||||
const pattern = formArray.at(i).get('pattern').value;
|
||||
@@ -185,37 +214,65 @@ export class LdnServiceFormComponent implements OnInit {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes the currently open modal and returns to the services directory..
|
||||
*/
|
||||
resetFormAndLeave() {
|
||||
this.sendBack();
|
||||
this.closeModal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the currently open modal and triggers change detection.
|
||||
*/
|
||||
closeModal() {
|
||||
this.modalRef.close();
|
||||
this.cdRef.detectChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new inbound pattern form group to the notifyServiceInboundPatterns form array.
|
||||
*/
|
||||
addInboundPattern() {
|
||||
const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||
notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the inbound pattern form group at the specified index from the notifyServiceInboundPatterns form array.
|
||||
*
|
||||
* @param {number} index - The index of the inbound pattern form group to remove.
|
||||
* @memberof LdnServiceFormComponent
|
||||
*/
|
||||
removeInboundPattern(index: number) {
|
||||
const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||
notifyServiceInboundPatternsArray.removeAt(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new outbound pattern form group to the notifyServiceOutboundPatterns form array.
|
||||
*/
|
||||
addOutboundPattern() {
|
||||
const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
||||
notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the outbound pattern form group at the specified index from the notifyServiceOutboundPatterns form array.
|
||||
*
|
||||
* @param {number} index - The index of the outbound pattern form group to remove.
|
||||
*/
|
||||
removeOutboundPattern(index: number) {
|
||||
const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
||||
notifyServiceOutboundPatternsArray.removeAt(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the value of the 'automatic' control at the specified index in the notifyServiceInboundPatterns form array.
|
||||
*
|
||||
* @param {number} i - The index of the 'automatic' control to toggle.
|
||||
* @memberof LdnServiceFormComponent
|
||||
*/
|
||||
toggleAutomatic(i: number) {
|
||||
const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`);
|
||||
if (automaticControl) {
|
||||
@@ -223,7 +280,12 @@ export class LdnServiceFormComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Selects an outbound pattern for a specific index in the notifyServiceOutboundPatterns form array.
|
||||
*
|
||||
* @param {string} patternValue - The selected pattern value.
|
||||
* @param {number} index - The index of the outbound pattern in the form array.
|
||||
*/
|
||||
selectOutboundPattern(patternValue: string, index: number): void {
|
||||
const patternArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray)
|
||||
patternArray.controls[index].patchValue({pattern: patternValue})
|
||||
@@ -231,6 +293,12 @@ export class LdnServiceFormComponent implements OnInit {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects an inbound pattern for a specific index in the form array.
|
||||
*
|
||||
* @param {string} patternValue - The selected pattern value.
|
||||
* @param {number} index - The index of the inbound pattern in the form array.
|
||||
*/
|
||||
selectInboundPattern(patternValue: string, index: number): void {
|
||||
const patternArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray)
|
||||
patternArray.controls[index].patchValue({pattern: patternValue})
|
||||
@@ -238,21 +306,40 @@ export class LdnServiceFormComponent implements OnInit {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects an inbound item filter for a specific index in the form array.
|
||||
*
|
||||
* @param {string} filterValue - The selected item filter value.
|
||||
* @param {number} index - The index of the inbound item filter in the form array.
|
||||
*/
|
||||
selectInboundItemFilter(filterValue: string, index: number): void {
|
||||
const filterArray = (this.formModel.get('notifyServiceInboundPatterns') as FormArray)
|
||||
filterArray.controls[index].patchValue({constraint: filterValue})
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects an outbound item filter for a specific index in the form array.
|
||||
*
|
||||
* @param {string} filterValue - The selected item filter value.
|
||||
* @param {number} index - The index of the outbound item filter in the form array.
|
||||
*/
|
||||
selectOutboundItemFilter(filterValue: string, index: number) {
|
||||
const filterArray = (this.formModel.get('notifyServiceOutboundPatterns') as FormArray)
|
||||
filterArray.controls[index].patchValue({constraint: filterValue})
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the user back to the LDN services list.
|
||||
*/
|
||||
private sendBack() {
|
||||
this.router.navigateByUrl('admin/ldn/services');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a form group for an outbound pattern in the notifyServiceOutboundPatterns form array.
|
||||
*
|
||||
* @private
|
||||
* @returns {FormGroup} - The created form group.
|
||||
*/
|
||||
private createOutboundPatternFormGroup(): FormGroup {
|
||||
return this.formBuilder.group({
|
||||
pattern: [''],
|
||||
@@ -261,6 +348,12 @@ export class LdnServiceFormComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form group for an inbound pattern in the notifyServiceInboundPatterns form array.
|
||||
*
|
||||
* @private
|
||||
* @returns {FormGroup} - The created form group.
|
||||
*/
|
||||
private createInboundPatternFormGroup(): FormGroup {
|
||||
return this.formBuilder.group({
|
||||
pattern: [''],
|
||||
|
@@ -37,10 +37,24 @@ export class LdnItemfiltersService extends IdentifiableDataService<Itemfilter> i
|
||||
this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the endpoint URL for the itemfilters.
|
||||
*
|
||||
* @returns {string} - The endpoint URL.
|
||||
*/
|
||||
getEndpoint() {
|
||||
return this.halService.getEndpoint(this.linkPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all itemfilters based on the provided options and link configurations.
|
||||
*
|
||||
* @param {FindListOptions} options - The options for finding a list of itemfilters.
|
||||
* @param {boolean} useCachedVersionIfAvailable - Whether to use the cached version if available.
|
||||
* @param {boolean} reRequestOnStale - Whether to re-request the data if it's stale.
|
||||
* @param {...FollowLinkConfig<Itemfilter>[]} linksToFollow - Configurations for following specific links.
|
||||
* @returns {Observable<RemoteData<PaginatedList<Itemfilter>>>} - An observable of remote data containing a paginated list of itemfilters.
|
||||
*/
|
||||
findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<Itemfilter>[]): Observable<RemoteData<PaginatedList<Itemfilter>>> {
|
||||
return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
||||
}
|
||||
|
@@ -12,12 +12,14 @@ import {LdnService} from "../ldn-services-model/ldn-services.model";
|
||||
import {PaginatedList} from "../../../core/data/paginated-list.model";
|
||||
import {RemoteData} from "../../../core/data/remote-data";
|
||||
import {LdnServicesOverviewComponent} from './ldn-services-directory.component';
|
||||
import {createSuccessfulRemoteDataObject$} from "../../../shared/remote-data.utils";
|
||||
import {createPaginatedList} from "../../../shared/testing/utils.test";
|
||||
|
||||
describe('LdnServicesOverviewComponent', () => {
|
||||
describe('LdnServicesOverviewComponent', ( ) => {
|
||||
let component: LdnServicesOverviewComponent;
|
||||
let fixture: ComponentFixture<LdnServicesOverviewComponent>;
|
||||
let ldnServicesService: LdnServicesService;
|
||||
let paginationService: PaginationService;
|
||||
let ldnServicesService;
|
||||
let paginationService;
|
||||
let modalService: NgbModal;
|
||||
let notificationsService: NotificationsService;
|
||||
let translateService: TranslateService;
|
||||
@@ -30,16 +32,20 @@ describe('LdnServicesOverviewComponent', () => {
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
paginationService = new PaginationServiceStub();
|
||||
ldnServicesService = jasmine.createSpyObj('LdnServicesService', ['findAll', 'delete', 'patch'])
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [LdnServicesOverviewComponent],
|
||||
providers: [
|
||||
{provide: LdnServicesService, useValue: jasmine.createSpyObj('LdnServicesService', ['findAll', 'delete', 'patch'])},
|
||||
{provide: PaginationService, useValue: new PaginationServiceStub()},
|
||||
{
|
||||
provide: LdnServicesService,
|
||||
useValue: ldnServicesService
|
||||
},
|
||||
{provide: PaginationService, useValue: paginationService},
|
||||
{
|
||||
provide: NgbModal, useValue: {
|
||||
open: () => { /*comment*/
|
||||
}
|
||||
open: () => { /*comment*/}
|
||||
}
|
||||
},
|
||||
{provide: ChangeDetectorRef, useValue: {}},
|
||||
@@ -77,27 +83,17 @@ describe('LdnServicesOverviewComponent', () => {
|
||||
|
||||
it('should set ldnServicesRD$ with mock data', fakeAsync(() => {
|
||||
spyOn(component, 'setLdnServices').and.callThrough();
|
||||
const mockData = {
|
||||
payload: {
|
||||
page: [
|
||||
const testData: LdnService[] = Object.assign([new LdnService()], [
|
||||
{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.ngOnInit();
|
||||
tick();
|
||||
expect(component.setLdnServices).toHaveBeenCalled();
|
||||
{id: 3, name: 'Service 3', description: 'Description 3', enabled: true}]);
|
||||
|
||||
const mockLdnServicesRD = createPaginatedList(testData)
|
||||
component.ldnServicesRD$ = createSuccessfulRemoteDataObject$(mockLdnServicesRD);
|
||||
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 tableRows = fixture.debugElement.nativeElement.querySelectorAll('tbody tr');
|
||||
expect(tableRows.length).toBe(testData.length);
|
||||
const firstRowContent = tableRows[0].textContent;
|
||||
expect(firstRowContent).toContain('Service 1');
|
||||
expect(firstRowContent).toContain('Description 1');
|
||||
@@ -106,8 +102,8 @@ describe('LdnServicesOverviewComponent', () => {
|
||||
|
||||
describe('ngOnDestroy', () => {
|
||||
it('should call paginationService.clearPagination and unsubscribe', () => {
|
||||
spyOn(paginationService, 'clearPagination');
|
||||
spyOn(component.isProcessingSub, 'unsubscribe');
|
||||
// spyOn(paginationService, 'clearPagination');
|
||||
// spyOn(component.isProcessingSub, 'unsubscribe');
|
||||
component.ngOnDestroy();
|
||||
expect(paginationService.clearPagination).toHaveBeenCalledWith(component.pageConfig.id);
|
||||
expect(component.isProcessingSub.unsubscribe).toHaveBeenCalled();
|
||||
@@ -124,7 +120,7 @@ describe('LdnServicesOverviewComponent', () => {
|
||||
|
||||
describe('closeModal', () => {
|
||||
it('should close modal and detect changes', () => {
|
||||
spyOn(component.modalRef, 'close');
|
||||
// spyOn(component.modalRef, 'close');
|
||||
spyOn(component.cdRef, 'detectChanges');
|
||||
component.closeModal();
|
||||
expect(component.modalRef.close).toHaveBeenCalled();
|
||||
@@ -135,10 +131,9 @@ describe('LdnServicesOverviewComponent', () => {
|
||||
describe('deleteSelected', () => {
|
||||
it('should delete selected service and update data', fakeAsync(() => {
|
||||
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 = { /* just an empty object to retrieve as as RemoteData<PaginatedList<LdnService>> */};
|
||||
spyOn(component, 'setLdnServices').and.callThrough();
|
||||
const deleteSpy = spyOn(ldnServicesService, 'delete').and.returnValue(of(mockRemoteData as RemoteData<PaginatedList<LdnService>>));
|
||||
const deleteSpy = ldnServicesService.delete.and.returnValue(of(mockRemoteData as RemoteData<PaginatedList<LdnService>>));
|
||||
component.selectedServiceId = serviceId;
|
||||
component.deleteSelected(serviceId, ldnServicesService);
|
||||
tick();
|
||||
|
Reference in New Issue
Block a user