artifact-summary.component.spec.ts 3.26 KB
Newer Older
1
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
2 3 4 5 6 7 8 9 10 11
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
import { ArtifactDefaultService } from './artifact.service';
16 17 18 19 20 21 22 23 24 25 26 27 28 29

describe('ArtifactSummaryComponent', () => {

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

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

30 31 32 33 34 35
  const fakedArtifactDefaultService = {
    getIconsFromBackEnd() {
      return undefined;
    },
    getIcon() {
      return undefined;
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    }
  };
  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
52
        artifactResolver: [mockedArtifact, new Project()]
53 54 55 56 57
      }
    },
    data: of({
      projectResolver: {
        ismember: true,
AllForNothing's avatar
AllForNothing committed
58
        role_name: 'maintainer',
59 60 61 62 63 64 65 66 67 68 69
      }
    })
  };
  const fakedAppConfigService = {
    getConfig: () => {
      return {with_admiral: false};
    }
  };
  const mockRouter = {
    navigate: () => { }
  };
70
  beforeEach(waitForAsync(() => {
71 72 73
    TestBed.configureTestingModule({
      imports: [
        ClarityModule,
Yogi_Wang's avatar
Yogi_Wang committed
74
        AllPipesModule,
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
        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 },
93
        { provide: ArtifactDefaultService, useValue: fakedArtifactDefaultService },
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
        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');
  });
});