Commit 9dfc1f2f authored by Christopher Fullarton's avatar Christopher Fullarton

Adds more tests

parent 392b98a8
Pipeline #34622 passed with stages
in 14 minutes and 39 seconds
......@@ -17,7 +17,7 @@ module.exports = function (config) {
captureConsole: false
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
dir: require('path').join(__dirname, 'coverage'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
......
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'quizAdminFilter',
})
export class QuizAdminFilterPipeMock implements PipeTransform {
public transform(value: any, ...args): any {
return value;
}
}
import { QuizEntity } from '../../app/lib/entities/QuizEntity';
import { QuizState } from '../../app/lib/enums/QuizState';
import { QuizVisibility } from '../../app/lib/enums/QuizVisibility';
export const QuizMock: QuizEntity = new QuizEntity({
currentQuestionIndex: 0,
currentStartTimestamp: 0,
description: '',
expiry: undefined,
memberGroups: undefined,
questionList: undefined,
sessionConfig: undefined,
state: QuizState.Active,
visibility: QuizVisibility.Account,
name: 'quiz-test',
});
import { AdminModule } from './admin.module';
describe('AdminModule', () => {
let adminModule: AdminModule;
beforeEach(() => {
adminModule = new AdminModule();
});
it('should create an instance', () => {
expect(adminModule).toBeTruthy();
});
});
......@@ -65,7 +65,7 @@
class="d-flex">
<fa-icon [icon]="'times'"
class="cursor-pointer"
(click)="deleteElem($event, quiz)"></fa-icon>
(click)="deleteElem(quiz)"></fa-icon>
<a class="nav-link text-dark p-0 ml-3"
[routerLink]="['/admin', 'quiz', quiz.id]">
<fa-icon class="cursor-pointer"
......@@ -107,4 +107,4 @@
</div>
</div>
</div>
</div>
\ No newline at end of file
</div>
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { Pipe, PipeTransform, PLATFORM_ID } from '@angular/core';
import { PLATFORM_ID } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { JWT_OPTIONS, JwtHelperService, JwtModule } from '@auth0/angular-jwt';
import { TranslateService } from '@ngx-translate/core';
import { RxStompService } from '@stomp/ng2-stompjs';
import { Observable, of } from 'rxjs';
import { QuizMock } from '../../../_mocks/_fixtures/quiz.mock';
import { QuizAdminFilterPipeMock } from '../../../_mocks/QuizAdminFilterPipeMock';
import { TranslateServiceMock } from '../../../_mocks/TranslateServiceMock';
import { QuizState } from '../../lib/enums/QuizState';
import { jwtOptionsFactory } from '../../lib/jwt.factory';
import { AdminApiService } from '../../service/api/admin/admin-api.service';
import { ConnectionMockService } from '../../service/connection/connection.mock.service';
import { ConnectionService } from '../../service/connection/connection.service';
import { FooterBarService } from '../../service/footer-bar/footer-bar.service';
......@@ -25,16 +30,6 @@ import { UserService } from '../../service/user/user.service';
import { SharedModule } from '../../shared/shared.module';
import { QuizAdminComponent } from './quiz-admin.component';
@Pipe({
name: 'quizAdminFilter',
})
class QuizAdminFilterPipeMock implements PipeTransform {
public transform(value: any, ...args): any {
return value;
}
}
describe('QuizAdminComponent', () => {
let component: QuizAdminComponent;
let fixture: ComponentFixture<QuizAdminComponent>;
......@@ -70,7 +65,20 @@ describe('QuizAdminComponent', () => {
}, SharedService, {
provide: UserService,
useValue: {},
}, JwtHelperService,
}, JwtHelperService, {
provide: AdminApiService,
useValue: {
getAvailableQuizzes: () => of([{ ...QuizMock }]),
deactivateQuiz: () => new Observable(subscriber => {
subscriber.next();
subscriber.complete();
}),
deleteQuiz: () => new Observable(subscriber => {
subscriber.next();
subscriber.complete();
}),
},
},
],
declarations: [
QuizAdminFilterPipeMock, QuizAdminComponent,
......@@ -87,4 +95,21 @@ describe('QuizAdminComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should check if a quiz has a state considered as "active"', () => {
expect(component.isActiveQuiz(component.quizzes[0])).toBeTruthy();
component.quizzes[0].state = QuizState.Inactive;
expect(component.isActiveQuiz(component.quizzes[0])).toBeFalsy();
});
it('should deactivate a quiz', () => {
expect(component.isActiveQuiz(component.quizzes[0])).toBeTruthy();
component.deactivateQuiz(component.quizzes[0]);
expect(component.isActiveQuiz(component.quizzes[0])).toBeFalsy();
});
it('should delete a quiz', () => {
component.deleteElem(component.quizzes[0]);
expect(component.quizzes.length).toEqual(0);
});
});
......@@ -50,7 +50,7 @@ export class QuizAdminComponent implements OnInit {
return this._deletingElements.indexOf(quiz.name) > -1;
}
public deleteElem($event: Event, quiz: IAdminQuiz): void {
public deleteElem(quiz: IAdminQuiz): void {
const index = this._deletingElements.push(quiz.name) - 1;
this.adminApiService.deleteQuiz(quiz.name).subscribe(() => {
this._deletingElements.splice(index, 1);
......
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AbstractQuestionEntity } from '../../lib/entities/question/AbstractQuestionEntity';
import { SurveyQuestionEntity } from '../../lib/entities/question/SurveyQuestionEntity';
import { FooterBarService } from '../../service/footer-bar/footer-bar.service';
import { UserService } from '../../service/user/user.service';
import { QuizDetailsAdminComponent } from './quiz-details-admin.component';
......@@ -37,4 +39,26 @@ describe('QuizDetailsAdminComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should select "general" as default viewed info tab', () => {
expect(component['_isSelected']).toEqual('general');
});
it('should select "questions" as currently viewed info tab', () => {
component.select('questions');
expect(component['_isSelected']).toEqual('questions');
});
it('should should check if a value is set (not null or undefined)', () => {
expect(component.isSet(null)).toBeFalsy();
expect(component.isSet(undefined)).toBeFalsy();
expect(component.isSet(0)).toBeTruthy();
expect(component.isSet('')).toBeTruthy();
expect(component.isSet(true)).toBeTruthy();
});
it('should convert the type of a question to a SurveyQuestion', () => {
const question = {} as AbstractQuestionEntity;
expect(component.getQuestionAsSurvey(question)).toEqual(question as unknown as SurveyQuestionEntity);
});
});
......@@ -41,7 +41,7 @@ export class QuizDetailsAdminComponent implements OnInit {
}
public isSet(value: any): boolean {
return !['undefined', 'null'].includes(typeof value);
return value !== null && typeof value !== 'undefined';
}
public getQuestionAsSurvey(question: AbstractQuestionEntity): SurveyQuestionEntity {
......
import { IMemberSerialized } from '../interfaces/entities/Member/IMemberSerialized';
import { Attendee } from './attendee';
describe('Attendee', () => {
let attendee: Attendee;
const member: IMemberSerialized = {
id: 'id',
colorCode: 'colorCode',
currentQuizName: 'test-quiz',
groupName: 'groupName',
name: 'string',
responses: [],
ticket: 'ticket',
};
beforeEach(() => {
attendee = new Attendee(member);
});
it('should create', () => {
expect(attendee).toBeTruthy();
});
it('should set all correct properties of the attendee', () => {
expect(attendee.id).toEqual(member.id);
expect(attendee.colorCode).toEqual(member.colorCode);
expect(attendee.currentQuizName).toEqual(member.currentQuizName);
expect(attendee.groupName).toEqual(member.groupName);
expect(attendee.name).toEqual(member.name);
expect(attendee.responses).toEqual(member.responses);
expect(attendee.ticket).toEqual(member.ticket);
});
});
......@@ -79,6 +79,7 @@ export class Attendee implements IMemberSerialized {
this._id = member.id;
this._name = member.name;
this._groupName = member.groupName;
this._currentQuizName = member.currentQuizName;
this._colorCode = member.colorCode;
this._responses = member.responses || [];
this._ticket = member.ticket;
......
import { Countdown } from './countdown';
describe('Countdown', () => {
let countdown: Countdown;
beforeEach(() => {
countdown = new Countdown(10);
});
it('should create', () => {
expect(countdown).toBeTruthy();
});
it('should run the countdown', done => {
expect(countdown.isRunning).toBeTruthy();
countdown.onChange.subscribe(val => {
expect(countdown.remainingTime).toEqual(val);
clearInterval(countdown['_interval']);
done();
});
});
it('should stop the countdown', () => {
countdown.stop();
expect(countdown.remainingTime).toEqual(0);
expect(countdown.isRunning).toEqual(false);
expect(countdown.hasFinished).toEqual(true);
});
});
import { HttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { PLATFORM_ID } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { JWT_OPTIONS, JwtHelperService, JwtModule } from '@auth0/angular-jwt';
import { of } from 'rxjs';
import { jwtOptionsFactory } from '../../../lib/jwt.factory';
import { StorageService } from '../../storage/storage.service';
import { UserService } from '../../user/user.service';
......@@ -24,8 +26,7 @@ describe('AdminApiService', () => {
{
provide: UserService,
useValue: {},
},
JwtHelperService,
}, JwtHelperService,
],
});
});
......@@ -34,4 +35,61 @@ describe('AdminApiService', () => {
const service: AdminApiService = TestBed.get(AdminApiService);
expect(service).toBeTruthy();
});
it('#getAvailableUsers', () => {
const service: AdminApiService = TestBed.get(AdminApiService);
const http: HttpClient = TestBed.get(HttpClient);
spyOn(http, 'get').and.callFake(() => of(null));
service.getAvailableUsers();
expect(http.get).toHaveBeenCalledWith(service['_getAvailableUsersUrl'], { headers: { authorization: undefined } });
});
it('#getAvailableQuizzes', () => {
const service: AdminApiService = TestBed.get(AdminApiService);
const http: HttpClient = TestBed.get(HttpClient);
spyOn(http, 'get').and.callFake(() => of(null));
service.getAvailableQuizzes();
expect(http.get).toHaveBeenCalledWith(service['_getAvailableQuizzesUrl'], { headers: { authorization: undefined } });
});
it('#deleteQuiz', () => {
const service: AdminApiService = TestBed.get(AdminApiService);
const http: HttpClient = TestBed.get(HttpClient);
spyOn(http, 'delete').and.callFake(() => of(null));
service.deleteQuiz('test-quiz');
expect(http.delete).toHaveBeenCalledWith(service['_deleteQuizUrl'] + '/test-quiz', { headers: { authorization: undefined } });
});
it('#deleteUser', () => {
const service: AdminApiService = TestBed.get(AdminApiService);
const http: HttpClient = TestBed.get(HttpClient);
spyOn(http, 'delete').and.callFake(() => of(null));
service.deleteUser('test-user');
expect(http.delete).toHaveBeenCalledWith(service['_deleteUserUrl'] + '/test-user', { headers: { authorization: undefined } });
});
it('#updateUser', () => {
const service: AdminApiService = TestBed.get(AdminApiService);
const http: HttpClient = TestBed.get(HttpClient);
spyOn(http, 'put').and.callFake(() => of(null));
const newUser = {};
service.updateUser(newUser);
expect(http.put).toHaveBeenCalledWith(service['_putUserUrl'], newUser, { headers: { authorization: undefined } });
});
it('#getQuiz', () => {
const service: AdminApiService = TestBed.get(AdminApiService);
const http: HttpClient = TestBed.get(HttpClient);
spyOn(http, 'get').and.callFake(() => of(null));
service.getQuiz('test-quiz');
expect(http.get).toHaveBeenCalledWith(service['_getQuizUrl'] + '/test-quiz', { headers: { authorization: undefined } });
});
it('#deactivateQuiz', () => {
const service: AdminApiService = TestBed.get(AdminApiService);
const http: HttpClient = TestBed.get(HttpClient);
spyOn(http, 'post').and.callFake(() => of(null));
service.deactivateQuiz('test-quiz');
expect(http.post).toHaveBeenCalledWith(service['_postQuizDeactivateUrl'], { quizname: 'test-quiz' }, { headers: { authorization: undefined } });
});
});
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