| import { ToastrService } from 'ngx-toastr'; |
| import { SpinnerComponent } from './../../../shared/components/spinner/spinner.component'; |
| import { ServerSideModel } from './../../../shared/models/server-side.model'; |
| import { CardLayoutComponent } from './../../../shared/containers/card-layout/card-layout.component'; |
| import { ContactsListComponent } from './contacts-list.component'; |
| import { HttpClientTestingModule } from '@angular/common/http/testing'; |
| import { Store, ActionsSubject, StateObservable } from '@ngrx/store'; |
| import { Location, CommonModule } from "@angular/common"; |
| import { TestBed, async } from '@angular/core/testing'; |
| import { RouterTestingModule } from "@angular/router/testing"; |
| import { Router, RouterModule } from "@angular/router"; |
| import { ContactsRoutingModule } from './../contacts-routing.module'; |
| import { AgGridModule } from 'ag-grid-angular'; |
| import { NgxDatatableModule } from '@swimlane/ngx-datatable'; |
| import { NgrxFormsModule } from 'ngrx-forms'; |
| import { FormsModule, ReactiveFormsModule } from '@angular/forms'; |
| import { ContactsSandbox } from '../contacts.sandbox'; |
| import { ContactsService } from '../contacts.service'; |
| import { ContactsApiClient } from '../contacts-api-client'; |
| import { ComponentsModule } from '@app/shared/components'; |
| import { TranslateModule } from '@ngx-translate/core'; |
| import { DirectivesModule } from '@app/shared/directives'; |
| import { FiltersModule } from '@app/shared/filters/index.module'; |
| import { ContainersModule } from '@app/shared/containers'; |
| import { By } from '@angular/platform-browser'; |
| |
| |
| class MockContactSandbox {} |
| class MockToastrService{ |
| public success(v1:string, v2:string){return null;} |
| } |
| class MockStore{} |
| class MockActionsSubject{} |
| |
| |
| |
| fdescribe('ContactsListComponent', () => { |
| let component: ContactsListComponent; |
| |
| let contactsSandbox: any = {}; |
| let toastr: any = {}; |
| let router: any = {}; |
| let location: any = {}; |
| let fixture; |
| |
| |
| beforeEach(() => { |
| TestBed.configureTestingModule({ |
| imports: [ |
| CommonModule, |
| ComponentsModule, |
| DirectivesModule, |
| FiltersModule, |
| ReactiveFormsModule, |
| FormsModule, |
| ContainersModule, |
| TranslateModule.forRoot(), |
| RouterTestingModule, |
| NgxDatatableModule, |
| NgrxFormsModule, |
| AgGridModule.withComponents([]), |
| ContactsRoutingModule, |
| |
| ], |
| declarations: [ContactsListComponent], |
| providers: [ |
| { provide: ContactsSandbox, useClass: MockContactSandbox}, |
| { provide: ToastrService, useClass: MockToastrService}, |
| { provide: Store, useClass: MockStore}, |
| { provide: ActionsSubject, useClass: MockActionsSubject}, |
| ] |
| }) |
| |
| contactsSandbox = TestBed.get(ContactsSandbox); |
| toastr = TestBed.get(ToastrService); |
| router = TestBed.get(Router); |
| location = TestBed.get(Location); |
| |
| component = new ContactsListComponent(contactsSandbox, router, toastr); |
| |
| fixture = TestBed.createComponent(ContactsListComponent); |
| }); |
| |
| it('should create', () => { |
| expect(component).toBeTruthy(); |
| }); |
| |
| it('should have value of /new_intern_contact', () => { |
| let value = fixture.debugElement.query(By.css('select > option:nth-child(2)')).nativeElement |
| .getAttribute('value'); |
| console.log(value); |
| expect(value).toEqual('/new_intern_contact'); |
| }); |
| |
| it('should have value of /new_extern_contact', () => { |
| let value = fixture.debugElement.query(By.css('select > option:nth-child(3)')).nativeElement |
| .getAttribute('value'); |
| expect(value).toEqual('/new_extern_contact'); |
| }); |
| |
| it('should have value of /new_company', () => { |
| let value = fixture.debugElement.query(By.css('select > option:nth-child(4)')).nativeElement |
| .getAttribute('value'); |
| expect(value).toEqual('/new_company'); |
| }); |
| |
| it('checks if function NavigateTo works', () => { |
| const routerSpy = spyOn(router, 'navigate'); |
| |
| let url = '/new_intern_contact'; |
| component.navigateTo(url); |
| expect(routerSpy).toHaveBeenCalledTimes(1); |
| |
| }); |
| }); |