46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
|
|
import { Main } from './main';
|
|
import { STRINGS_INJECTOR } from '../../app.config';
|
|
import { strings } from '../../strings';
|
|
import { ContactService } from './contact.service';
|
|
import { ContactList } from '../../components/contact-list/contact-list';
|
|
import { of } from 'rxjs';
|
|
import { ContactDTO } from '../../models/ContactDTO';
|
|
import { By } from '@angular/platform-browser';
|
|
import { ContactForm } from '../../components/contact-form/contact-form';
|
|
|
|
describe('Main', () => {
|
|
let component: Main;
|
|
let fixture: ComponentFixture<Main>;
|
|
let contactService: jasmine.SpyObj<ContactService>;
|
|
|
|
beforeEach(async () => {
|
|
contactService = jasmine.createSpyObj(ContactList.name, ['getAll', 'save']);
|
|
contactService.getAll.and.returnValue(of([]));
|
|
await TestBed.configureTestingModule({
|
|
imports: [Main],
|
|
providers: [
|
|
{ provide: STRINGS_INJECTOR, useValue: strings },
|
|
{ provide: ContactService, useValue: contactService }
|
|
],
|
|
}).compileComponents();
|
|
fixture = TestBed.createComponent(Main);
|
|
component = fixture.componentInstance;
|
|
fixture.detectChanges();
|
|
});
|
|
|
|
it('should create', () => {
|
|
expect(component).toBeTruthy();
|
|
});
|
|
|
|
it('should call save on contact event', () => {
|
|
contactService.save.and.returnValue(of([]));
|
|
const saveSpy = spyOn(component, 'save').and.callThrough();
|
|
const CONTACT_MOCK = new ContactDTO()
|
|
const contactForm: ContactForm = fixture.debugElement.query(By.css('app-contact-form')).componentInstance;
|
|
contactForm.contact.emit(CONTACT_MOCK);
|
|
expect(saveSpy).toHaveBeenCalledOnceWith(CONTACT_MOCK);
|
|
});
|
|
});
|