mirror of https://github.com/goharbor/harbor.git
Fix: Helm Chart Copy Button in UI (#21969)
* 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:
parent
9e18bbc112
commit
ada851b49a
|
@ -3,6 +3,7 @@
|
||||||
*ngIf="isImage(artifact)"
|
*ngIf="isImage(artifact)"
|
||||||
[title]="getPullCommandForRuntimeByDigest(artifact)"
|
[title]="getPullCommandForRuntimeByDigest(artifact)"
|
||||||
[iconMode]="true"
|
[iconMode]="true"
|
||||||
|
id="pullCommandForDigest"
|
||||||
(onCopySuccess)="
|
(onCopySuccess)="
|
||||||
onCpSuccess(getPullCommandForRuntimeByDigest(artifact))
|
onCpSuccess(getPullCommandForRuntimeByDigest(artifact))
|
||||||
"
|
"
|
||||||
|
@ -12,6 +13,7 @@
|
||||||
<div
|
<div
|
||||||
*ngIf="isCNAB(artifact)"
|
*ngIf="isCNAB(artifact)"
|
||||||
class="flex"
|
class="flex"
|
||||||
|
id="pullCommandForCNAB"
|
||||||
aria-label="Dropdown header Action">
|
aria-label="Dropdown header Action">
|
||||||
<hbr-copy-input
|
<hbr-copy-input
|
||||||
[title]="getPullCommandForCNAB(artifact)"
|
[title]="getPullCommandForCNAB(artifact)"
|
||||||
|
@ -20,8 +22,9 @@
|
||||||
[defaultValue]="getPullCommandForCNAB(artifact)"></hbr-copy-input>
|
[defaultValue]="getPullCommandForCNAB(artifact)"></hbr-copy-input>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
*ngIf="isChart(artifact)"
|
*ngIf="isChart(artifact) && artifact.tagNumber > 0"
|
||||||
class="flex"
|
class="flex"
|
||||||
|
id="pullCommandForChart"
|
||||||
aria-label="Dropdown header Action">
|
aria-label="Dropdown header Action">
|
||||||
<hbr-copy-input
|
<hbr-copy-input
|
||||||
[title]="getPullCommandForChart(artifact)"
|
[title]="getPullCommandForChart(artifact)"
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
import { PullCommandComponent } from './pull-command.component';
|
import { PullCommandComponent } from './pull-command.component';
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { SharedTestingModule } from '../../../../../../../../shared/shared.module';
|
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', () => {
|
describe('PullCommandComponent', () => {
|
||||||
let component: PullCommandComponent;
|
let component: PullCommandComponent;
|
||||||
|
@ -29,11 +30,11 @@ describe('PullCommandComponent', () => {
|
||||||
fixture = TestBed.createComponent(PullCommandComponent);
|
fixture = TestBed.createComponent(PullCommandComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
|
||||||
// Mock the artifact input with a valid value
|
|
||||||
component.artifact = {
|
component.artifact = {
|
||||||
type: ArtifactType.IMAGE,
|
type: ArtifactType.CHART,
|
||||||
digest: 'sampleDigest',
|
tagNumber: 1,
|
||||||
tags: [{ name: 'latest' }],
|
digest: 'sha256@digest',
|
||||||
|
tags: [{ name: '1.0.0' }],
|
||||||
};
|
};
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
@ -42,4 +43,69 @@ describe('PullCommandComponent', () => {
|
||||||
it('should create', () => {
|
it('should create', () => {
|
||||||
expect(component).toBeTruthy();
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -100,14 +100,18 @@ export class PullCommandComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
getPullCommandForChart(artifact: Artifact): string {
|
getPullCommandForChart(artifact: Artifact): string {
|
||||||
return getPullCommandByTag(
|
if (artifact.tagNumber > 0) {
|
||||||
artifact.type,
|
return getPullCommandByTag(
|
||||||
`${this.registryUrl ? this.registryUrl : location.hostname}/${
|
artifact.type,
|
||||||
this.projectName
|
`${this.registryUrl ? this.registryUrl : location.hostname}/${
|
||||||
}/${this.repoName}`,
|
this.projectName
|
||||||
artifact.tags[0].name,
|
}/${this.repoName}`,
|
||||||
Clients.CHART
|
artifact.tags[0].name,
|
||||||
);
|
Clients.CHART
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For tagMode
|
// For tagMode
|
||||||
|
|
Loading…
Reference in New Issue