This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit b6b5018c authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

My first jest-Test :-). And some minor cleanup

parent e8c5cac0
2 merge requests!188Merging Peer Reviewing et. al to Master,!164211 peer reviewing functionality
...@@ -6,7 +6,6 @@ import { ProfileInfo } from 'app/layouts/profiles/profile-info.model'; ...@@ -6,7 +6,6 @@ import { ProfileInfo } from 'app/layouts/profiles/profile-info.model';
import { NavbarComponent } from 'app/layouts/navbar/navbar.component'; import { NavbarComponent } from 'app/layouts/navbar/navbar.component';
import { AccountService } from 'app/core/auth/account.service'; import { AccountService } from 'app/core/auth/account.service';
import { ProfileService } from 'app/layouts/profiles/profile.service'; import { ProfileService } from 'app/layouts/profiles/profile.service';
import { SearchService } from 'app/search/service/search-service'
import { FormBuilder } from '@angular/forms'; import { FormBuilder } from '@angular/forms';
describe('Component Tests', () => { describe('Component Tests', () => {
...@@ -15,7 +14,6 @@ describe('Component Tests', () => { ...@@ -15,7 +14,6 @@ describe('Component Tests', () => {
let fixture: ComponentFixture<NavbarComponent>; let fixture: ComponentFixture<NavbarComponent>;
let accountService: AccountService; let accountService: AccountService;
let profileService: ProfileService; let profileService: ProfileService;
let searchService: SearchService;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [GitsearchTestModule], imports: [GitsearchTestModule],
...@@ -33,7 +31,6 @@ describe('Component Tests', () => { ...@@ -33,7 +31,6 @@ describe('Component Tests', () => {
comp = fixture.componentInstance; comp = fixture.componentInstance;
accountService = TestBed.get(AccountService); accountService = TestBed.get(AccountService);
profileService = TestBed.get(ProfileService); profileService = TestBed.get(ProfileService);
searchService = TestBed.get(SearchService);
}); });
it('Should call profileService.getProfileInfo on init', () => { it('Should call profileService.getProfileInfo on init', () => {
......
import { TestBed, getTestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { MessageService, BroadCastMessage } from 'app/shared/service/message-service';
describe('Service Tests', () => {
describe('Message Service', () => {
let injector: TestBed;
let service: MessageService;
let httpMock: HttpTestingController;
let expectedResult: Array<BroadCastMessage>;
let returnedFromService: Array<BroadCastMessage>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
});
expectedResult = new Array<BroadCastMessage>();
injector = getTestBed();
service = injector.get(MessageService);
httpMock = injector.get(HttpTestingController);
const messageNow :BroadCastMessage = {
message: "Some Test now Message",
// eslint-disable-next-line @typescript-eslint/camelcase
starts_at: new Date(),
// eslint-disable-next-line @typescript-eslint/camelcase
ends_at: new Date(new Date().getDate() + 1),
// eslint-disable-next-line @typescript-eslint/camelcase
color: "red", id: 1, font: "unused", active: true, target_path: "unused", broadcast_type: "broadcast_type", dismissable:true
};
const messageTomorrow :BroadCastMessage = {
message: "Some Test tomorrwo Message",
// eslint-disable-next-line @typescript-eslint/camelcase
starts_at: new Date(new Date().getDate() + 1),
// eslint-disable-next-line @typescript-eslint/camelcase
ends_at: new Date(new Date().getDate() + 2),
// eslint-disable-next-line @typescript-eslint/camelcase
color: "red", id: 2, font: "unused", active: true, target_path: "unused", broadcast_type: "broadcast_type", dismissable:true
}
returnedFromService = new Array<BroadCastMessage>(messageNow, messageTomorrow);
});
describe('Service methods', () => {
it('should get some messages', () => {
expectedResult = service.getMessages(); // this may return an empty list, because webclient may not yet received results
const req = httpMock.expectOne({ method: 'GET' });
req.flush(returnedFromService);
expectedResult = service.getMessages();
expect(expectedResult).toMatchObject(returnedFromService);
});
});
describe('Service methods', () => {
it('should get some messages', () => {
expectedResult = service.getActiveMessages(); // this may return an empty list, because webclient may not yet received results
const req = httpMock.expectOne({ method: 'GET' });
req.flush(returnedFromService);
expectedResult = service.getActiveMessages();
const now = new Date();
expect(expectedResult).toMatchObject(returnedFromService.filter(m => m.starts_at <= now && m.ends_at >= now));
});
});
afterEach(() => {
httpMock.verify();
});
});
});
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment