Add unit test of build history section.

Move style to scss file.

Signed-off-by: Frank Kung <kfanjian@gmail.com>
This commit is contained in:
Frank Kung 2018-10-15 22:42:16 +08:00
parent fd9e3dc2b8
commit 735ae1b2f6
8 changed files with 148 additions and 82 deletions

View File

@ -1,89 +1,118 @@
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { ComponentFixture, TestBed, async } from "@angular/core/testing";
import { SharedModule } from '../shared/shared.module';
import { ResultGridComponent } from '../vulnerability-scanning/result-grid.component';
import { TagDetailComponent } from './tag-detail.component';
import { SharedModule } from "../shared/shared.module";
import { ResultGridComponent } from "../vulnerability-scanning/result-grid.component";
import { TagDetailComponent } from "./tag-detail.component";
import { TagHistoryComponent } from "./tag-history.component";
import { ErrorHandler } from '../error-handler/error-handler';
import { Tag, VulnerabilitySummary, VulnerabilityItem, VulnerabilitySeverity } from '../service/interface';
import { SERVICE_CONFIG, IServiceConfig } from '../service.config';
import { TagService, TagDefaultService, ScanningResultService, ScanningResultDefaultService } from '../service/index';
import { FilterComponent } from '../filter/index';
import { VULNERABILITY_SCAN_STATUS } from '../utils';
import {VULNERABILITY_DIRECTIVES} from "../vulnerability-scanning/index";
import {LabelPieceComponent} from "../label-piece/label-piece.component";
import {JobLogViewerComponent} from "../job-log-viewer/job-log-viewer.component";
import {ChannelService} from "../channel/channel.service";
import {JobLogService, JobLogDefaultService} from "../service/job-log.service";
describe('TagDetailComponent (inline template)', () => {
import { ErrorHandler } from "../error-handler/error-handler";
import {
Tag,
Manifest,
VulnerabilitySummary,
VulnerabilityItem,
VulnerabilitySeverity
} from "../service/interface";
import { SERVICE_CONFIG, IServiceConfig } from "../service.config";
import {
TagService,
TagDefaultService,
ScanningResultService,
ScanningResultDefaultService
} from "../service/index";
import { FilterComponent } from "../filter/index";
import { VULNERABILITY_SCAN_STATUS } from "../utils";
import { VULNERABILITY_DIRECTIVES } from "../vulnerability-scanning/index";
import { LabelPieceComponent } from "../label-piece/label-piece.component";
import { JobLogViewerComponent } from "../job-log-viewer/job-log-viewer.component";
import { ChannelService } from "../channel/channel.service";
import {
JobLogService,
JobLogDefaultService
} from "../service/job-log.service";
describe("TagDetailComponent (inline template)", () => {
let comp: TagDetailComponent;
let fixture: ComponentFixture<TagDetailComponent>;
let tagService: TagService;
let scanningService: ScanningResultService;
let spy: jasmine.Spy;
let vulSpy: jasmine.Spy;
let manifestSpy: jasmine.Spy;
let mockVulnerability: VulnerabilitySummary = {
scan_status: VULNERABILITY_SCAN_STATUS.finished,
severity: 5,
update_time: new Date(),
components: {
total: 124,
summary: [{
severity: 1,
count: 90
}, {
severity: 3,
count: 10
}, {
severity: 4,
count: 10
}, {
severity: 5,
count: 13
}]
summary: [
{
severity: 1,
count: 90
},
{
severity: 3,
count: 10
},
{
severity: 4,
count: 10
},
{
severity: 5,
count: 13
}
]
}
};
let mockTag: Tag = {
"digest": "sha256:e5c82328a509aeb7c18c1d7fb36633dc638fcf433f651bdcda59c1cc04d3ee55",
"name": "nginx",
"size": "2049",
"architecture": "amd64",
"os": "linux",
"docker_version": "1.12.3",
"author": "steven",
"created": new Date("2016-11-08T22:41:15.912313785Z"),
"signature": null,
"scan_overview": mockVulnerability,
"labels": [],
digest:
"sha256:e5c82328a509aeb7c18c1d7fb36633dc638fcf433f651bdcda59c1cc04d3ee55",
name: "nginx",
size: "2049",
architecture: "amd64",
os: "linux",
docker_version: "1.12.3",
author: "steven",
created: new Date("2016-11-08T22:41:15.912313785Z"),
signature: null,
scan_overview: mockVulnerability,
labels: []
};
let config: IServiceConfig = {
repositoryBaseEndpoint: '/api/repositories/testing'
repositoryBaseEndpoint: "/api/repositories/testing"
};
let mockManifest: Manifest = {
manifset: {},
// tslint:disable-next-line:max-line-length
config: `{"architecture":"amd64","config":{"Hostname":"","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/sh"],"ArgsEscaped":true,"Image":"sha256:fbef17698ac8605733924d5662f0cbfc0b27a51e83ab7d7a4b8d8a9a9fe0d1c2","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"container":"30e1a2427aa2325727a092488d304505780501585a6ccf5a6a53c4d83a826101","container_config":{"Hostname":"30e1a2427aa2","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/sh","-c","#(nop) ","CMD [\\"/bin/sh\\"]"],"ArgsEscaped":true,"Image":"sha256:fbef17698ac8605733924d5662f0cbfc0b27a51e83ab7d7a4b8d8a9a9fe0d1c2","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":{}},"created":"2018-01-09T21:10:58.579708634Z","docker_version":"17.06.2-ce","history":[{"created":"2018-01-09T21:10:58.365737589Z","created_by":"/bin/sh -c #(nop) ADD file:093f0723fa46f6cdbd6f7bd146448bb70ecce54254c35701feeceb956414622f in / "},{"created":"2018-01-09T21:10:58.579708634Z","created_by":"/bin/sh -c #(nop) CMD [\\"/bin/sh\\"]","empty_layer":true}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:cd7100a72410606589a54b932cabd804a17f9ae5b42a1882bd56d263e02b6215"]}}`
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
SharedModule
],
imports: [SharedModule],
declarations: [
TagDetailComponent,
TagHistoryComponent,
ResultGridComponent,
VULNERABILITY_DIRECTIVES,
LabelPieceComponent,
JobLogViewerComponent,
LabelPieceComponent,
JobLogViewerComponent,
FilterComponent
],
providers: [
ErrorHandler,
ChannelService,
JobLogDefaultService,
{provide: JobLogService, useClass: JobLogDefaultService},
{ provide: JobLogService, useClass: JobLogDefaultService },
{ provide: SERVICE_CONFIG, useValue: config },
{ provide: TagService, useClass: TagDefaultService },
{ provide: ScanningResultService, useClass: ScanningResultDefaultService }
{
provide: ScanningResultService,
useClass: ScanningResultDefaultService
}
]
});
}));
@ -96,54 +125,83 @@ describe('TagDetailComponent (inline template)', () => {
comp.repositoryId = "mock_repo";
tagService = fixture.debugElement.injector.get(TagService);
spy = spyOn(tagService, 'getTag').and.returnValues(Promise.resolve(mockTag));
spy = spyOn(tagService, "getTag").and.returnValues(
Promise.resolve(mockTag)
);
let mockData: VulnerabilityItem[] = [];
for (let i = 0; i < 30; i++) {
let res: VulnerabilityItem = {
id: "CVE-2016-" + (8859 + i),
severity: i % 2 === 0 ? VulnerabilitySeverity.HIGH : VulnerabilitySeverity.MEDIUM,
severity:
i % 2 === 0
? VulnerabilitySeverity.HIGH
: VulnerabilitySeverity.MEDIUM,
package: "package_" + i,
link: "https://security-tracker.debian.org/tracker/CVE-2016-4484",
layer: "layer_" + i,
version: '4.' + i + ".0",
fixedVersion: '4.' + i + '.11',
version: "4." + i + ".0",
fixedVersion: "4." + i + ".11",
description: "Mock data"
};
mockData.push(res);
}
scanningService = fixture.debugElement.injector.get(ScanningResultService);
vulSpy = spyOn(scanningService, 'getVulnerabilityScanningResults').and.returnValue(Promise.resolve(mockData));
vulSpy = spyOn(
scanningService,
"getVulnerabilityScanningResults"
).and.returnValue(Promise.resolve(mockData));
manifestSpy = spyOn(tagService, "getManifest").and.returnValues(
Promise.resolve(mockManifest)
);
fixture.detectChanges();
});
it('should load data', async(() => {
it("should load data", async(() => {
expect(spy.calls.any).toBeTruthy();
}));
it('should rightly display tag name and version', async(() => {
it("should load history data", async(() => {
expect(manifestSpy.calls.any).toBeTruthy();
}));
it("should rightly display tag name and version", async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let el: HTMLElement = fixture.nativeElement.querySelector('.custom-h2');
let el: HTMLElement = fixture.nativeElement.querySelector(".custom-h2");
expect(el).toBeTruthy();
expect(el.textContent.trim()).toEqual('mock_repo:nginx');
expect(el.textContent.trim()).toEqual("mock_repo:nginx");
});
}));
it('should display tag details', async(() => {
it("should display tag details", async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let el: HTMLElement = fixture.nativeElement.querySelector('.image-detail-label .image-details');
let el: HTMLElement = fixture.nativeElement.querySelector(
".image-detail-label .image-details"
);
expect(el).toBeTruthy();
expect(el.textContent).toEqual("steven");
});
}));
it("should render history info", async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let els: HTMLElement[] = fixture.nativeElement.querySelectorAll(
".history-item"
);
expect(els).toBeTruthy();
expect(els.length).toBe(2);
});
}));
});

View File

@ -1,5 +1,5 @@
<clr-datagrid [clrDgLoading]="loading">
<clr-dg-column style="width: 160px;">{{ 'TAG.CREATION' | translate }}</clr-dg-column>
<clr-dg-column class="history-time">{{ 'TAG.CREATION' | translate }}</clr-dg-column>
<clr-dg-column>{{ 'TAG.COMMAND' | translate }}</clr-dg-column>
<clr-dg-row *clrDgItems="let h of history" [clrDgItem]='h' class="history-item">

View File

@ -0,0 +1,3 @@
.history-time {
width: 160px;
}

View File

@ -6,6 +6,7 @@ import { ErrorHandler } from "../error-handler/index";
@Component({
selector: "hbr-tag-history",
templateUrl: "./tag-history.component.html",
styleUrls: ["./tag-history.component.scss"],
providers: []
})

View File

@ -823,8 +823,8 @@
"UNKNOWN": "n/a",
"STATUS": "Status",
"START_TIME": "Start Time",
"END_TIME": "End Time",
"DETAILS": "Details",
"UPDATE_TIME": "Update Time",
"LOGS": "Logs",
"PENDING": "Pending",
"FINISHED": "Finished",
"STOPPED": "Stopped",
@ -834,16 +834,17 @@
"NONE": "None",
"DAILY": "Daily",
"WEEKLY": "Weekly",
"MANUAL": "Manual"
"MANUAL": "Manual",
"ON": "on",
"AT": "at"
},
"GC": {
"CURRENT_SCHEDULE": "Current Schedule",
"GC_NOW": "GC NOW",
"JOB_LIST": "GC Jobs List",
"JOB_HISTORY": "GC Jobs History",
"JOB_ID": "Job ID",
"TRIGGER_TYPE": "Trigger Type",
"LATEST_JOBS": "Latest {{param}} Jobs",
"LOG_DETAIL": "Log Details",
"MSG_SUCCESS": "Garbage Collection Successful",
"MSG_SCHEDULE_SET": "Garbage Collection schedule has been set",
"MSG_SCHEDULE_RESET": "Garbage Collection schedule has been reset"

View File

@ -821,8 +821,8 @@
"UNKNOWN": "n/a",
"STATUS": "Status",
"START_TIME": "Start Time",
"END_TIME": "End Time",
"DETAILS": "Details",
"UPDATE_TIME": "Update Time",
"LOGS": "Logs",
"PENDING": "Pending",
"FINISHED": "Finished",
"STOPPED": "Stopped",
@ -832,16 +832,17 @@
"NONE": "None",
"DAILY": "Daily",
"WEEKLY": "Weekly",
"MANUAL": "Manual"
"MANUAL": "Manual",
"ON": "on",
"AT": "at"
},
"GC": {
"CURRENT_SCHEDULE": "Current Schedule",
"GC_NOW": "GC NOW",
"JOB_LIST": "GC Jobs List",
"JOB_HISTORY": "GC Jobs History",
"JOB_ID": "Job ID",
"TRIGGER_TYPE": "Trigger Type",
"LATEST_JOBS": "Latest {{param}} Jobs",
"LOG_DETAIL": "Log Details",
"MSG_SUCCESS": "Garbage Collection Successful",
"MSG_SCHEDULE_SET": "Garbage Collection schedule has been set",
"MSG_SCHEDULE_RESET": "Garbage Collection schedule has been reset"

View File

@ -784,8 +784,8 @@
"UNKNOWN": "n. d.",
"STATUS": "Status",
"START_TIME": "Start Time",
"END_TIME": "End Time",
"DETAILS": "Details",
"UPDATE_TIME": "Update Time",
"LOGS": "Logs",
"PENDING": "Pending",
"FINISHED": "Finished",
"STOPPED": "Stopped",
@ -795,16 +795,17 @@
"NONE": "None",
"DAILY": "Daily",
"WEEKLY": "Weekly",
"MANUAL": "Manual"
"MANUAL": "Manual",
"ON": "on",
"AT": "at"
},
"GC": {
"CURRENT_SCHEDULE": "Current Schedule",
"GC_NOW": "GC NOW",
"JOB_LIST": "GC Jobs List",
"JOB_HISTORY": "GC Jobs History",
"JOB_ID": "Job ID",
"TRIGGER_TYPE": "Trigger Type",
"LATEST_JOBS": "Latest {{param}} Jobs",
"LOG_DETAIL": "Log Details",
"MSG_SUCCESS": "Garbage Collection Successful",
"MSG_SCHEDULE_SET": "Garbage Collection schedule has been set",
"MSG_SCHEDULE_RESET": "Garbage Collection schedule has been reset"

View File

@ -818,9 +818,9 @@
"INCONRRECT_OLD_PWD": "旧密码不正确。",
"UNKNOWN": "未知",
"STATUS": "状态",
"START_TIME": "开始时间",
"END_TIME": "结束时间",
"DETAILS": "详情",
"START_TIME": "创建时间",
"UPDATE_TIME": "更新时间",
"LOGS": "日志",
"PENDING": "未开始",
"FINISHED": "已完成",
"STOPPED": "已停止",
@ -830,16 +830,17 @@
"NONE": "无",
"DAILY": "每天",
"WEEKLY": "每周",
"MANUAL": "手动"
"MANUAL": "手动",
"ON": " ",
"AT": " "
},
"GC": {
"CURRENT_SCHEDULE": "当前定时任务",
"GC_NOW": "立即清理垃圾",
"JOB_LIST": "任务列表",
"JOB_HISTORY": "历史任务",
"JOB_ID": "任务ID",
"TRIGGER_TYPE": "触发类型",
"LATEST_JOBS": "最新的 {{param}} 个任务",
"LOG_DETAIL": "日志详情",
"MSG_SUCCESS": "垃圾回收成功",
"MSG_SCHEDULE_SET": "垃圾回收定时任务设置成功",
"MSG_SCHEDULE_RESET": "垃圾回收定时任务已被重置"