From 140a3da238a4f1d054500053eb7703bab254b44b Mon Sep 17 00:00:00 2001 From: "Shijun Sun (c)" Date: Tue, 16 Jul 2019 15:21:01 +0800 Subject: [PATCH] modify UT for cve-whitelist UI Signed-off-by: Shijun Sun (c) --- .../src/config/registry-config.component.spec.ts | 13 +++++++++---- .../project-policy-config.component.spec.ts | 11 ++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/portal/lib/src/config/registry-config.component.spec.ts b/src/portal/lib/src/config/registry-config.component.spec.ts index 0e118ff55..9aef842d4 100644 --- a/src/portal/lib/src/config/registry-config.component.spec.ts +++ b/src/portal/lib/src/config/registry-config.component.spec.ts @@ -19,7 +19,7 @@ import { ScanningResultDefaultService, SystemInfoService, SystemInfoDefaultService, - SystemInfo + SystemInfo, SystemCVEWhitelist } from '../service/index'; import { Configuration } from './config'; import { of } from 'rxjs'; @@ -56,7 +56,12 @@ describe('RegistryConfigComponent (inline template)', () => { "harbor_version": "v1.1.1-rc1-160-g565110d", "next_scan_all": 0 }; - + let mockSystemWhitelist: SystemCVEWhitelist = { + "expires_at": 1561996800, + "id": 1, + "items": [], + "project_id": 0 + }; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ @@ -90,13 +95,13 @@ describe('RegistryConfigComponent (inline template)', () => { systemInfoService = fixture.debugElement.injector.get(SystemInfoService); spy = spyOn(cfgService, 'getConfigurations').and.returnValue(of(mockConfig)); spySystemInfo = spyOn(systemInfoService, 'getSystemInfo').and.returnValue(of(mockSystemInfo)); - + spySystemInfo = spyOn(systemInfoService, 'getSystemWhitelist').and.returnValue(of(mockSystemWhitelist)); fixture.detectChanges(); }); it('should render configurations to the view', async(() => { expect(spy.calls.count()).toEqual(1); - expect(spySystemInfo.calls.count()).toEqual(2); + expect(spySystemInfo.calls.count()).toEqual(1); fixture.detectChanges(); fixture.whenStable().then(() => { diff --git a/src/portal/lib/src/project-policy-config/project-policy-config.component.spec.ts b/src/portal/lib/src/project-policy-config/project-policy-config.component.spec.ts index b1dc96798..cd044afa0 100644 --- a/src/portal/lib/src/project-policy-config/project-policy-config.component.spec.ts +++ b/src/portal/lib/src/project-policy-config/project-policy-config.component.spec.ts @@ -6,7 +6,7 @@ import { ProjectPolicyConfigComponent } from './project-policy-config.component' import { SharedModule } from '../shared/shared.module'; import { ProjectService, ProjectDefaultService} from '../service/project.service'; import { SERVICE_CONFIG, IServiceConfig} from '../service.config'; -import { SystemInfo } from '../service/interface'; +import {SystemCVEWhitelist, SystemInfo} from '../service/interface'; import { Project } from './project'; import { UserPermissionService, UserPermissionDefaultService } from '../service/permission.service'; import { USERSTATICPERMISSION } from '../service/permission-static'; @@ -83,8 +83,12 @@ describe('ProjectPolicyConfigComponent', () => { } } ]; - - + let mockSystemWhitelist: SystemCVEWhitelist = { + "expires_at": 1561996800, + "id": 1, + "items": [], + "project_id": 0 + }; let component: ProjectPolicyConfigComponent; let fixture: ComponentFixture; @@ -122,6 +126,7 @@ describe('ProjectPolicyConfigComponent', () => { projectPolicyService = fixture.debugElement.injector.get(ProjectService); spySystemInfo = spyOn(systemInfoService, 'getSystemInfo').and.returnValues(of(mockSystemInfo[0])); + spySystemInfo = spyOn(systemInfoService, 'getSystemWhitelist').and.returnValue(of(mockSystemWhitelist)); spyProjectPolicies = spyOn(projectPolicyService, 'getProject').and.returnValues(of(mockProjectPolicies[0])); userPermissionService = fixture.debugElement.injector.get(UserPermissionService);