From: Bastian Dehn Date: Sun, 3 Jul 2022 11:16:58 +0000 (+0200) Subject: add: tests for title X-Git-Tag: v1.0.7^2~3 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=484bac31d9c1254a3e89dbf96a73fa8d25a1f4e2;p=speisekarten-editor.git add: tests for title --- diff --git a/src/app/title/title.component.spec.ts b/src/app/title/title.component.spec.ts index be77eca..879b11b 100644 --- a/src/app/title/title.component.spec.ts +++ b/src/app/title/title.component.spec.ts @@ -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); + }); });