/* tslint:disable max-line-length */ import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; import { HttpResponse } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import { BaresTestModule } from '../../../test.module'; import { ArticuloCategoriaUpdateComponent } from 'app/entities/articulo-categoria/articulo-categoria-update.component'; import { ArticuloCategoriaService } from 'app/entities/articulo-categoria/articulo-categoria.service'; import { ArticuloCategoria } from 'app/shared/model/articulo-categoria.model'; import { CategoriaService } from 'app/entities/categoria'; import { ArticuloService } from 'app/entities/articulo'; describe('Component Tests', () => { describe('ArticuloCategoria Management Update Component', () => { let comp: ArticuloCategoriaUpdateComponent; let fixture: ComponentFixture; let service: ArticuloCategoriaService; beforeEach(() => { TestBed.configureTestingModule({ imports: [BaresTestModule], declarations: [ArticuloCategoriaUpdateComponent], providers: [CategoriaService, ArticuloService, ArticuloCategoriaService] }) .overrideTemplate(ArticuloCategoriaUpdateComponent, '') .compileComponents(); fixture = TestBed.createComponent(ArticuloCategoriaUpdateComponent); comp = fixture.componentInstance; service = fixture.debugElement.injector.get(ArticuloCategoriaService); }); describe('save', () => { it( 'Should call update service on save for existing entity', fakeAsync(() => { // GIVEN const entity = new ArticuloCategoria(123); spyOn(service, 'update').and.returnValue(Observable.of(new HttpResponse({ body: entity }))); comp.articuloCategoria = entity; // WHEN comp.save(); tick(); // simulate async // THEN expect(service.update).toHaveBeenCalledWith(entity); expect(comp.isSaving).toEqual(false); }) ); it( 'Should call create service on save for new entity', fakeAsync(() => { // GIVEN const entity = new ArticuloCategoria(); spyOn(service, 'create').and.returnValue(Observable.of(new HttpResponse({ body: entity }))); comp.articuloCategoria = entity; // WHEN comp.save(); tick(); // simulate async // THEN expect(service.create).toHaveBeenCalledWith(entity); expect(comp.isSaving).toEqual(false); }) ); }); }); });