Adds tests for the attendee service

parent 2af96b1f
......@@ -536,6 +536,9 @@
"src/assets/serverEndpoint.json",
"src/assets/imageDerivates.json",
"src/assets/themeData.json"
],
"codeCoverageExclude": [
"/**/*mock*.ts"
]
}
},
......
import { IMemberSerialized } from '../../app/lib/interfaces/entities/Member/IMemberSerialized';
export const MemberMock: IMemberSerialized = {
colorCode: '',
currentQuizName: '',
groupName: '',
id: '',
responses: [
{
value: [],
responseTime: -1,
readingConfirmation: false,
confidence: undefined,
},
],
ticket: '',
name: 'user-test',
};
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { PLATFORM_ID } from '@angular/core';
import { async, inject, TestBed } from '@angular/core/testing';
import { async, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { JWT_OPTIONS, JwtModule } from '@auth0/angular-jwt';
import { TranslateService } from '@ngx-translate/core';
import { RxStompService } from '@stomp/ng2-stompjs';
import { MemberMock } from '../../../_mocks/_fixtures/member.mock';
import { Attendee } from '../../lib/attendee/attendee';
import { jwtOptionsFactory } from '../../lib/jwt.factory';
import { ConnectionMockService } from '../connection/connection.mock.service';
import { ConnectionService } from '../connection/connection.service';
......@@ -19,6 +21,8 @@ import { TrackingMockService } from '../tracking/tracking.mock.service';
import { AttendeeService } from './attendee.service';
describe('AttendeeService', () => {
let memberMock: Attendee;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
......@@ -48,7 +52,172 @@ describe('AttendeeService', () => {
});
}));
it('should be created', async(inject([AttendeeService], (service: AttendeeService) => {
beforeEach(() => {
sessionStorage.clear();
memberMock = new Attendee(JSON.parse(JSON.stringify(MemberMock)));
});
afterEach(() => {
sessionStorage.clear();
});
it('should be created', () => {
const service = TestBed.get(AttendeeService);
expect(service).toBeTruthy();
})));
});
it('should get all member groups', () => {
const service: AttendeeService = TestBed.get(AttendeeService);
expect(service.getMemberGroups()).toContain('Default');
});
it('should get all members of a group', () => {
const service: AttendeeService = TestBed.get(AttendeeService);
memberMock.groupName = 'Default';
service.addMember(memberMock);
expect(service.getMembersOfGroup('Default')).toContain(memberMock);
});
it('should clean up all the local data', () => {
const service: AttendeeService = TestBed.get(AttendeeService);
service.addMember(memberMock);
service.cleanUp();
expect(service.attendees.length).toEqual(0);
});
it('should add a member', () => {
const service: AttendeeService = TestBed.get(AttendeeService);
memberMock.name = 'testname';
service.addMember(memberMock);
expect(service.attendees).toContain(memberMock);
});
it('should remove a member', () => {
const service: AttendeeService = TestBed.get(AttendeeService);
memberMock.name = 'testname';
service.addMember(memberMock);
service.removeMember(memberMock.name);
expect(service.attendees).not.toContain(memberMock);
});
it('should clear all responses', () => {
const service: AttendeeService = TestBed.get(AttendeeService);
const response = {
value: [0, 1, 2],
responseTime: 47,
readingConfirmation: true,
confidence: 50,
};
memberMock.name = 'testname';
memberMock.responses = [JSON.parse(JSON.stringify(response))];
service.addMember(memberMock);
service.clearResponses();
expect(service.attendees[0].responses).not.toContain(response);
});
it('should return true if the provided value equals the own nick', () => {
const service: AttendeeService = TestBed.get(AttendeeService);
const nick = 'testname';
service.ownNick = nick;
expect(service.isOwnNick(nick)).toBe(true);
});
it('should update the response', () => {
const service: AttendeeService = TestBed.get(AttendeeService);
const response = {
value: [0, 1, 2],
responseTime: 47,
readingConfirmation: true,
confidence: 50,
};
memberMock.name = 'testname';
service.addMember(memberMock);
service.modifyResponse({
nickname: memberMock.name,
questionIndex: 0,
update: response,
});
expect(service.attendees[0].responses).toContain(response);
});
it('should check if a response is set', () => {
const service: AttendeeService = TestBed.get(AttendeeService);
const response = {
value: [0, 1, 2],
responseTime: 47,
readingConfirmation: true,
confidence: 50,
};
memberMock.name = 'testname';
service.addMember(memberMock);
service.ownNick = memberMock.name;
expect(service.hasReponse()).toEqual(false);
service.modifyResponse({
nickname: memberMock.name,
questionIndex: 0,
update: response,
});
expect(service.hasReponse()).toEqual(true);
});
it('should check if a reading confirmation is set', () => {
const service: AttendeeService = TestBed.get(AttendeeService);
const response = {
value: [0, 1, 2],
responseTime: 47,
readingConfirmation: true,
confidence: 50,
};
memberMock.name = 'testname';
service.addMember(memberMock);
service.ownNick = memberMock.name;
expect(service.hasReadingConfirmation()).toEqual(false);
service.modifyResponse({
nickname: memberMock.name,
questionIndex: 0,
update: response,
});
expect(service.hasReadingConfirmation()).toEqual(true);
});
it('should check if a confidence value is set', () => {
const service: AttendeeService = TestBed.get(AttendeeService);
const response = {
value: [0, 1, 2],
responseTime: 47,
readingConfirmation: true,
confidence: 50,
};
memberMock.name = 'testname';
service.addMember(memberMock);
service.ownNick = memberMock.name;
expect(service.hasConfidenceValue()).toEqual(false);
service.modifyResponse({
nickname: memberMock.name,
questionIndex: 0,
update: response,
});
expect(service.hasConfidenceValue()).toEqual(true);
});
});
......@@ -21,6 +21,7 @@ export class QuizMockService {
this.quiz = new QuizEntity({
name: 'test',
sessionConfig: new SessionConfigurationEntity(DefaultSettings.defaultQuizSettings.sessionConfig),
currentQuestionIndex: 0,
questionList: [
new SingleChoiceQuestionEntity({}), new FreeTextQuestionEntity({
questionText: '',
......
Markdown is supported
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