-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from marc101101/feature/testing
Feature/testing
- Loading branch information
Showing
36 changed files
with
98,309 additions
and
2,770 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
client/app/components/home/categories/categories.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { async, TestBed, fakeAsync, tick } from '@angular/core/testing'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { AlertService } from '../../../services/alert.service'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { SharedModule } from '../../../sharedModule/shared.module'; | ||
import { Observable, of } from 'rxjs'; | ||
import 'rxjs/add/observable/from'; | ||
import { CategoryService } from '../../../services/category.service'; | ||
import { CommunicationService } from '../shared/communication.service'; | ||
import { CategoriesComponent } from './categories.component'; | ||
import {Location} from "@angular/common"; | ||
|
||
|
||
|
||
/** | ||
* Test should test all four methods of courses.component.ts | ||
* ngOnInit() / routeToCourse() | ||
**/ | ||
describe('CategoriesComponent', () => { | ||
let categoriesModel = [{ | ||
"KURS_NAME":"Test Kurs", | ||
"KURS_BESCHREIBUNG": "Test Kurs Beschreibung" | ||
}]; | ||
|
||
var fixture; | ||
var component; | ||
var categoryService: CategoryService; | ||
var location; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ CategoriesComponent ], | ||
imports: [ HttpClientModule, RouterTestingModule, SharedModule ], | ||
providers: [ CategoryService, AlertService, CommunicationService, Location], | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(CategoriesComponent); | ||
component = fixture.componentInstance; | ||
categoryService = fixture.debugElement.injector.get(CategoryService); | ||
location = TestBed.get(Location); | ||
})); | ||
|
||
it('CategoriesComponent: should successfuly be able to create a CategoriesComponent', () => { | ||
expect(fixture.componentInstance instanceof CategoriesComponent).toBe(true, "should create CategoriesComponent"); | ||
}); | ||
|
||
//test ngOnit methods and check its effects by mocking userService method getUserMe | ||
it("CategoriesComponent: ngOnit() sets categories and dataIsAvailable values correctly", fakeAsync(() => { | ||
//set preconditions | ||
spyOn(categoryService, "getAllCategories").and.returnValue(Observable.of(categoriesModel)); | ||
//call testing method | ||
component.ngOnInit(); | ||
//check results | ||
fixture.detectChanges(); | ||
expect(component.categories).toBe(categoriesModel); | ||
expect(component.dataIsAvailable).toBe(true); | ||
})); | ||
|
||
it('CategoriesComponent: navigate to course(id: 1111) redirects you to /#/home/kurs-uebersicht/1111', fakeAsync(() => { | ||
component.routeToCourse("1111", "primary"); | ||
tick(50); | ||
expect(location._platformStrategy.internalPath).toBe('/#/home/kurs-uebersicht/1111'); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
client/app/components/home/contact/contact.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { async, TestBed, fakeAsync } from '@angular/core/testing'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { AlertService } from '../../../services/alert.service'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { SharedModule } from '../../../sharedModule/shared.module'; | ||
import { Observable, of } from 'rxjs'; | ||
import 'rxjs/add/observable/from'; | ||
import { CommunicationService } from '../shared/communication.service'; | ||
import { CoursesService } from '../shared/courses.service'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { ContactService } from '../shared/contact.service'; | ||
import { ContactComponent } from './contact.component'; | ||
import { FormsModule } from '@angular/forms'; | ||
|
||
|
||
/** | ||
* Test should test all four methods of contact.component.ts | ||
* ngOnit() / submit() | ||
**/ | ||
describe('ContactComponent', () => { | ||
|
||
let coursesByCourseIdModel = { | ||
"ANM_DATUM": Date.now(), | ||
"KURS_NAME": "Testname", | ||
"KURS_BESCHREIBUNG": "Testbeschreibung" | ||
}; | ||
|
||
var fixture; | ||
var component; | ||
var coursesService: CoursesService; | ||
var contactService: ContactService; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ ContactComponent ], | ||
imports: [ HttpClientModule, RouterTestingModule, SharedModule, FormsModule ], | ||
providers: [ | ||
AlertService, | ||
CommunicationService, | ||
ContactService, | ||
CoursesService, | ||
{ | ||
provide: ActivatedRoute, | ||
useValue: { | ||
params: Observable.of({ id: 'test-id' }) | ||
} | ||
}], | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ContactComponent); | ||
component = fixture.componentInstance; | ||
coursesService = fixture.debugElement.injector.get(CoursesService); | ||
contactService = fixture.debugElement.injector.get(ContactService); | ||
})); | ||
|
||
it('ContactComponent: should successfuly be able to create a ContactComponent and check ngOninit', () => { | ||
//set preconditions | ||
component.activatedRoute.params.value.id = "test-id"; | ||
//spyOn(userService, "getCoursesByUser").and.returnValue(Observable.of(userCoursesModel)); | ||
spyOn(coursesService, "getCoursesByCourseId").and.returnValue(Observable.of(coursesByCourseIdModel)); | ||
//call testing method | ||
component.ngOnInit(); | ||
//check results | ||
fixture.detectChanges(); | ||
expect(component.single_course).toBe(coursesByCourseIdModel); | ||
expect(component.headerText).toBe("Bewertung: " + component.single_course.KURS_NAME); | ||
expect(component.course_feedback).toBe(true); | ||
expect(fixture.componentInstance instanceof ContactComponent).toBe(true, "should create ContactComponent"); | ||
}); | ||
|
||
it('ContactComponent: should successfuly submit feedback for course', () => { | ||
//set preconditions | ||
component.course_feedback = true; | ||
component.single_course = {"KURS_ID": 1234}; | ||
//spyOn(userService, "getCoursesByUser").and.returnValue(Observable.of(userCoursesModel)); | ||
spyOn(coursesService, "postFeedbackByCourse").and.returnValue(Observable.of(coursesByCourseIdModel)); | ||
//call testing method | ||
component.submit(); | ||
//check results | ||
fixture.detectChanges(); | ||
expect(component.button_text).toBe("Senden erfolgreich"); | ||
}); | ||
|
||
it('ContactComponent: should successfuly submit feedback for app in general', () => { | ||
//set preconditions | ||
component.course_feedback = false; | ||
//spyOn(userService, "getCoursesByUser").and.returnValue(Observable.of(userCoursesModel)); | ||
spyOn(contactService, "postContactFeedback").and.returnValue(Observable.of(coursesByCourseIdModel)); | ||
//call testing method | ||
component.submit(); | ||
//check results | ||
fixture.detectChanges(); | ||
expect(component.button_text).toBe("Senden erfolgreich"); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
client/app/components/home/courses/courses.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { async, TestBed, fakeAsync } from '@angular/core/testing'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { AlertService } from '../../../services/alert.service'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { SharedModule } from '../../../sharedModule/shared.module'; | ||
import { Observable, of } from 'rxjs'; | ||
import 'rxjs/add/observable/from'; | ||
import { CoursesComponent } from './courses.component'; | ||
import { CommunicationService } from '../shared/communication.service'; | ||
import { UserService } from '../../../services/user.service'; | ||
import { CoursesService } from '../shared/courses.service'; | ||
import { CategoryService } from '../../../services/category.service'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
|
||
|
||
/** | ||
* Test should test all four methods of courses.component.ts | ||
* requestCoursesByUser() / requestCoursesByCategory() | ||
**/ | ||
describe('CoursesComponent', () => { | ||
let userCoursesModel = [ | ||
{ | ||
"ANM_KURS_ID": 1, | ||
"ANM_DATUM": Date.now() | ||
}, | ||
{ | ||
"ANM_KURS_ID": 2, | ||
"ANM_DATUM": Date.now() | ||
} | ||
]; | ||
|
||
let coursesByCourseIdModel = { | ||
"ANM_DATUM": Date.now(), | ||
"KURS_NAME": "Testname", | ||
"KURS_BESCHREIBUNG": "Testbeschreibung" | ||
}; | ||
|
||
var fixture; | ||
var component; | ||
var userService: UserService; | ||
var coursesService: CoursesService; | ||
var categoryService: CategoryService; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ CoursesComponent ], | ||
imports: [ HttpClientModule, RouterTestingModule, SharedModule ], | ||
providers: [ | ||
CategoryService, | ||
AlertService, | ||
CommunicationService, | ||
UserService, | ||
CoursesService, | ||
{ | ||
provide: ActivatedRoute, | ||
useValue: { | ||
params: Observable.of({ id: 'me' }) | ||
} | ||
}], | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(CoursesComponent); | ||
component = fixture.componentInstance; | ||
userService = fixture.debugElement.injector.get(UserService); | ||
coursesService = fixture.debugElement.injector.get(CoursesService); | ||
categoryService = fixture.debugElement.injector.get(CategoryService); | ||
})); | ||
|
||
it('CoursesComponent: should successfuly be able to create a CoursesComponent', () => { | ||
expect(fixture.componentInstance instanceof CoursesComponent).toBe(true, "should create CoursesComponent"); | ||
}); | ||
|
||
//test ngOnit methods and check its effects by mocking userService method getUserMe | ||
it("CoursesComponent /me: ngOnit() sets courses and dataIsAvailable values correctly", fakeAsync(() => { | ||
//set preconditions | ||
component.activatedRoute.params.value.id = "me"; | ||
spyOn(userService, "getCoursesByUser").and.returnValue(Observable.of(userCoursesModel)); | ||
spyOn(coursesService, "getCoursesByCourseId").and.returnValue(Observable.of(coursesByCourseIdModel)); | ||
//call testing method | ||
component.ngOnInit(); | ||
//check results | ||
fixture.detectChanges(); | ||
expect(component.courses[0].KURS_BESCHREIBUNG).toBe("Testbeschreibung"); | ||
expect(component.courses[0].KURS_NAME).toBe("Testname"); | ||
expect(component.dataIsAvailable).toBe(true); | ||
})); | ||
|
||
//test ngOnit methods and check its effects by mocking userService method getUserMe | ||
it("CoursesComponent /:kursId: ngOnit() sets courses and dataIsAvailable values correctly", fakeAsync(() => { | ||
//here a different test bed is needed because the ActivatedRoute is /1111 | ||
component.category = "Test Category"; | ||
component.activatedRoute.params.value.id = "test-kursId"; | ||
//set preconditions | ||
spyOn(categoryService, "getCoursesByCategoryId").and.returnValue(Observable.of([coursesByCourseIdModel])); | ||
//call testing method | ||
component.ngOnInit(); | ||
//check results | ||
fixture.detectChanges(); | ||
expect(component.courses[0].KURS_BESCHREIBUNG).toBe("Testbeschreibung"); | ||
expect(component.courses[0].KURS_NAME).toBe("Testname"); | ||
expect(component.dataIsAvailable).toBe(true); | ||
})); | ||
|
||
//test ngOnit methods and check its effects by mocking userService method getUserMe | ||
it("CoursesComponent /highlights: ngOnit() sets courses and dataIsAvailable values correctly", fakeAsync(() => { | ||
//here a different test bed is needed because the ActivatedRoute is /1111 | ||
component.category = "Test Category"; | ||
component.activatedRoute.params.value.id = "highlights"; | ||
//set preconditions | ||
spyOn(coursesService, "getCoursesByHighlight").and.returnValue(Observable.of([coursesByCourseIdModel])); | ||
//call testing method | ||
component.ngOnInit(); | ||
//check results | ||
fixture.detectChanges(); | ||
expect(component.courses[0].KURS_BESCHREIBUNG).toBe("Testbeschreibung"); | ||
expect(component.courses[0].KURS_NAME).toBe("Testname"); | ||
expect(component.dataIsAvailable).toBe(true); | ||
})); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.