import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { TitleComponent } from './title.component';
+import { ISubtitle } from '../isubtitle';
describe('TitleComponent', () => {
let component: TitleComponent;
beforeEach(() => {
fixture = TestBed.createComponent(TitleComponent);
component = fixture.componentInstance;
+ component.title = {
+ Title: "",
+ Subtitles: [
+ {
+ Subtitle: "Vorspeise",
+ Foods: []
+ },
+ {
+ Subtitle: "Hauptgericht",
+ Foods: []
+ },
+ {
+ Subtitle: "Vegetarisch",
+ Foods: []
+ }
+ ]
+ };
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
+
+ it('edit form visible by init', () => {
+ expect(component.formTitleVisible).toBeTruthy();
+ });
+
+ it('edit form visible for edit', () => {
+ component.formTitleVisible = false;
+ component.editTitle();
+ expect(component.formTitleVisible).toBeTruthy();
+ });
+
+ it('edit form not visible aufter save after enter', () => {
+ component.formTitleVisible = true;
+ let key = { keyCode: 13 };
+ component.onKeypressEnter(key);
+ expect(component.formTitleVisible).toBeFalsy();
+ });
+
+ it('edit form not visible aufter save', () => {
+ component.formTitleVisible = true;
+ component.saveTitle();
+ expect(component.formTitleVisible).toBeFalsy();
+ });
+
+ it('add new subtitel', () => {
+ let expectSubtitles: ISubtitle[] = [
+ {
+ Subtitle: "Vorspeise",
+ Foods: []
+ },
+ {
+ Subtitle: "Hauptgericht",
+ Foods: []
+ },
+ {
+ Subtitle: "Vegetarisch",
+ Foods: []
+ },
+ {
+ Subtitle: "",
+ Foods: []
+ }
+ ];
+ component.insertSubSection(component.title.Subtitles.length);
+ expect(component.title.Subtitles).toEqual(expectSubtitles);
+ });
+
+ it('insert new subtitle', () => {
+ let expectSubtitles: ISubtitle[] = [
+ {
+ Subtitle: "Vorspeise",
+ Foods: []
+ },
+ {
+ Subtitle: "Hauptgericht",
+ Foods: []
+ },
+ {
+ Subtitle: "",
+ Foods: []
+ },
+ {
+ Subtitle: "Vegetarisch",
+ Foods: []
+ }
+ ];
+ component.insertSubSection(1);
+ expect(component.title.Subtitles).toEqual(expectSubtitles);
+ });
+
+ it('remove one subtitle', () => {
+ let expectSubtitles: ISubtitle[] = [
+ {
+ Subtitle: "Hauptgericht",
+ Foods: []
+ },
+ {
+ Subtitle: "Vegetarisch",
+ Foods: []
+ }
+ ];
+ component.removeSubSection(0);
+ expect(component.title.Subtitles).toEqual(expectSubtitles);
+ });
});