sound-manager.component.spec.ts 3.7 KB
Newer Older
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
1
import { HttpClientTestingModule } from '@angular/common/http/testing';
2
import { PLATFORM_ID } from '@angular/core';
3
import { ComponentFixture, inject, TestBed } from '@angular/core/testing';
4
import { FormsModule } from '@angular/forms';
5
import { RouterTestingModule } from '@angular/router/testing';
6
import { JWT_OPTIONS, JwtModule } from '@auth0/angular-jwt';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
7 8
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { TranslateService } from '@ngx-translate/core';
9
import { RxStompService } from '@stomp/ng2-stompjs';
10 11
import { TranslatePipeMock } from '../../../../_mocks/_pipes/TranslatePipeMock';
import { TranslateServiceMock } from '../../../../_mocks/_services/TranslateServiceMock';
12
import { jwtOptionsFactory } from '../../../lib/jwt.factory';
13 14 15
import { ConnectionMockService } from '../../../service/connection/connection.mock.service';
import { ConnectionService } from '../../../service/connection/connection.service';
import { FooterBarService } from '../../../service/footer-bar/footer-bar.service';
16 17
import { QuizMockService } from '../../../service/quiz/quiz-mock.service';
import { QuizService } from '../../../service/quiz/quiz.service';
18 19
import { SettingsService } from '../../../service/settings/settings.service';
import { SharedService } from '../../../service/shared/shared.service';
20 21
import { StorageService } from '../../../service/storage/storage.service';
import { StorageServiceMock } from '../../../service/storage/storage.service.mock';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
22
import { AudioPlayerComponent } from '../../../shared/audio-player/audio-player.component';
23
import { SoundManagerComponent } from './sound-manager.component';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
24 25 26 27 28

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

29 30 31
  beforeEach((() => {
    TestBed.configureTestingModule({
      imports: [
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
32
        RouterTestingModule, HttpClientTestingModule, FormsModule, FontAwesomeModule, JwtModule.forRoot({
33 34 35 36 37 38
          jwtOptionsProvider: {
            provide: JWT_OPTIONS,
            useFactory: jwtOptionsFactory,
            deps: [PLATFORM_ID],
          },
        }),
39 40
      ],
      providers: [
41
        RxStompService,
42
        {
43 44 45 46 47 48 49 50
          provide: StorageService,
          useClass: StorageServiceMock,
        }, {
          provide: QuizService,
          useClass: QuizMockService,
        }, FooterBarService, SettingsService, {
          provide: ConnectionService,
          useClass: ConnectionMockService,
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
51 52 53 54
        }, SharedService, {
          provide: TranslateService,
          useClass: TranslateServiceMock,
        },
55 56
      ],
      declarations: [
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
57
        SoundManagerComponent, TranslatePipeMock, AudioPlayerComponent,
58 59 60
      ],
    }).compileComponents();
  }));
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
61

62 63 64 65 66
  beforeEach((() => {
    fixture = TestBed.createComponent(SoundManagerComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  }));
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
67

68 69 70 71 72 73
  it('should be created', (() => {
    expect(component).toBeTruthy();
  }));
  it('should contain a TYPE reference', (() => {
    expect(SoundManagerComponent.TYPE).toEqual('SoundManagerComponent');
  }));
74 75

  describe('#selectSound', () => {
76
    it('should select a given sound title', inject([QuizService], (quizService: QuizService) => {
77 78
      const value = 'Song1';
      const event = <any>{ target: { value } };
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
79
      quizService.quizUpdateEmitter.next(quizService.quiz);
80
      component.selectSound('lobby', event);
81
      expect(quizService.quiz.sessionConfig.music.titleConfig.lobby).toEqual(value);
82
    }));
83 84 85
  });

  describe('#openTab', () => {
86
    it('should open a config tab', inject([QuizService], (quizService: QuizService) => {
87 88
      const id = 'panel-lobby';
      component.openTab(id);
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
89
      expect(component.isSelected(id)).toBeTruthy();
90
    }));
91
  });
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
92
});