values.component.spec.ts 2.3 KB
Newer Older
1
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
2
import { TranslateModule, TranslateService } from '@ngx-translate/core';
3
import { CUSTOM_ELEMENTS_SCHEMA, SecurityContext } from '@angular/core';
4 5
import { ClarityModule } from '@clr/angular';
import { FormsModule } from '@angular/forms';
6
import { MarkdownModule, MarkedOptions } from 'ngx-markdown';
7 8 9 10
import { BrowserModule } from '@angular/platform-browser';
import { ValuesComponent } from "./values.component";
import { AdditionsService } from "../additions.service";
import { of } from "rxjs";
11 12 13
import { AdditionLink } from "../../../../../../../ng-swagger-gen/models/addition-link";
import { ErrorHandler } from "../../../../../../lib/utils/error-handler";

14 15 16 17 18

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

AllForNothing's avatar
AllForNothing committed
19 20 21 22 23
  const mockedValues = `
    adminserver.image.pullPolicy: IfNotPresent,
    adminserver.image.repository: vmware/harbor-adminserver,
    adminserver.image.tag: dev
    `;
24 25 26 27 28 29 30 31 32
  const fakedAdditionsService = {
    getDetailByLink() {
      return of(mockedValues);
    }
  };
  const mockedLink: AdditionLink = {
    absolute: false,
    href: '/test'
  };
33
  beforeEach(waitForAsync(() => {
34 35 36
    TestBed.configureTestingModule({
      imports: [
        TranslateModule.forRoot(),
37
        MarkdownModule.forRoot({ sanitize: SecurityContext.HTML }),
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        ClarityModule,
        FormsModule,
        BrowserModule
      ],
      declarations: [ValuesComponent],
      schemas: [
        CUSTOM_ELEMENTS_SCHEMA
      ],
      providers: [
        TranslateService,
        ErrorHandler,
        {provide: AdditionsService, useValue: fakedAdditionsService},
        {provide: MarkedOptions, useValue: {}},
      ]
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ValuesComponent);
    component = fixture.componentInstance;
AllForNothing's avatar
AllForNothing committed
58 59 60
    component.valueMode = true;
    component.valuesLink = mockedLink;
    component.ngOnInit();
61 62 63
    fixture.detectChanges();
  });

AllForNothing's avatar
AllForNothing committed
64
  it('should create', () => {
65
    expect(component).toBeTruthy();
AllForNothing's avatar
AllForNothing committed
66
  });
67 68 69 70 71 72 73
  it('should get values  and render', async () => {
    fixture.detectChanges();
    await fixture.whenStable();
    const trs = fixture.nativeElement.getElementsByTagName('tr');
    expect(trs.length).toEqual(3);
  });
});