diff --git a/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/pull-command/pull-command.component.html b/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/pull-command/pull-command.component.html index 8884cacf4a..2d9d98f6f7 100644 --- a/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/pull-command/pull-command.component.html +++ b/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/pull-command/pull-command.component.html @@ -3,6 +3,7 @@ *ngIf="isImage(artifact)" [title]="getPullCommandForRuntimeByDigest(artifact)" [iconMode]="true" + id="pullCommandForDigest" (onCopySuccess)=" onCpSuccess(getPullCommandForRuntimeByDigest(artifact)) " @@ -12,6 +13,7 @@
{ let component: PullCommandComponent; @@ -29,11 +30,11 @@ describe('PullCommandComponent', () => { fixture = TestBed.createComponent(PullCommandComponent); component = fixture.componentInstance; - // Mock the artifact input with a valid value component.artifact = { - type: ArtifactType.IMAGE, - digest: 'sampleDigest', - tags: [{ name: 'latest' }], + type: ArtifactType.CHART, + tagNumber: 1, + digest: 'sha256@digest', + tags: [{ name: '1.0.0' }], }; fixture.detectChanges(); @@ -42,4 +43,69 @@ describe('PullCommandComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should not display pull command for chart', async () => { + // Mock the artifact input with a valid value + component.artifact = { + type: ArtifactType.CHART, + tagNumber: 0, + digest: 'sha256@digest', + tags: [], + }; + component.getPullCommandForChart(component.artifact); + expect( + component.getPullCommandForChart(component.artifact).length + ).toBe(0); + fixture.detectChanges(); + await fixture.whenStable(); + const modal = + fixture.nativeElement.querySelector(`#pullCommandForChart`); + expect(modal).toBeFalsy(); + }); + + it('should display when pull command for chart is available', async () => { + // Mock the artifact input with a valid value + component.artifact = { + type: ArtifactType.CHART, + tagNumber: 1, + digest: 'sha256@digest', + tags: [{ name: '1.0.0' }], + }; + component.getPullCommandForChart(component.artifact); + expect( + component.getPullCommandForChart(component.artifact).length + ).toBeGreaterThan(0); + fixture.detectChanges(); + await fixture.whenStable(); + const modal = + fixture.nativeElement.querySelector(`#pullCommandForChart`); + expect(modal).toBeTruthy(); + }); + + it('should display when pull command for digest is available', async () => { + // Mock the artifact input with a valid value + component.artifact = { + type: ArtifactType.IMAGE, + }; + component.getPullCommandForRuntimeByDigest(component.artifact); + fixture.detectChanges(); + await fixture.whenStable(); + const modal = fixture.nativeElement.querySelector( + `#pullCommandForDigest` + ); + expect(modal).toBeTruthy(); + }); + + it('should display when pull command for CNAB is available', async () => { + // Mock the artifact input with a valid value + component.artifact = { + type: ArtifactType.CNAB, + }; + component.getPullCommandForCNAB(component.artifact); + fixture.detectChanges(); + await fixture.whenStable(); + const modal = + fixture.nativeElement.querySelector(`#pullCommandForCNAB`); + expect(modal).toBeTruthy(); + }); }); diff --git a/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/pull-command/pull-command.component.ts b/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/pull-command/pull-command.component.ts index 1fe4d79014..df0a8a7792 100644 --- a/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/pull-command/pull-command.component.ts +++ b/src/portal/src/app/base/project/repository/artifact/artifact-list-page/artifact-list/artifact-list-tab/pull-command/pull-command.component.ts @@ -100,14 +100,18 @@ export class PullCommandComponent { } getPullCommandForChart(artifact: Artifact): string { - return getPullCommandByTag( - artifact.type, - `${this.registryUrl ? this.registryUrl : location.hostname}/${ - this.projectName - }/${this.repoName}`, - artifact.tags[0].name, - Clients.CHART - ); + if (artifact.tagNumber > 0) { + return getPullCommandByTag( + artifact.type, + `${this.registryUrl ? this.registryUrl : location.hostname}/${ + this.projectName + }/${this.repoName}`, + artifact.tags[0].name, + Clients.CHART + ); + } else { + return ''; + } } // For tagMode