From 345d8f4a5e27567a8c9b38ad6848b8aa8ea74e28 Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Tue, 18 Apr 2017 00:50:52 +0200 Subject: [PATCH] Final - Doc for new classes --- project-manager/e2e/access/access.e2e-spec.ts | 6 ++ .../e2e/page-object/task/task-edit.po.ts | 82 ++++++++++++++++--- .../e2e/page-object/task/task-overview.po.ts | 33 ++++++++ .../e2e/task/create-new-task.e2e-spec.ts | 2 +- project-manager/projects-server/test.json | 11 +-- .../blog-entry/blog-entry.component.spec.ts | 6 ++ .../src/app/blog/blog.component.spec.ts | 20 +++-- .../src/app/login/login.component.spec.ts | 7 +- .../src/app/mocks/mock-blog.component.ts | 7 ++ .../src/app/mocks/mock-login-service.ts | 9 +- .../src/app/mocks/mock-task-item.component.ts | 6 ++ .../model-driven-form.component.spec.ts | 15 +++- .../login-service/login.service.spec.ts | 5 +- .../edit-task/edit-task.component.spec.ts | 26 ++++-- .../task-list/task-list.component.spec.ts | 20 +++-- 15 files changed, 201 insertions(+), 54 deletions(-) diff --git a/project-manager/e2e/access/access.e2e-spec.ts b/project-manager/e2e/access/access.e2e-spec.ts index b3aa34b..cc1255a 100644 --- a/project-manager/e2e/access/access.e2e-spec.ts +++ b/project-manager/e2e/access/access.e2e-spec.ts @@ -2,6 +2,12 @@ import {browser, element, by} from 'protractor'; import {AbstractHeaderPage} from "../page-object/abstract-header.po"; import {TaskOverviewPage} from "../page-object/task/task-overview.po"; +/** + * E2E-Test für grundsätzlichen Seitenzugriff und die Seitennavigation + * bezüglich AbstractPageHeader Implementierung + * + * @author FHartwich + */ describe('Access Projectmanager Homepage', function () { beforeEach(() => { diff --git a/project-manager/e2e/page-object/task/task-edit.po.ts b/project-manager/e2e/page-object/task/task-edit.po.ts index e49b231..463168f 100644 --- a/project-manager/e2e/page-object/task/task-edit.po.ts +++ b/project-manager/e2e/page-object/task/task-edit.po.ts @@ -2,19 +2,57 @@ import {AbstractHeaderPage} from "../abstract-header.po"; import {by, element} from "protractor"; import {TaskOverviewPage} from "./task-overview.po"; +/** + * PageObject Klasse, repräsentiert die Formularseite zum + * editieren und Erstellen von Aufgaben + * + * @author FHartwich + */ export class TaskEditPage extends AbstractHeaderPage { + /** + * Array mit möglichen Fehleranzeigen + * @type {{title: string; email: string}} + */ errorMessages = {title: 'Titel muss mindestens 5 Zeichen enthalten', email : 'Bitte geben Sie eine gültige E-Mail Adresse an'}; + /** + * Eingabefeld - Titel + * @type {ElementFinder} + */ titleInput = element(by.id('title')); + + /** + * Eingabefeld - Beschreibung + * @type {ElementFinder} + */ descriptionInput = element(by.id('description')); - statusDropdown = element(by.id('state')); - assigneeName = element(by.id('assignee_name')); + + /** + * Eingabefeld - Verantwortlicher, eMail + * @type {ElementFinder} + */ assigneeEmail = element(by.id('assignee_email')); + + /** + * Speichern - Button + * @type {ElementFinder} + */ saveButton = element(by.id('save')); + + /** + * Abbrechen - Button + * @type {ElementFinder} + */ cancelButton = element(by.id('cancel')); + + /** + * Konstruktor + * @param newTask - true, wenn die Seite für einen neuen Tasks geöffnet wird + * false, wenn ein Task editiert wird + */ constructor(newTask: boolean) { super(); let headline; @@ -26,47 +64,65 @@ export class TaskEditPage extends AbstractHeaderPage { super.validatePageHeadline(headline) } + /** + * Löscht alten Titel und gibt neuen ein + * @param title - neuer Titel + */ clearEnterTitle(title: string) { - this.titleInput.clear(); this.titleInput.sendKeys(title); } + /** + * Löscht alte Beschreibung und gibt neue ein + * @param description - neue Beschreibung + */ clearEnterDescription(description: string) { this.descriptionInput.clear(); this.descriptionInput.sendKeys(description); } - setStatus(state: string) { - this.statusDropdown.element(by.css('[value="${state}"]')) - .click()// -> Höller, Christoph - Angular, S. 562 - Listing 14.12 - } - - clearInsertName(name: string) { - this.assigneeName.clear(); - this.assigneeName.sendKeys(name); - } - + /** + * Löscht alte Assignee eMail und trägt neue ein + * @param email - neue eMail Adresse + */ clearInsertEmail(email: string) { this.assigneeEmail.clear(); this.assigneeEmail.sendKeys(email); } + /** + * Klick auf den Button zum absenden des Formulars + * @returns {TaskOverviewPage} + */ submitTaskForm() { this.saveButton.click(); return new TaskOverviewPage; } + /** + * Klick auf den Button zum Abbrechen der Formulareingabe + * @returns {TaskOverviewPage} + */ cancelSubmitTask() : TaskOverviewPage { this.cancelButton.click(); return new TaskOverviewPage(); } + /** + * überprüft den Feldwert des über die ID beschriebenen Elements + * @param elementId - CSS ID des Testfeldes + * @param value - erwarteter Wert + */ static validateInput(elementId: string, value: string) { const input = element(by.id(elementId)); expect(input.getAttribute('value')).toBe(value); } + /** + * prüft ob ein Error existiert der diesen Wert hat + * @param input - erwartete Fehlermeldung + */ validateError(input: string) { expect(element(by.className('alert')).getText()) .toBe(this.errorMessages[input]); diff --git a/project-manager/e2e/page-object/task/task-overview.po.ts b/project-manager/e2e/page-object/task/task-overview.po.ts index 13a99d6..45c9c56 100644 --- a/project-manager/e2e/page-object/task/task-overview.po.ts +++ b/project-manager/e2e/page-object/task/task-overview.po.ts @@ -2,11 +2,26 @@ import {AbstractHeaderPage} from "../abstract-header.po"; import {browser, by, element, ElementArrayFinder, ElementFinder, ExpectedConditions} from "protractor"; import {TaskEditPage} from "./task-edit.po"; +/** + * PageObject Klasse als Repräösentation der Aufgabenübersichts-Seite + * + * @author FHartwich + */ export class TaskOverviewPage extends AbstractHeaderPage { + /** + * Button zum Anlegen einer neuen Aufgabe + */ neueAufgabeBtn: ElementFinder; + + /** + * Liste aller Einträge + */ taskEntries: ElementArrayFinder; + /** + * Konstruktor + */ constructor() { super(); super.validatePageHeadline('Aufgaben durchsuchen'); @@ -14,21 +29,39 @@ export class TaskOverviewPage extends AbstractHeaderPage { this.taskEntries = element.all(by.className('task-list-entry')); } + /** + * Prüft den Wert im Suchfeld + * @param value - erwarteter Wert + */ validateSearchFieldValue(value: string) { const inputField = element(by.id('search-tasks')); expect(inputField.getAttribute('value')).toEqual(value); } + /** + * Klick auf den Button zum Erstellen einer neuen Aufgabe + * @returns {TaskEditPage} + */ clickNeueAufgabe(): TaskEditPage { this.neueAufgabeBtn.click(); return new TaskEditPage(true); } + /** + * validiert dass ein Task mit gegebenen Titel in der Liste + * vorhanden ist + * @param title - erwarteter Titel + */ verifyNewTask(title: string) { const newEntry = element(by.linkText(title)); browser.wait(ExpectedConditions.presenceOf(newEntry)); } + /** + * Klick auf den Link einer Aufgabe mit gegebenen Titel + * @param title - Titel der Aufgabe + * @returns {TaskEditPage} + */ clickTask(title: string) { const entry = element(by.linkText(title)); entry.click(); diff --git a/project-manager/e2e/task/create-new-task.e2e-spec.ts b/project-manager/e2e/task/create-new-task.e2e-spec.ts index aaff394..fc36391 100644 --- a/project-manager/e2e/task/create-new-task.e2e-spec.ts +++ b/project-manager/e2e/task/create-new-task.e2e-spec.ts @@ -3,7 +3,7 @@ import {TaskOverviewPage} from "../page-object/task/task-overview.po"; import {TaskEditPage} from "../page-object/task/task-edit.po"; /** - * E2E Testsuite für seitenübergreifende + * E2E Test für seitenübergreifende * Interaktionen beim Erstellen einer neuen Aufagbe * * @author FHartwich diff --git a/project-manager/projects-server/test.json b/project-manager/projects-server/test.json index 568c627..7506597 100644 --- a/project-manager/projects-server/test.json +++ b/project-manager/projects-server/test.json @@ -2,7 +2,7 @@ "tasks": [ { "id": 3, - "title": "Ersten Prototyp mit Angular 4.0 entwickelt", + "title": "Ersten Prototyp mit Angular 2.0 entwickeln", "description": "Der Prototyp soll zeigen, wie Routing und HTTP-Anbindung umgesetzt werden können.", "tags": [], "state": "IN_PROGRESS", @@ -57,15 +57,6 @@ "state": "IN_PROGRESS", "title": "New Task", "id": 9 - }, - { - "assignee": { - "email": "testuser@test.com" - }, - "tags": [], - "state": "BACKLOG", - "title": "valid title", - "id": 10 } ] } \ No newline at end of file diff --git a/project-manager/src/app/blog/blog-entry/blog-entry.component.spec.ts b/project-manager/src/app/blog/blog-entry/blog-entry.component.spec.ts index bad0a61..7285351 100644 --- a/project-manager/src/app/blog/blog-entry/blog-entry.component.spec.ts +++ b/project-manager/src/app/blog/blog-entry/blog-entry.component.spec.ts @@ -5,6 +5,12 @@ import {BlogComponent} from "../blog.component"; import {RouterTestingModule} from "@angular/router/testing"; import {MockBlogComponent} from "../../mocks/mock-blog.component"; +/** + * Test für die Klasse BlogEntryComponent + * isoliert und in Abhängigkeit zu BlogComponent + * + * @author FHartwich + */ describe('Blog Entry Isolated Test', () => { describe('Isolated Test', () => { diff --git a/project-manager/src/app/blog/blog.component.spec.ts b/project-manager/src/app/blog/blog.component.spec.ts index a3a8e18..d3c72f9 100644 --- a/project-manager/src/app/blog/blog.component.spec.ts +++ b/project-manager/src/app/blog/blog.component.spec.ts @@ -1,11 +1,17 @@ -import {BlogComponent} from './blog.component' -import {async, inject, TestBed} from "@angular/core/testing"; +import {BlogComponent} from "./blog.component"; +import {async, TestBed} from "@angular/core/testing"; import {RouterTestingModule} from "@angular/router/testing"; -import {Component, CUSTOM_ELEMENTS_SCHEMA} from "@angular/core"; +import {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core"; import {By} from "@angular/platform-browser"; -import {BlogEntryComponent} from "./blog-entry/blog-entry.component";; -import {Router} from "@angular/router/router"; +import {BlogEntryComponent} from "./blog-entry/blog-entry.component"; +; +/** + * Test für die BlogComponent Klasse, z.T.mit + * sich wiederholenden Tesfällen, verschiedenen Kontextumfangs + * + * @author FHartwich + */ describe('Blog Component', () => { describe('Isolated Component Test', () => { @@ -15,10 +21,10 @@ describe('Blog Component', () => { TestBed.configureTestingModule({ imports: [RouterTestingModule.withRoutes([])], declarations: [BlogComponent] - }); + }); }); - beforeEach(async(()=> { + beforeEach(async(() => { TestBed.overrideComponent(BlogComponent, {set: {template: ''}}); blogComponent = TestBed.createComponent(BlogComponent).componentInstance; })); diff --git a/project-manager/src/app/login/login.component.spec.ts b/project-manager/src/app/login/login.component.spec.ts index f6ed848..6b19eb9 100644 --- a/project-manager/src/app/login/login.component.spec.ts +++ b/project-manager/src/app/login/login.component.spec.ts @@ -6,7 +6,12 @@ import {FormsModule} from "@angular/forms"; import {MockLoginService} from "../mocks/mock-login-service"; import Spy = jasmine.Spy; - +/** + * Test für die LoginComponent Klasse + * für Formulareingabe und Service Interaktion + * + * @author FHartwich + */ describe('Login Component UI Driven Form Test with Spy', () => { beforeEach(() => { diff --git a/project-manager/src/app/mocks/mock-blog.component.ts b/project-manager/src/app/mocks/mock-blog.component.ts index d6451a6..9a7569d 100644 --- a/project-manager/src/app/mocks/mock-blog.component.ts +++ b/project-manager/src/app/mocks/mock-blog.component.ts @@ -1,5 +1,12 @@ import {Component} from "@angular/core"; +/** + * Gemockte Klasse basierend auf BlogComponent, + * die lediglich die Directive und zwei minimal-Einträge + * des BlogEntry zur Interaktion bereitstellt + * + * @author FHartwich + */ @Component({ selector: 'blog', template: '' diff --git a/project-manager/src/app/mocks/mock-login-service.ts b/project-manager/src/app/mocks/mock-login-service.ts index 2e2796b..82c5533 100644 --- a/project-manager/src/app/mocks/mock-login-service.ts +++ b/project-manager/src/app/mocks/mock-login-service.ts @@ -1,5 +1,12 @@ +/** + * Klasse mit einzelner, leerer Methode + * als Mock zum Testen der Service-Interaktion + * + * @author FHartwich + */ export class MockLoginService { - login(name, password) {}; + login(name, password) { + }; } diff --git a/project-manager/src/app/mocks/mock-task-item.component.ts b/project-manager/src/app/mocks/mock-task-item.component.ts index 3ad38bd..30f825b 100644 --- a/project-manager/src/app/mocks/mock-task-item.component.ts +++ b/project-manager/src/app/mocks/mock-task-item.component.ts @@ -1,5 +1,11 @@ import {Component} from "@angular/core"; +/** + * Mock für die TaskItemComponent + * zur Nutzung als leere Klasse ohne Interaktion + * + * @author FHartwich + */ @Component({ selector: 'pjm-task-item', template: '', diff --git a/project-manager/src/app/model-driven-form/model-driven-form.component.spec.ts b/project-manager/src/app/model-driven-form/model-driven-form.component.spec.ts index 5d0c72b..18bc9dc 100644 --- a/project-manager/src/app/model-driven-form/model-driven-form.component.spec.ts +++ b/project-manager/src/app/model-driven-form/model-driven-form.component.spec.ts @@ -1,11 +1,18 @@ -import {FormGroup, ReactiveFormsModule} from '@angular/forms'; -import {TestBed} from '@angular/core/testing'; -import {ModelDrivenFormComponent} from './model-driven-form.component'; -import {UserService} from '../services/user-service/user.service'; +import {FormGroup, ReactiveFormsModule} from "@angular/forms"; +import {TestBed} from "@angular/core/testing"; +import {ModelDrivenFormComponent} from "./model-driven-form.component"; +import {UserService} from "../services/user-service/user.service"; import {TaskServiceModelForm} from "../services/task-service/task-model-form.service"; import {ShowErrorComponentModelDriven} from "../show-error/show-error-model-driven.component"; import {generateRandomString} from "../test/test.helper"; + +/** + * Test für die ModelDrivenFormComponent mit Interaktion + * auf Grundlage des Modell-Getriebenen-Formulars (FormGroup) + * + * @author FHartwich + */ describe('Model Driven Form', () => { // ModelDrivenFormComponent Fixture diff --git a/project-manager/src/app/services/login-service/login.service.spec.ts b/project-manager/src/app/services/login-service/login.service.spec.ts index 8fa0438..60dc0c1 100644 --- a/project-manager/src/app/services/login-service/login.service.spec.ts +++ b/project-manager/src/app/services/login-service/login.service.spec.ts @@ -7,8 +7,11 @@ import {LoginService} from "./login-service"; import {UserStore} from "../stores/user.store"; /** + * Test für die LoginService Klasse * Initialisierung und Durchführung nach Vorlage aus dem * TaskService Tests (../task-service/task.service.spec.ts) von Christoph Höller + * + * @author FHartwich */ describe('Login-Service', () => { beforeEach(() => { @@ -47,7 +50,7 @@ describe('Login-Service', () => { const expectedUrl = 'http://localhost:3000/api/users?name=admin'; expect(connection.request.url).toBe(expectedUrl); expect(connection.request.method).toBe(RequestMethod.Get); - const response = new ResponseOptions({body: JSON.stringify(user)}); + const response = new ResponseOptions({body: JSON.stringify(user)}); connection.mockRespond(new Response(response)); }); loginService.getUser('admin'); diff --git a/project-manager/src/app/tasks/edit-task/edit-task.component.spec.ts b/project-manager/src/app/tasks/edit-task/edit-task.component.spec.ts index 95a518e..75d6882 100644 --- a/project-manager/src/app/tasks/edit-task/edit-task.component.spec.ts +++ b/project-manager/src/app/tasks/edit-task/edit-task.component.spec.ts @@ -1,14 +1,22 @@ -import {TaskService} from '../../services/task-service/task.service'; -import {RouterTestingModule} from '@angular/router/testing'; -import {TestBed} from '@angular/core/testing'; -import {EditTaskComponent} from './edit-task.component'; -import {ShowErrorComponent} from '../../show-error/show-error.component'; -import {APPLICATION_VALIDATORS} from '../../models/app-validators'; -import {Title} from '@angular/platform-browser'; -import {FormsModule} from '@angular/forms'; -import {MockTaskService} from '../../mocks/mock-task-service'; +import {TaskService} from "../../services/task-service/task.service"; +import {RouterTestingModule} from "@angular/router/testing"; +import {TestBed} from "@angular/core/testing"; +import {EditTaskComponent} from "./edit-task.component"; +import {ShowErrorComponent} from "../../show-error/show-error.component"; +import {APPLICATION_VALIDATORS} from "../../models/app-validators"; +import {Title} from "@angular/platform-browser"; +import {FormsModule} from "@angular/forms"; +import {MockTaskService} from "../../mocks/mock-task-service"; import {generateRandomString} from "../../test/test.helper"; + +/** + * Test für die Klasse EditTaskComponent + * zur Prüfung von Formularinteraktion auf Grundlage + * eines Template-Getriebenen-Formulars + * + * @author FHartwich + */ describe('EditTask Component', () => { describe('Template Driven Form API-based Test', () => { diff --git a/project-manager/src/app/tasks/task-list/task-list.component.spec.ts b/project-manager/src/app/tasks/task-list/task-list.component.spec.ts index 2a26724..427330f 100644 --- a/project-manager/src/app/tasks/task-list/task-list.component.spec.ts +++ b/project-manager/src/app/tasks/task-list/task-list.component.spec.ts @@ -1,14 +1,20 @@ -import {async, TestBed} from "@angular/core/testing"; +import {async, inject, TestBed} from "@angular/core/testing"; import {Router} from "@angular/router"; import {ReactiveFormsModule} from "@angular/forms"; -import {inject} from "@angular/core/testing"; import {TaskListComponent} from "./task-list.component"; import {RouterTestingModule} from "@angular/router/testing"; import {MockTaskService} from "../../mocks/mock-task-service"; import {TaskService} from "../../services/task-service/task.service"; -import {MockTaskItemComponent} from '../../mocks/mock-task-item.component' +import {MockTaskItemComponent} from "../../mocks/mock-task-item.component"; -describe('Task Overview Component Routing', () => { + +/** + * Test der TaskListComponent + * im Hinblick auf die Router-Iteraktion + * + * @author FHartwich + */ +describe('Task List Component Routing', () => { let component: TaskListComponent; let fixture; @@ -17,7 +23,7 @@ describe('Task Overview Component Routing', () => { TestBed.configureTestingModule({ imports: [ReactiveFormsModule, RouterTestingModule.withRoutes([])], declarations: [TaskListComponent, MockTaskItemComponent], - providers: [ {provide: TaskService, useClass: MockTaskService} ] + providers: [{provide: TaskService, useClass: MockTaskService}] }); fixture = TestBed.createComponent(TaskListComponent); component = fixture.componentInstance; @@ -29,7 +35,7 @@ describe('Task Overview Component Routing', () => { }) ); - it('should call Router.navigate with id to open quickedit ',() => { + it('should call Router.navigate with id to open quickedit ', () => { fixture.whenStable().then(() => { let taskId = 12; let spyNavigation = spyOn(router, 'navigate'); @@ -37,7 +43,7 @@ describe('Task Overview Component Routing', () => { component.selectTask(taskId); expect(spyNavigation).toHaveBeenCalled(); expect(spyNavigation.calls.first().args[0]) - .toContain({outlets: {'right': ['overview', taskId]}}); + .toContain({outlets: {'right': ['overview', taskId]}}); }); });