Skip to content

Commit

Permalink
[CST-12490] unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alisaismailati committed Nov 3, 2023
1 parent 5b3bcf4 commit f74efd6
Show file tree
Hide file tree
Showing 21 changed files with 327 additions and 157 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,79 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { LdnServiceFormEditComponent } from './ldn-service-form-edit.component';
import { ChangeDetectorRef, EventEmitter } from '@angular/core';
import { ReactiveFormsModule, FormBuilder } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { PaginationService } from 'ngx-pagination';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { LdnItemfiltersService } from '../ldn-services-data/ldn-itemfilters-data.service';
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
import { RouterStub } from '../../../shared/testing/router.stub';
import { MockActivatedRoute } from '../../../shared/mocks/active-router.mock';
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
import { of } from 'rxjs';
import { RouteService } from '../../../core/services/route.service';
import { provideMockStore } from '@ngrx/store/testing';

describe('LdnServiceFormEditComponent', () => {
let component: LdnServiceFormEditComponent;
let fixture: ComponentFixture<LdnServiceFormEditComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [LdnServiceFormEditComponent]
})
.compileComponents();

fixture = TestBed.createComponent(LdnServiceFormEditComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
let component: LdnServiceFormEditComponent;
let fixture: ComponentFixture<LdnServiceFormEditComponent>;

let ldnServicesService: any;
let ldnItemfiltersService: any;
let cdRefStub: any;
let modalService: any;

const translateServiceStub = {
get: () => of('translated-text'),
onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter()
};

it('should create', () => {
expect(component).toBeTruthy();
beforeEach(async () => {
ldnServicesService = {
update: () => ({}),
};
ldnItemfiltersService = {
findAll: () => of(['item1', 'item2']),
};
cdRefStub = Object.assign({
detectChanges: () => fixture.detectChanges()
});
modalService = {
open: () => {/*comment*/
}
};

await TestBed.configureTestingModule({
imports: [ReactiveFormsModule, TranslateModule.forRoot()],
declarations: [LdnServiceFormEditComponent],
providers: [
{ provide: LdnServicesService, useValue: ldnServicesService },
{ provide: LdnItemfiltersService, useValue: ldnItemfiltersService },
{ provide: Router, useValue: new RouterStub() },
{ provide: ActivatedRoute, useValue: new MockActivatedRoute() },
{ provide: ChangeDetectorRef, useValue: cdRefStub },
{ provide: NgbModal, useValue: modalService },
{ provide: NotificationsService, useValue: NotificationsServiceStub },
{ provide: TranslateService, useValue: translateServiceStub },
{ provide: PaginationService, useValue: {} },
FormBuilder,
RouteService,
provideMockStore({ }),
]
})
.compileComponents();

fixture = TestBed.createComponent(LdnServiceFormEditComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,25 +1,80 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { LdnServiceFormComponent } from './ldn-service-form.component';
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { NgbModal, NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { LdnItemfiltersService } from '../ldn-services-data/ldn-itemfilters-data.service';
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
import { NotificationsService } from 'src/app/shared/notifications/notifications.service';
import { Router } from '@angular/router';
import { RouterStub } from 'src/app/shared/testing/router.stub';
import { createPaginatedList } from 'src/app/shared/testing/utils.test';
import { Itemfilter } from '../ldn-services-model/ldn-service-itemfilters';
import { createSuccessfulRemoteDataObject$ } from 'src/app/shared/remote-data.utils';
import { of } from 'rxjs';
import { EventEmitter } from '@angular/core';

describe('LdnServiceFormComponent', () => {
let component: LdnServiceFormComponent;
let fixture: ComponentFixture<LdnServiceFormComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [LdnServiceFormComponent]
})
.compileComponents();
let component: LdnServiceFormComponent;
let fixture: ComponentFixture<LdnServiceFormComponent>;

let ldnServicesService: any;
let ldnItemfiltersService: any;
let notificationsService: any;

const itemFiltersRdPL$ = createSuccessfulRemoteDataObject$(createPaginatedList([new Itemfilter()]));
const translateServiceStub = {
get: () => of('translated-text'),
onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter()
};

beforeEach(async () => {
ldnItemfiltersService = jasmine.createSpyObj('ldnItemfiltersService', {
findAll: jasmine.createSpy('findAll'),
});

beforeEach(() => {
fixture = TestBed.createComponent(LdnServiceFormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
ldnServicesService = jasmine.createSpyObj('ldnServicesService', {
create: jasmine.createSpy('create'),
});

it('should create', () => {
expect(component).toBeTruthy();
notificationsService = jasmine.createSpyObj('notificationsService', {
success: jasmine.createSpy('success'),
error: jasmine.createSpy('error'),
});

await TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
RouterTestingModule,
NgbModalModule,
TranslateModule.forRoot()
],
providers: [
{ provide: LdnItemfiltersService, useValue: ldnItemfiltersService },
{ provide: LdnServicesService, useValue: ldnServicesService },
{ provide: NotificationsService, useValue: notificationsService },
{ provide: TranslateService, useValue: translateServiceStub },
{ provide: Router, useValue: new RouterStub() },
{ provide: NgbModal, useValue: { open: () => {/*comment*/ } } },
FormBuilder
],
declarations: [LdnServiceFormComponent]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(LdnServiceFormComponent);
component = fixture.componentInstance;
ldnItemfiltersService.findAll.and.returnValue(itemFiltersRdPL$);
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { LdnService } from "../ldn-services-model/ldn-services.model";
import { ActivatedRoute } from "@angular/router";
import { ProcessDataService } from "../../../core/data/processes/process-data.service";
import { LinkService } from "../../../core/cache/builders/link.service";
import { Component } from '@angular/core';

@Component({
selector: 'ds-ldn-service-new',
templateUrl: './ldn-service-new.component.html',
styleUrls: ['./ldn-service-new.component.scss']
})
export class LdnServiceNewComponent implements OnInit {
/**
* Emits preselected process if there is one
*/
ldnService$?: Observable<LdnService>;

constructor(private route: ActivatedRoute, private processService: ProcessDataService, private linkService: LinkService) {
}

/**
* If there's an id parameter, use this the process with this identifier as presets for the form
*/
ngOnInit() {
}
export class LdnServiceNewComponent {
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LdnServicesOverviewComponent } from './ldn-services-directory.component';
import { ChangeDetectorRef, EventEmitter } from '@angular/core';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
import { PaginationService } from '../../../core/pagination/pagination.service';
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
import { of } from 'rxjs';

import { ServicesDirectoryComponent } from './services-directory.component';
describe('LdnServicesOverviewComponent', () => {
let component: LdnServicesOverviewComponent;
let fixture: ComponentFixture<LdnServicesOverviewComponent>;

describe('ServicesDirectoryComponent', () => {
let component: ServicesDirectoryComponent;
let fixture: ComponentFixture<ServicesDirectoryComponent>;
const translateServiceStub = {
get: () => of('translated-text'),
onLangChange: new EventEmitter(),
onTranslationChange: new EventEmitter(),
onDefaultLangChange: new EventEmitter()
};

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ServicesDirectoryComponent]
})
.compileComponents();
});
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()],
declarations: [LdnServicesOverviewComponent],
providers: [
{ provide: LdnServicesService, useValue: {} },
{ provide: PaginationService, useValue: new PaginationServiceStub() },
{
provide: NgbModal, useValue: {
open: () => {/*comment*/
}
}
},
{ provide: ChangeDetectorRef, useValue: {} },
{ provide: NotificationsService, useValue: NotificationsServiceStub },
{ provide: TranslateService, useValue: translateServiceStub },
]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(ServicesDirectoryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
beforeEach(() => {
fixture = TestBed.createComponent(LdnServicesOverviewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { NotifyInfoComponent } from './notify-info.component';
import { NotifyInfoService } from './notify-info.service';
import { TranslateModule } from '@ngx-translate/core';

describe('NotifyInfoComponent', () => {
let component: NotifyInfoComponent;
let fixture: ComponentFixture<NotifyInfoComponent>;
let notifyInfoServiceSpy: any;

beforeEach(async () => {
notifyInfoServiceSpy = jasmine.createSpyObj('NotifyInfoService', ['getCoarLdnLocalInboxUrls']);

await TestBed.configureTestingModule({
declarations: [ NotifyInfoComponent ]
imports: [TranslateModule.forRoot()],
declarations: [ NotifyInfoComponent ],
providers: [
{ provide: NotifyInfoService, useValue: notifyInfoServiceSpy }
]
})
.compileComponents();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class NotifyInfoComponent implements OnInit {
*/
coarRestApiUrl: Observable<string[]> = of([]);

constructor(public notifyInfoService: NotifyInfoService) {}
constructor(private notifyInfoService: NotifyInfoService) {}

ngOnInit() {
this.coarRestApiUrl = this.notifyInfoService.getCoarLdnLocalInboxUrls();
Expand Down
Loading

0 comments on commit f74efd6

Please sign in to comment.