markdown-bar.component.spec.ts 2.58 KB
Newer Older
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
1
import { HttpClientTestingModule } from '@angular/common/http/testing';
2 3
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
4 5
import { FaIconLibrary } from '@fortawesome/angular-fontawesome';
import { faBold, faCode, faGlobe, faHeading, faImage, faItalic, faListUl, faStrikethrough } from '@fortawesome/free-solid-svg-icons';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
6
import { TranslateService } from '@ngx-translate/core';
7
import { TranslateServiceMock } from '../../../_mocks/_services/TranslateServiceMock';
8 9
import { TrackingMockService } from '../../service/tracking/tracking.mock.service';
import { TrackingService } from '../../service/tracking/tracking.service';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
10
import { SharedModule } from '../../shared/shared.module';
11 12

import { MarkdownBarComponent } from './markdown-bar.component';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
13 14 15 16 17 18 19

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

  beforeEach(async(() => {
    TestBed.configureTestingModule({
20
      imports: [
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
21
        SharedModule, RouterTestingModule, HttpClientTestingModule,
22 23
      ],
      providers: [
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
24 25 26
        {
          provide: TrackingService,
          useClass: TrackingMockService,
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
27 28 29
        }, {
          provide: TranslateService,
          useClass: TranslateServiceMock,
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
30
        },
31 32 33
      ],
      declarations: [MarkdownBarComponent],
    }).compileComponents();
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
34 35
  }));

36
  beforeEach(async(() => {
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
37 38 39 40 41 42 43 44 45
    const library: FaIconLibrary = TestBed.get(FaIconLibrary);
    library.addIcons(faBold);
    library.addIcons(faHeading);
    library.addIcons(faGlobe);
    library.addIcons(faListUl);
    library.addIcons(faCode);
    library.addIcons(faImage);
    library.addIcons(faStrikethrough);
    library.addIcons(faItalic);
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
46 47 48
    fixture = TestBed.createComponent(MarkdownBarComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
49
  }));
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
50

51
  it('should be created', async(() => {
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
52
    expect(component).toBeTruthy();
53
  }));
54 55 56 57 58 59

  it('should have a TYPE reference', async(() => {
    expect(MarkdownBarComponent.TYPE).toEqual('MarkdownBarComponent');
  }));

  it('#connector', async(inject([TrackingService], (trackingService: TrackingService) => {
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
60
    const element = component.markdownBarElements.find(el => el.id === 'boldMarkdownButton');
61 62 63 64 65 66 67 68 69

    spyOn(component.connectorEmitter, 'emit').and.callFake(() => {});
    spyOn(trackingService, 'trackClickEvent').and.callFake(() => {});

    component.connector(element);

    expect(trackingService.trackClickEvent).toHaveBeenCalled();
    expect(component.connectorEmitter.emit).toHaveBeenCalled();
  })));
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
70
});