Fix: Helm Chart Copy Button in UI (#21969)
Build Package Workflow / BUILD_PACKAGE (push) Has been cancelled Details
Code scanning - action / CodeQL-Build (push) Has been cancelled Details

* fix: helm chart copy btn in UI

Signed-off-by: bupd <bupdprasanth@gmail.com>

* add: tests for pull command component in UI

Signed-off-by: bupd <bupdprasanth@gmail.com>

---------

Signed-off-by: bupd <bupdprasanth@gmail.com>
This commit is contained in:
Prasanth Baskar 2025-05-09 11:08:01 +05:30 committed by GitHub
parent 9e18bbc112
commit ada851b49a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 87 additions and 14 deletions

View File

@ -3,6 +3,7 @@
*ngIf="isImage(artifact)"
[title]="getPullCommandForRuntimeByDigest(artifact)"
[iconMode]="true"
id="pullCommandForDigest"
(onCopySuccess)="
onCpSuccess(getPullCommandForRuntimeByDigest(artifact))
"
@ -12,6 +13,7 @@
<div
*ngIf="isCNAB(artifact)"
class="flex"
id="pullCommandForCNAB"
aria-label="Dropdown header Action">
<hbr-copy-input
[title]="getPullCommandForCNAB(artifact)"
@ -20,8 +22,9 @@
[defaultValue]="getPullCommandForCNAB(artifact)"></hbr-copy-input>
</div>
<div
*ngIf="isChart(artifact)"
*ngIf="isChart(artifact) && artifact.tagNumber > 0"
class="flex"
id="pullCommandForChart"
aria-label="Dropdown header Action">
<hbr-copy-input
[title]="getPullCommandForChart(artifact)"

View File

@ -14,7 +14,8 @@
import { PullCommandComponent } from './pull-command.component';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SharedTestingModule } from '../../../../../../../../shared/shared.module';
import { ArtifactType } from '../../../../artifact'; // Import the necessary type
import { ArtifactType, Clients } from '../../../../artifact'; // Import the necessary type
import { ArtifactFront } from '../../../../artifact';
describe('PullCommandComponent', () => {
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();
});
});

View File

@ -100,6 +100,7 @@ export class PullCommandComponent {
}
getPullCommandForChart(artifact: Artifact): string {
if (artifact.tagNumber > 0) {
return getPullCommandByTag(
artifact.type,
`${this.registryUrl ? this.registryUrl : location.hostname}/${
@ -108,6 +109,9 @@ export class PullCommandComponent {
artifact.tags[0].name,
Clients.CHART
);
} else {
return '';
}
}
// For tagMode