diff --git a/project-manager/e2e/page-object/abstract-header.po.ts b/project-manager/e2e/page-object/abstract-header.po.ts index d809747..664a4ad 100644 --- a/project-manager/e2e/page-object/abstract-header.po.ts +++ b/project-manager/e2e/page-object/abstract-header.po.ts @@ -1,23 +1,42 @@ import {element, by} from "protractor"; import {AbstractPage} from "./abstract-page.po"; +/** + * PageObject Klasse zur Repräsentation jeder + * Seite mit Navigations Header und weiteren Router-Outlets + * + * @author FHartwich + */ export class AbstractHeaderPage extends AbstractPage { + /** + * Überschrift auf der Seite + * @type {ElementFinder} + */ + head = element(by.css('h1')); + + /** + * Schnellzugriff Dropdown Button + * @type {ElementFinder} + */ + schnellzugriffBtn = element(by.className('dropdown')); + + /** + * Validierung der gegebenen Seiten-Überschrift + * @param headline - zu validierende Überschrift + */ validatePageHeadline(headline: string) { - const head = element(by.css('h1')); - expect(head.getText()).toBe(headline); - } - - clickBrandLink(linkText: string) { - const headerEntry = element(by.linkText(linkText)); - headerEntry.click() + expect(this.head.getText()).toBe(headline); } + /** + * Klick auf ein Element im Schnellzugriff Dropdown + * @param linkText - Link-Bezeichnung aus dem Menü + */ clickSchnellzugriffFollowedBy(linkText: string) { // starts with css Selector: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors - const schnellzugriffBtn = element(by.className('dropdown')); - schnellzugriffBtn.click(); - schnellzugriffBtn.element(by.linkText(linkText)).click(); + this.schnellzugriffBtn.click(); + this.schnellzugriffBtn.element(by.linkText(linkText)).click(); } } diff --git a/project-manager/e2e/page-object/abstract-page.po.ts b/project-manager/e2e/page-object/abstract-page.po.ts index d4125d3..f6de299 100644 --- a/project-manager/e2e/page-object/abstract-page.po.ts +++ b/project-manager/e2e/page-object/abstract-page.po.ts @@ -1,9 +1,23 @@ import {browser} from "protractor"; +/** + * PageObject Klasse, als Grundlage für Browserinteraktion + * + * @author FHartwich + */ export class AbstractPage { + /** + * baseUrl aus der Protractor Konfiguration + * @type {string} + */ baseUrl: string = browser.baseUrl + '/'; + /** + * prüft ob die aktuelle URL mit dem gegebene Pfad + * übereinstimmt + * @param urlEnding - URL Appendix + */ validateCurrentUrl(urlEnding: string) { expect(browser.getCurrentUrl()).toBe(this.baseUrl + urlEnding); } 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 74eeb3b..aaff394 100644 --- a/project-manager/e2e/task/create-new-task.e2e-spec.ts +++ b/project-manager/e2e/task/create-new-task.e2e-spec.ts @@ -2,6 +2,12 @@ import {browser} from 'protractor'; import {TaskOverviewPage} from "../page-object/task/task-overview.po"; import {TaskEditPage} from "../page-object/task/task-edit.po"; +/** + * E2E Testsuite für seitenübergreifende + * Interaktionen beim Erstellen einer neuen Aufagbe + * + * @author FHartwich + */ describe('Create New Task Form', function () { it('should redirect to "New Task Form" and contain new entry in list after creation with valid title and assignee-email', () => { @@ -24,7 +30,6 @@ describe('Create New Task Form', function () { const taskEditPage = new TaskEditPage(true); taskEditPage.clearEnterTitle(testTitle); taskEditPage.clearEnterDescription(''); - browser.pause(); taskEditPage.validateError('title'); }); diff --git a/project-manager/e2e/task/edit-task.e2e-spec.ts b/project-manager/e2e/task/edit-task.e2e-spec.ts index 46c6bbc..2ec7f01 100644 --- a/project-manager/e2e/task/edit-task.e2e-spec.ts +++ b/project-manager/e2e/task/edit-task.e2e-spec.ts @@ -2,6 +2,13 @@ import {browser} from 'protractor'; import {TaskOverviewPage} from "../page-object/task/task-overview.po"; import {TaskEditPage} from "../page-object/task/task-edit.po"; + +/** + * E2E Test für die seitenübergreifende Interaktion beim + * Bearbeiten von Aufgaben + * + * @author FHartwich + */ describe('Edit Task Form', function () { const dbTask = { diff --git a/project-manager/projects-server/test.json b/project-manager/projects-server/test.json index 7506597..568c627 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 2.0 entwickeln", + "title": "Ersten Prototyp mit Angular 4.0 entwickelt", "description": "Der Prototyp soll zeigen, wie Routing und HTTP-Anbindung umgesetzt werden können.", "tags": [], "state": "IN_PROGRESS", @@ -57,6 +57,15 @@ "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/mocks/mock-task-item.component.ts b/project-manager/src/app/mocks/mock-task-item.component.ts new file mode 100644 index 0000000..3ad38bd --- /dev/null +++ b/project-manager/src/app/mocks/mock-task-item.component.ts @@ -0,0 +1,11 @@ +import {Component} from "@angular/core"; + +@Component({ + selector: 'pjm-task-item', + template: '', + inputs: ['task', 'selected'], + outputs: ['taskSelected', 'taskDelete'], +}) +export class MockTaskItemComponent { + +} 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 72541e4..95a518e 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,17 +1,10 @@ import {TaskService} from '../../services/task-service/task.service'; - import {RouterTestingModule} from '@angular/router/testing'; - -import {BehaviorSubject} from 'rxjs/BehaviorSubject'; - -import {TestBed, inject} from '@angular/core/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 {ActivatedRoute, Router} from '@angular/router'; -import {fakeAsync, tick} from '@angular/core/testing'; import {Title} from '@angular/platform-browser'; -import {Component} from '@angular/core'; import {FormsModule} from '@angular/forms'; import {MockTaskService} from '../../mocks/mock-task-service'; import {generateRandomString} from "../../test/test.helper"; @@ -112,91 +105,4 @@ describe('EditTask Component', () => { }); - /** - * Hinweis: Die folgende TestSuite entstammt dem ursprünglichen edit-task.component.spec.ts Tests - * dieses Projektes und ist geistiges Eigentum vom Chritoph Höller, dem Ersteller des Ausgangsprojektes - */ - describe('Routing', () => { - - @Component({ - template: '' - }) - class TestComponent { - } - - let taskService: TaskService; - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [FormsModule, RouterTestingModule.withRoutes([ - {path: 'new', component: EditTaskComponent}, - {path: 'edit/:id', component: EditTaskComponent} - ], - )], - declarations: [EditTaskComponent, ShowErrorComponent, APPLICATION_VALIDATORS, TestComponent], - providers: [ - Title, - {provide: TaskService, useClass: MockTaskService}, - ] - }); - }); - - beforeEach(inject([TaskService], (_taskService) => { - taskService = _taskService; - })); - - it('should load the correct task in Edit-Mode', fakeAsync(() => { - const fixture = TestBed.createComponent(EditTaskComponent); - const route = TestBed.get(ActivatedRoute); - (route.params).next({id: '42'}); - - const element = fixture.nativeElement; - - const spy = spyOn(taskService, 'getTask'); - const fakeTask = {title: 'Task1', assignee: {name: 'John'}}; - spy.and.returnValue(new BehaviorSubject(fakeTask)); - - fixture.autoDetectChanges(true); - fixture.whenStable().then(() => { - tick(); - expect(spy).toHaveBeenCalledWith('42'); - const titleInput = element.querySelector('#title'); - expect(titleInput.value).toBe(fakeTask.title); - - const assigneeInput = element.querySelector('#assignee_name'); - expect(assigneeInput.value).toBe(fakeTask.assignee.name); - }); - })); - - - it('should load the correct task (with router)', fakeAsync(() => { - const fixture = TestBed.createComponent(TestComponent); - const router = TestBed.get(Router); - router.navigateByUrl('edit/42'); - - const spy = spyOn(taskService, 'getTask'); - const fakeTask = {title: 'Task1', assignee: {name: 'John'}}; - spy.and.returnValue(new BehaviorSubject(fakeTask)); - fixture.whenStable().then(() => { - tick(); - expect(spy).toHaveBeenCalledWith('42'); - const titleInput = fixture.nativeElement.querySelector('#title'); - expect(titleInput.value).toBe(fakeTask.title); - }); - })); - - it('should work without passing URL-Parameter', fakeAsync(() => { - const fixture = TestBed.createComponent(TestComponent); - const router = TestBed.get(Router); - router.navigateByUrl('new'); - const spy = spyOn(taskService, 'getTask'); - fixture.whenStable().then(() => { - tick(); - expect(spy).not.toHaveBeenCalled(); - const titleInput = fixture.nativeElement.querySelector('#title'); - expect(titleInput.value).toBe(''); - }); - })); - }); - }); diff --git a/project-manager/src/app/tasks/task-list/task-overview.component.spec.ts b/project-manager/src/app/tasks/task-list/task-list.component.spec.ts similarity index 90% rename from project-manager/src/app/tasks/task-list/task-overview.component.spec.ts rename to project-manager/src/app/tasks/task-list/task-list.component.spec.ts index 3b08404..2a26724 100644 --- a/project-manager/src/app/tasks/task-list/task-overview.component.spec.ts +++ b/project-manager/src/app/tasks/task-list/task-list.component.spec.ts @@ -3,24 +3,21 @@ import {Router} from "@angular/router"; import {ReactiveFormsModule} from "@angular/forms"; import {inject} from "@angular/core/testing"; import {TaskListComponent} from "./task-list.component"; -import {TaskItemComponent} from "./task-item.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' describe('Task Overview Component Routing', () => { + let component: TaskListComponent; let fixture; let router; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ReactiveFormsModule, RouterTestingModule.withRoutes([])], - declarations: [TaskListComponent, TaskItemComponent], - providers: [ {provide: TaskService, useClass: MockTaskService} - ] + declarations: [TaskListComponent, MockTaskItemComponent], + providers: [ {provide: TaskService, useClass: MockTaskService} ] }); fixture = TestBed.createComponent(TaskListComponent); component = fixture.componentInstance; @@ -35,7 +32,6 @@ describe('Task Overview Component Routing', () => { it('should call Router.navigate with id to open quickedit ',() => { fixture.whenStable().then(() => { let taskId = 12; - let spyNavigation = spyOn(router, 'navigate'); component.selectTask(taskId);