From: Bastian Dehn Date: Sat, 2 Jul 2022 22:25:05 +0000 (+0200) Subject: add: tests for subtitle X-Git-Tag: v1.0.7^2~7 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=cc21db4df45d918951174987e265a707fb7ee61d;p=speisekarten-editor.git add: tests for subtitle --- diff --git a/src/app/subtitle/subtitle.component.spec.ts b/src/app/subtitle/subtitle.component.spec.ts index 2c88a95..e0f43d8 100644 --- a/src/app/subtitle/subtitle.component.spec.ts +++ b/src/app/subtitle/subtitle.component.spec.ts @@ -23,4 +23,158 @@ describe('SubtitleComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('edit form visible by init', () => { + expect(component.formSubtitleVisible).toBeTruthy(); + }); + + it('edit form visible for edit', () => { + component.formSubtitleVisible = false; + component.editSubtitle(); + expect(component.formSubtitleVisible).toBeTruthy(); + }); + + it('edit form not visible after save with enter', () => { + component.formSubtitleVisible = true; + let key = { keyCode: 13 }; + component.onKeypressEnter(key); + expect(component.formSubtitleVisible).toBeFalsy(); + }); + + it('edit form not visible after save', () => { + component.formSubtitleVisible = true; + component.saveSubtitle(); + expect(component.formSubtitleVisible).toBeFalsy(); + }); + + it('add new food', () => { + let expectedFoods = [ + { + Food: "", + sideDish: "", + price: "" + } + ]; + component.addNewFood(); + expect(component.subtitle.Foods).toEqual(expectedFoods); + }); + + it('insert new food', () => { + let initFoods = [ + { + Food: "Schnitzel", + sideDish: "mit Pommes", + price: "10,50 €" + }, + { + Food: "Jägerschnitzel", + sideDish: "mit Pommes", + price: "12,50 €" + }, + { + Food: "Hawaischnitzel", + sideDish: "mit Pommes", + price: "11,50 €" + } + ]; + component.subtitle.Foods = initFoods; + let expectedFoods = [ + { + Food: "Schnitzel", + sideDish: "mit Pommes", + price: "10,50 €" + }, + { + Food: "Jägerschnitzel", + sideDish: "mit Pommes", + price: "12,50 €" + }, + { + Food: "", + sideDish: "", + price: "" + }, + { + Food: "Hawaischnitzel", + sideDish: "mit Pommes", + price: "11,50 €" + } + ]; + component.insertNewFood(1); + expect(component.subtitle.Foods).toEqual(expectedFoods); + }); + + it('remove one food', () => { + let initFoods = [ + { + Food: "Schnitzel", + sideDish: "mit Pommes", + price: "10,50 €" + }, + { + Food: "Jägerschnitzel", + sideDish: "mit Pommes", + price: "12,50 €" + }, + { + Food: "Hawaischnitzel", + sideDish: "mit Pommes", + price: "11,50 €" + } + ]; + component.subtitle.Foods = initFoods; + let expectedFoods = [ + { + Food: "Schnitzel", + sideDish: "mit Pommes", + price: "10,50 €" + }, + { + Food: "Hawaischnitzel", + sideDish: "mit Pommes", + price: "11,50 €" + } + ]; + component.removeFood(1); + expect(component.subtitle.Foods).toEqual(expectedFoods); + }); + + it('drag and drop move item', () => { + let initFoods = [ + { + Food: "Schnitzel", + sideDish: "mit Pommes", + price: "10,50 €" + }, + { + Food: "Jägerschnitzel", + sideDish: "mit Pommes", + price: "12,50 €" + }, + { + Food: "Hawaischnitzel", + sideDish: "mit Pommes", + price: "11,50 €" + } + ]; + component.subtitle.Foods = initFoods; + let expectedFoods = [ + { + Food: "Schnitzel", + sideDish: "mit Pommes", + price: "10,50 €" + }, + { + Food: "Hawaischnitzel", + sideDish: "mit Pommes", + price: "11,50 €" + }, + { + Food: "Jägerschnitzel", + sideDish: "mit Pommes", + price: "12,50 €" + } + ]; + expect(component.subtitle.Foods).toEqual(expectedFoods); + }); });