]> gitweb.hhaalo.de Git - speisekarten-editor.git/commitdiff
add: tests for title
authorBastian Dehn <hhaalo@arcor.de>
Sun, 3 Jul 2022 11:16:58 +0000 (13:16 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 3 Jul 2022 11:16:58 +0000 (13:16 +0200)
src/app/title/title.component.spec.ts

index be77ecaeb1a98a262c77f4fc02b91f6524d4088c..879b11b17f33670c9485870c6d772dd6ad25977d 100644 (file)
@@ -1,6 +1,7 @@
 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;
@@ -17,10 +18,111 @@ describe('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);
+  });
 });