progress-bar.component.spec.ts 5.33 KB
Newer Older
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
1
import { HttpClientTestingModule } from '@angular/common/http/testing';
2 3 4
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
5
import { TranslateService } from '@ngx-translate/core';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
6
import { MarkdownService, MarkedOptions } from 'ngx-markdown';
7
import { TranslateServiceMock } from '../../../../../_mocks/_services/TranslateServiceMock';
8 9
import { Attendee } from '../../../../lib/attendee/attendee';
import { AbstractChoiceQuestionEntity } from '../../../../lib/entities/question/AbstractChoiceQuestionEntity';
10 11 12 13 14 15 16 17
import { AttendeeMockService } from '../../../../service/attendee/attendee.mock.service';
import { AttendeeService } from '../../../../service/attendee/attendee.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';
import { HeaderLabelService } from '../../../../service/header-label/header-label.service';
import { I18nService } from '../../../../service/i18n/i18n.service';
import { QuestionTextService } from '../../../../service/question-text/question-text.service';
18 19
import { QuizMockService } from '../../../../service/quiz/quiz-mock.service';
import { QuizService } from '../../../../service/quiz/quiz.service';
20 21
import { SettingsService } from '../../../../service/settings/settings.service';
import { SharedService } from '../../../../service/shared/shared.service';
22 23
import { StorageService } from '../../../../service/storage/storage.service';
import { StorageServiceMock } from '../../../../service/storage/storage.service.mock';
24 25
import { TrackingMockService } from '../../../../service/tracking/tracking.mock.service';
import { TrackingService } from '../../../../service/tracking/tracking.service';
26
import { SharedModule } from '../../../../shared/shared.module';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
27
import { ProgressBarAnonymousComponent } from './progress-bar-anonymous/progress-bar-anonymous.component';
28 29 30 31 32
import { ProgressBarFreetextComponent } from './progress-bar-freetext/progress-bar-freetext.component';
import { ProgressBarMultipleChoiceComponent } from './progress-bar-multiple-choice/progress-bar-multiple-choice.component';
import { ProgressBarRangedComponent } from './progress-bar-ranged/progress-bar-ranged.component';
import { ProgressBarSingleChoiceComponent } from './progress-bar-single-choice/progress-bar-single-choice.component';
import { ProgressBarSurveyComponent } from './progress-bar-survey/progress-bar-survey.component';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
33

34
import { ProgressBarComponent } from './progress-bar.component';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
35 36 37 38 39 40 41

describe('ProgressBarComponent', () => {
  let component: ProgressBarComponent;
  let fixture: ComponentFixture<ProgressBarComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
42
      imports: [
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
43
        SharedModule, RouterTestingModule, HttpClientTestingModule,
44 45
      ],
      providers: [
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
46 47 48 49
        MarkdownService, {
          provide: MarkedOptions,
          useValue: {},
        }, {
50 51 52
          provide: StorageService,
          useClass: StorageServiceMock,
        }, NgbActiveModal, {
53 54 55 56 57 58
          provide: TrackingService,
          useClass: TrackingMockService,
        }, FooterBarService, SettingsService, {
          provide: ConnectionService,
          useClass: ConnectionMockService,
        }, SharedService, {
59 60
          provide: QuizService,
          useClass: QuizMockService,
61 62 63
        }, I18nService, HeaderLabelService, {
          provide: AttendeeService,
          useClass: AttendeeMockService,
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
64 65 66 67
        }, QuestionTextService, {
          provide: TranslateService,
          useClass: TranslateServiceMock,
        },
68 69 70 71 72 73 74
      ],
      declarations: [
        ProgressBarSingleChoiceComponent,
        ProgressBarMultipleChoiceComponent,
        ProgressBarSurveyComponent,
        ProgressBarRangedComponent,
        ProgressBarFreetextComponent,
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
75
        ProgressBarComponent, ProgressBarAnonymousComponent,
76
      ],
77
    }).compileComponents();
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
78 79
  }));

80
  beforeEach(async(() => {
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
81 82 83
    fixture = TestBed.createComponent(ProgressBarComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
84
  }));
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
85

86 87 88 89 90 91
  it('should be created', (() => {
    expect(component).toBeTruthy();
  }));
  it('should contain a TYPE reference', (() => {
    expect(ProgressBarComponent.TYPE).toEqual('ProgressBarComponent');
  }));
92

93 94
  it('#attendeeDataForAnswer', async(inject([QuizService, AttendeeService, QuestionTextService],
    (quizService: QuizService, attendeeService: AttendeeService, questionTextService: QuestionTextService) => {
95
      component.questionIndex = 0;
96
      const question = <AbstractChoiceQuestionEntity>quizService.quiz.questionList[component.questionIndex];
97 98

      attendeeService.addMember(new Attendee({
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
99
        id: '',
100 101
        name: 'testNickname',
        groupName: 'Default',
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
102
        currentQuizName: '',
103 104 105 106
        colorCode: '#00000',
        responses: [],
      }));

107
      questionTextService.changeMultiple(question.answerOptionList.map(answer => answer.answerText));
108
      questionTextService.eventEmitter.subscribe((value) => {
109
        if (Array.isArray(value)) {
110 111 112 113
          component.data = value;
          expect(component.attendeeDataForAnswer(0)).toBeTruthy();
        }
      });
114
    })));
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
115
});