Merge pull request #8297 from AllForNothing/cve-whitelist

modify UT for cve-whitelist UI
This commit is contained in:
Will Sun 2019-07-16 17:14:08 +08:00 committed by GitHub
commit 8ea339f882
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -19,7 +19,7 @@ import {
ScanningResultDefaultService, ScanningResultDefaultService,
SystemInfoService, SystemInfoService,
SystemInfoDefaultService, SystemInfoDefaultService,
SystemInfo SystemInfo, SystemCVEWhitelist
} from '../service/index'; } from '../service/index';
import { Configuration } from './config'; import { Configuration } from './config';
import { of } from 'rxjs'; import { of } from 'rxjs';
@ -56,7 +56,12 @@ describe('RegistryConfigComponent (inline template)', () => {
"harbor_version": "v1.1.1-rc1-160-g565110d", "harbor_version": "v1.1.1-rc1-160-g565110d",
"next_scan_all": 0 "next_scan_all": 0
}; };
let mockSystemWhitelist: SystemCVEWhitelist = {
"expires_at": 1561996800,
"id": 1,
"items": [],
"project_id": 0
};
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
@ -90,13 +95,13 @@ describe('RegistryConfigComponent (inline template)', () => {
systemInfoService = fixture.debugElement.injector.get(SystemInfoService); systemInfoService = fixture.debugElement.injector.get(SystemInfoService);
spy = spyOn(cfgService, 'getConfigurations').and.returnValue(of(mockConfig)); spy = spyOn(cfgService, 'getConfigurations').and.returnValue(of(mockConfig));
spySystemInfo = spyOn(systemInfoService, 'getSystemInfo').and.returnValue(of(mockSystemInfo)); spySystemInfo = spyOn(systemInfoService, 'getSystemInfo').and.returnValue(of(mockSystemInfo));
spySystemInfo = spyOn(systemInfoService, 'getSystemWhitelist').and.returnValue(of(mockSystemWhitelist));
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should render configurations to the view', async(() => { it('should render configurations to the view', async(() => {
expect(spy.calls.count()).toEqual(1); expect(spy.calls.count()).toEqual(1);
expect(spySystemInfo.calls.count()).toEqual(2); expect(spySystemInfo.calls.count()).toEqual(1);
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { fixture.whenStable().then(() => {

View File

@ -6,7 +6,7 @@ import { ProjectPolicyConfigComponent } from './project-policy-config.component'
import { SharedModule } from '../shared/shared.module'; import { SharedModule } from '../shared/shared.module';
import { ProjectService, ProjectDefaultService} from '../service/project.service'; import { ProjectService, ProjectDefaultService} from '../service/project.service';
import { SERVICE_CONFIG, IServiceConfig} from '../service.config'; import { SERVICE_CONFIG, IServiceConfig} from '../service.config';
import { SystemInfo } from '../service/interface'; import {SystemCVEWhitelist, SystemInfo} from '../service/interface';
import { Project } from './project'; import { Project } from './project';
import { UserPermissionService, UserPermissionDefaultService } from '../service/permission.service'; import { UserPermissionService, UserPermissionDefaultService } from '../service/permission.service';
import { USERSTATICPERMISSION } from '../service/permission-static'; 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 component: ProjectPolicyConfigComponent;
let fixture: ComponentFixture<ProjectPolicyConfigComponent>; let fixture: ComponentFixture<ProjectPolicyConfigComponent>;
@ -122,6 +126,7 @@ describe('ProjectPolicyConfigComponent', () => {
projectPolicyService = fixture.debugElement.injector.get(ProjectService); projectPolicyService = fixture.debugElement.injector.get(ProjectService);
spySystemInfo = spyOn(systemInfoService, 'getSystemInfo').and.returnValues(of(mockSystemInfo[0])); 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])); spyProjectPolicies = spyOn(projectPolicyService, 'getProject').and.returnValues(of(mockProjectPolicies[0]));
userPermissionService = fixture.debugElement.injector.get(UserPermissionService); userPermissionService = fixture.debugElement.injector.get(UserPermissionService);