@@ -95,4 +95,4 @@
-
\ No newline at end of file
+
diff --git a/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.html b/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.html
index 3b41f4dc9..ccc679818 100644
--- a/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.html
+++ b/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.html
@@ -75,7 +75,7 @@
-
\ No newline at end of file
+
diff --git a/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.spec.ts b/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.spec.ts
index 0a6a1e725..2cfb9c0b4 100644
--- a/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.spec.ts
+++ b/src/portal/src/lib/components/config/project-quotas/edit-project-quotas/edit-project-quotas.component.spec.ts
@@ -1,10 +1,9 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
-
import { EditProjectQuotasComponent } from './edit-project-quotas.component';
-import { SharedModule } from '../../../../utils/shared/shared.module';
-import { InlineAlertComponent } from '../../../inline-alert/inline-alert.component';
import { SERVICE_CONFIG, IServiceConfig } from '../../../../entities/service.config';
-import { RouterModule } from '@angular/router';
+import { EditQuotaQuotaInterface } from '../../../../services';
+import { HarborLibraryModule } from '../../../../harbor-library.module';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
describe('EditProjectQuotasComponent', () => {
let component: EditProjectQuotasComponent;
@@ -12,13 +11,20 @@ describe('EditProjectQuotasComponent', () => {
let config: IServiceConfig = {
quotaUrl: "/api/quotas/testing"
};
+ const mockedEditQuota: EditQuotaQuotaInterface = {
+ editQuota: "Edit Default Project Quotas",
+ setQuota: "Set the default project quotas when creating new projects",
+ countQuota: "Default artifact count",
+ storageQuota: "Default storage consumption",
+ quotaHardLimitValue: {storageLimit: -1, storageUnit: "Byte", countLimit: -1},
+ isSystemDefaultQuota: true
+ };
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
- SharedModule,
- RouterModule.forRoot([])
+ HarborLibraryModule,
+ BrowserAnimationsModule
],
- declarations: [ EditProjectQuotasComponent, InlineAlertComponent ],
providers: [
{ provide: SERVICE_CONFIG, useValue: config },
]
@@ -34,4 +40,18 @@ describe('EditProjectQuotasComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
+ it('should open', async () => {
+ component.openEditQuota = true;
+ fixture.detectChanges();
+ await fixture.whenStable();
+ component.openEditQuotaModal(mockedEditQuota);
+ fixture.detectChanges();
+ await fixture.whenStable();
+ let countInput: HTMLInputElement = fixture.nativeElement.querySelector('#count');
+ countInput.value = "100";
+ countInput.dispatchEvent(new Event("input"));
+ fixture.detectChanges();
+ await fixture.whenStable();
+ expect(component.isValid).toBeTruthy();
+ });
});
diff --git a/src/portal/src/lib/components/config/project-quotas/project-quotas.component.html b/src/portal/src/lib/components/config/project-quotas/project-quotas.component.html
index 64b175c93..aa036572f 100644
--- a/src/portal/src/lib/components/config/project-quotas/project-quotas.component.html
+++ b/src/portal/src/lib/components/config/project-quotas/project-quotas.component.html
@@ -6,7 +6,7 @@
{{'QUOTA.PROJECT_QUOTA_DEFAULT_ARTIFACT' | translate}}
{{ quotaHardLimitValue?.countLimit === -1 ? ('QUOTA.UNLIMITED'| translate) : quotaHardLimitValue?.countLimit }}
-
diff --git a/src/portal/src/lib/components/config/project-quotas/project-quotas.component.spec.ts b/src/portal/src/lib/components/config/project-quotas/project-quotas.component.spec.ts
index f70897232..51a3e2665 100644
--- a/src/portal/src/lib/components/config/project-quotas/project-quotas.component.spec.ts
+++ b/src/portal/src/lib/components/config/project-quotas/project-quotas.component.spec.ts
@@ -1,11 +1,7 @@
-import { async, ComponentFixture, TestBed } from '@angular/core/testing';
-
+import { async, ComponentFixture, ComponentFixtureAutoDetect, TestBed } from '@angular/core/testing';
import { ProjectQuotasComponent } from './project-quotas.component';
import { IServiceConfig, SERVICE_CONFIG } from '../../../entities/service.config';
-import { SharedModule } from '../../../utils/shared/shared.module';
-import { RouterModule } from '@angular/router';
-import { EditProjectQuotasComponent } from './edit-project-quotas/edit-project-quotas.component';
-import { InlineAlertComponent } from '../../inline-alert/inline-alert.component';
+import { Router } from '@angular/router';
import {
ConfigurationService, ConfigurationDefaultService, QuotaService
, QuotaDefaultService, Quota, RequestQueryParams
@@ -14,8 +10,12 @@ import { ErrorHandler } from '../../../utils/error-handler';
import { of } from 'rxjs';
import { delay } from 'rxjs/operators';
import {APP_BASE_HREF} from '@angular/common';
+import { HarborLibraryModule } from '../../../harbor-library.module';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
describe('ProjectQuotasComponent', () => {
let spy: jasmine.Spy;
+ let spyUpdate: jasmine.Spy;
+ let spyRoute: jasmine.Spy;
let quotaService: QuotaService;
let component: ProjectQuotasComponent;
@@ -43,20 +43,35 @@ describe('ProjectQuotasComponent', () => {
},
}
];
+ const fakedRouter = {
+ navigate() {
+ return undefined;
+ }
+ };
+ const fakedErrorHandler = {
+ error() {
+ return undefined;
+ },
+ info() {
+ return undefined;
+ }
+ };
+ const timeout = (ms: number) => {
+ return new Promise(resolve => setTimeout(resolve, ms));
+ };
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
- SharedModule,
- RouterModule.forRoot([])
+ HarborLibraryModule,
+ BrowserAnimationsModule
],
- declarations: [ProjectQuotasComponent, EditProjectQuotasComponent, InlineAlertComponent],
providers: [
- ErrorHandler,
+ { provide: ErrorHandler, useValue: fakedErrorHandler },
{ provide: SERVICE_CONFIG, useValue: config },
{ provide: ConfigurationService, useClass: ConfigurationDefaultService },
{ provide: QuotaService, useClass: QuotaDefaultService },
- { provide: APP_BASE_HREF, useValue : '/' }
-
+ { provide: APP_BASE_HREF, useValue : '/' },
+ { provide: Router, useValue: fakedRouter }
]
})
.compileComponents();
@@ -83,11 +98,52 @@ describe('ProjectQuotasComponent', () => {
};
return of(httpRes).pipe(delay(0));
});
-
+ spyUpdate = spyOn(quotaService, 'updateQuota').and.returnValue(of(null));
+ spyRoute = spyOn(fixture.debugElement.injector.get(Router), 'navigate').and.returnValue(of(null));
fixture.detectChanges();
}));
it('should create', () => {
expect(component).toBeTruthy();
});
+ it('should open edit quota modal', async () => {
+ // wait getting list and rendering
+ await timeout(10);
+ fixture.detectChanges();
+ await fixture.whenStable();
+ const openEditButton: HTMLButtonElement = fixture.nativeElement.querySelector("#open-edit");
+ openEditButton.dispatchEvent(new Event("click"));
+ fixture.detectChanges();
+ await fixture.whenStable();
+ const modal: HTMLElement = fixture.nativeElement.querySelector("clr-modal");
+ expect(modal).toBeTruthy();
+ });
+ it('edit quota', async () => {
+ // wait getting list and rendering
+ await timeout(10);
+ fixture.detectChanges();
+ await fixture.whenStable();
+ component.editQuota(component.quotaList[0]);
+ fixture.detectChanges();
+ await fixture.whenStable();
+ const countInput: HTMLInputElement = fixture.nativeElement.querySelector('#count');
+ countInput.value = "100";
+ countInput.dispatchEvent(new Event("input"));
+ fixture.detectChanges();
+ await fixture.whenStable();
+ const saveButton: HTMLInputElement = fixture.nativeElement.querySelector('#edit-quota-save');
+ saveButton.dispatchEvent(new Event("click"));
+ fixture.detectChanges();
+ await fixture.whenStable();
+ expect(spyUpdate.calls.count()).toEqual(1);
+ });
+ it('should call navigate function', async () => {
+ // wait getting list and rendering
+ await timeout(10);
+ fixture.detectChanges();
+ await fixture.whenStable();
+ const a: HTMLElement = fixture.nativeElement.querySelector('clr-dg-cell a');
+ a.dispatchEvent(new Event("click"));
+ expect(spyRoute.calls.count()).toEqual(1);
+ });
});