artifact-summary.component.spec.ts 3.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ArtifactSummaryComponent } from "./artifact-summary.component";
import { of } from "rxjs";
import { ClarityModule } from "@clr/angular";
import { NO_ERRORS_SCHEMA } from "@angular/core";
import { Artifact } from "../../../../../ng-swagger-gen/models/artifact";
import { ProjectService } from "../../../../lib/services";
import { ArtifactService } from "../../../../../ng-swagger-gen/services/artifact.service";
import { ErrorHandler } from "../../../../lib/utils/error-handler";
import { TranslateFakeLoader, TranslateLoader, TranslateModule } from "@ngx-translate/core";
import { ActivatedRoute, Router } from "@angular/router";
AllForNothing's avatar
AllForNothing committed
12 13
import { AppConfigService } from "../../../services/app-config.service";
import { Project } from "../../project";
Yogi_Wang's avatar
Yogi_Wang committed
14
import { AllPipesModule } from "../../../all-pipes/all-pipes.module";
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

describe('ArtifactSummaryComponent', () => {

  const mockedArtifact: Artifact = {
    id: 123,
    type: 'IMAGE'
  };

  const fakedProjectService = {
    getProject() {
      return of({name: 'test'});
    }
  };

  const fakedArtifactService = {
    getArtifact() {
       return of(mockedArtifact);
    }
  };
  let component: ArtifactSummaryComponent;
  let fixture: ComponentFixture<ArtifactSummaryComponent>;
  const mockActivatedRoute = {
    RouterparamMap: of({ get: (key) => 'value' }),
    snapshot: {
      params: {
        id: 1,
        repo: "test",
        digest: "ABC",
        subscribe: () => {
          return of(null);
        }
      },
      data: {
AllForNothing's avatar
AllForNothing committed
48
        artifactResolver: [mockedArtifact, new Project()]
49 50 51 52 53
      }
    },
    data: of({
      projectResolver: {
        ismember: true,
AllForNothing's avatar
AllForNothing committed
54
        role_name: 'maintainer',
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
      }
    })
  };
  const fakedAppConfigService = {
    getConfig: () => {
      return {with_admiral: false};
    }
  };
  const mockRouter = {
    navigate: () => { }
  };
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        ClarityModule,
Yogi_Wang's avatar
Yogi_Wang committed
70
        AllPipesModule,
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
        TranslateModule.forRoot({
          loader: {
            provide: TranslateLoader,
            useClass: TranslateFakeLoader,
          }
        })
      ],
      declarations: [
        ArtifactSummaryComponent
      ],
      schemas: [
        NO_ERRORS_SCHEMA
      ],
      providers: [
        { provide: AppConfigService, useValue: fakedAppConfigService },
        { provide: Router, useValue: mockRouter },
        { provide: ActivatedRoute, useValue: mockActivatedRoute },
        { provide: ProjectService, useValue: fakedProjectService },
        { provide: ArtifactService, useValue: fakedArtifactService },
        ErrorHandler
      ]
    })
      .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ArtifactSummaryComponent);
    component = fixture.componentInstance;
    component.repositoryName = 'demo';
    component.artifactDigest = 'sha: acf4234f';
    fixture.detectChanges();
  });

  it('should create and get artifactDetails', async () => {
    expect(component).toBeTruthy();
    await fixture.whenStable();
    expect(component.artifact.type).toEqual('IMAGE');
  });
});