/* 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 { ComandaUpdateComponent } from 'app/entities/comanda/comanda-update.component'; import { ComandaService } from 'app/entities/comanda/comanda.service'; import { Comanda } from 'app/shared/model/comanda.model'; import { MesaService } from 'app/entities/mesa'; describe('Component Tests', () => { describe('Comanda Management Update Component', () => { let comp: ComandaUpdateComponent; let fixture: ComponentFixture; let service: ComandaService; beforeEach(() => { TestBed.configureTestingModule({ imports: [BaresTestModule], declarations: [ComandaUpdateComponent], providers: [MesaService, ComandaService] }) .overrideTemplate(ComandaUpdateComponent, '') .compileComponents(); fixture = TestBed.createComponent(ComandaUpdateComponent); comp = fixture.componentInstance; service = fixture.debugElement.injector.get(ComandaService); }); describe('save', () => { it( 'Should call update service on save for existing entity', fakeAsync(() => { // GIVEN const entity = new Comanda(123); spyOn(service, 'update').and.returnValue(Observable.of(new HttpResponse({ body: entity }))); comp.comanda = 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 Comanda(); spyOn(service, 'create').and.returnValue(Observable.of(new HttpResponse({ body: entity }))); comp.comanda = entity; // WHEN comp.save(); tick(); // simulate async // THEN expect(service.create).toHaveBeenCalledWith(entity); expect(comp.isSaving).toEqual(false); }) ); }); }); });