Merge pull request #9226 from zhoumeina/fix_ut

fix harbor portal unit test and set thresholds
This commit is contained in:
Mia ZHOU 2019-09-24 16:52:23 +08:00 committed by GitHub
commit 71dc9abcd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 603 additions and 79 deletions

View File

@ -48,10 +48,10 @@ module.exports = function (config) {
emitWarning: false, // set to `true` to not fail the test command when thresholds are not met emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
// thresholds for all files // thresholds for all files
global: { global: {
statements: 10, statements: 47,
lines: 10, branches: 18,
branches: 0, functions: 27,
functions: 10 lines: 47
}, },
// thresholds per file // thresholds per file
each: { each: {

View File

@ -48,10 +48,10 @@ module.exports = function (config) {
emitWarning: false, // set to `true` to not fail the test command when thresholds are not met emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
// thresholds for all files // thresholds for all files
global: { global: {
statements: 10, statements: 37,
lines: 10, branches: 20,
branches: 0, functions: 28,
functions: 10 lines: 36
}, },
// thresholds per file // thresholds per file
each: { each: {

View File

@ -1,9 +1,16 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { AccountSettingsModalService } from './account-settings-modal-service.service'; import { AccountSettingsModalService } from './account-settings-modal-service.service';
describe('AccountSettingsModalServiceService', () => { describe('AccountSettingsModalServiceService', () => {
beforeEach(() => TestBed.configureTestingModule({})); beforeEach(() => TestBed.configureTestingModule({
imports: [
HttpClientTestingModule
],
providers: [
AccountSettingsModalService
]
}));
it('should be created', () => { it('should be created', () => {
const service: AccountSettingsModalService = TestBed.get(AccountSettingsModalService); const service: AccountSettingsModalService = TestBed.get(AccountSettingsModalService);

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { BrowserModule } from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';
import { NgModule, APP_INITIALIZER, LOCALE_ID } from '@angular/core'; import { NgModule, APP_INITIALIZER, LOCALE_ID, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { BaseModule } from './base/base.module'; import { BaseModule } from './base/base.module';
@ -88,6 +88,9 @@ export function getCurrentLanguage(translateService: TranslateService) {
}, },
{provide: LOCALE_ID, useValue: "en-US"} {provide: LOCALE_ID, useValue: "en-US"}
], ],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })
export class AppModule {} export class AppModule {}

View File

@ -1,5 +1,6 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { DevCenterComponent } from './dev-center.component'; import { DevCenterComponent } from './dev-center.component';
describe('DevCenterComponent', () => { describe('DevCenterComponent', () => {
@ -8,9 +9,16 @@ describe('DevCenterComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ DevCenterComponent ] declarations: [DevCenterComponent],
imports: [
HttpClientTestingModule,
TranslateModule.forRoot()
],
providers: [
TranslateService
],
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,34 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from '@clr/angular';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { SessionService } from "../shared/session.service";
import { GcPageComponent } from './gc-page.component'; import { GcPageComponent } from './gc-page.component';
describe('GcPageComponent', () => { describe('GcPageComponent', () => {
let component: GcPageComponent; let component: GcPageComponent;
let fixture: ComponentFixture<GcPageComponent>; let fixture: ComponentFixture<GcPageComponent>;
let fakeSessionService = {
getCurrentUser: function () {
return { has_admin_role: true };
}
};
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ GcPageComponent ] declarations: [GcPageComponent],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
imports: [
ClarityModule,
TranslateModule.forRoot()
],
providers: [
TranslateService,
{ provide: SessionService, useValue: fakeSessionService }
]
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,57 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from '@clr/angular';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { CUSTOM_ELEMENTS_SCHEMA, ChangeDetectorRef } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { GroupService } from "../group.service";
import { MessageHandlerService } from "./../../shared/message-handler/message-handler.service";
import { SessionService } from "./../../shared/session.service";
import { UserGroup } from "./../group";
import { AppConfigService } from "../../app-config.service";
import { AddGroupModalComponent } from './add-group-modal.component'; import { AddGroupModalComponent } from './add-group-modal.component';
describe('AddGroupModalComponent', () => { describe('AddGroupModalComponent', () => {
let component: AddGroupModalComponent; let component: AddGroupModalComponent;
let fixture: ComponentFixture<AddGroupModalComponent>; let fixture: ComponentFixture<AddGroupModalComponent>;
let fakeSessionService = {
getCurrentUser: function () {
return { has_admin_role: true };
}
};
let fakeGroupService = null;
let fakeAppConfigService = {
isLdapMode: function () {
return true;
},
isHttpAuthMode: function () {
return false;
},
isOidcMode: function () {
return false;
}
};
let fakeMessageHandlerService = null;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ AddGroupModalComponent ] declarations: [AddGroupModalComponent],
imports: [
ClarityModule,
FormsModule,
TranslateModule.forRoot()
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
providers: [
ChangeDetectorRef,
{ provide: MessageHandlerService, useValue: fakeMessageHandlerService },
{ provide: SessionService, useValue: fakeSessionService },
{ provide: AppConfigService, useValue: fakeAppConfigService },
{ provide: GroupService, useValue: fakeGroupService },
]
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,70 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { GroupComponent } from './group.component'; import { GroupComponent } from './group.component';
import { ClarityModule } from '@clr/angular';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { FormsModule } from '@angular/forms';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { OperationService } from "@harbor/ui";
import { SessionService } from "./../shared/session.service";
import { GroupService } from "./group.service";
import { of } from "rxjs";
import { ConfirmationDialogService } from "./../shared/confirmation-dialog/confirmation-dialog.service";
import { MessageHandlerService } from '../shared/message-handler/message-handler.service';
import { AppConfigService } from '../app-config.service';
describe('GroupComponent', () => { describe('GroupComponent', () => {
let component: GroupComponent; let component: GroupComponent;
let fixture: ComponentFixture<GroupComponent>; let fixture: ComponentFixture<GroupComponent>;
let fakeMessageHandlerService = null;
let fakeOperationService = null;
let fakeGroupService = {
getUserGroups: function () {
return of([{
group_name: ''
}, {
group_name: 'abc'
}]);
}
};
let fakeConfirmationDialogService = {
confirmationConfirm$: of({
state: 1,
source: 2
})
};
let fakeSessionService = {
currentUser: {
has_admin_role: true
}
};
let fakeAppConfigService = {
isLdapMode: function () {
return true;
}
};
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ GroupComponent ] declarations: [GroupComponent],
imports: [
ClarityModule,
FormsModule,
TranslateModule.forRoot()
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
providers: [
TranslateService,
{ provide: MessageHandlerService, useValue: fakeMessageHandlerService },
{ provide: OperationService, useValue: fakeOperationService },
{ provide: GroupService, useValue: fakeGroupService },
{ provide: ConfirmationDialogService, useValue: fakeConfirmationDialogService },
{ provide: SessionService, useValue: fakeSessionService },
{ provide: AppConfigService, useValue: fakeAppConfigService }
]
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,11 +1,14 @@
import { TestBed, inject } from '@angular/core/testing'; import { TestBed, inject } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { GroupService } from './group.service'; import { GroupService } from './group.service';
describe('GroupService', () => { describe('GroupService', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [GroupService] providers: [GroupService],
imports: [
HttpClientTestingModule
]
}); });
}); });

View File

@ -2,7 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing';
import { LicenseComponent } from './license.component'; import { LicenseComponent } from './license.component';
fdescribe('LicenseComponent', () => { describe('LicenseComponent', () => {
let component: LicenseComponent; let component: LicenseComponent;
let fixture: ComponentFixture<LicenseComponent>; let fixture: ComponentFixture<LicenseComponent>;

View File

@ -1,16 +1,48 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from '@clr/angular';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { OidcOnboardService } from './oidc-onboard.service';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { Router, ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
import { OidcOnboardComponent } from './oidc-onboard.component'; import { OidcOnboardComponent } from './oidc-onboard.component';
describe('OidcOnboardComponent', () => { describe('OidcOnboardComponent', () => {
let component: OidcOnboardComponent; let component: OidcOnboardComponent;
let fixture: ComponentFixture<OidcOnboardComponent>; let fixture: ComponentFixture<OidcOnboardComponent>;
let fakeOidcOnboardService = null;
let fakeRouter = null;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ OidcOnboardComponent ] declarations: [OidcOnboardComponent],
}) schemas: [
.compileComponents(); CUSTOM_ELEMENTS_SCHEMA
],
imports: [
ClarityModule,
FormsModule,
ReactiveFormsModule,
TranslateModule.forRoot()
],
providers: [
TranslateService,
{ provide: OidcOnboardService, useValue: fakeOidcOnboardService },
{ provide: Router, useValue: fakeRouter },
{
provide: ActivatedRoute, useValue: {
queryParams: of({
view: 'abc',
objectId: 'ddd',
actionUid: 'ddd',
targets: '',
locale: ''
})
}
}
]
}).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,9 +1,17 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { HttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { OidcOnboardService } from './oidc-onboard.service'; import { OidcOnboardService } from './oidc-onboard.service';
describe('OidcOnboardService', () => { describe('OidcOnboardService', () => {
beforeEach(() => TestBed.configureTestingModule({})); beforeEach(() => TestBed.configureTestingModule({
imports: [
HttpClientTestingModule
],
providers: [
OidcOnboardService
]
}));
it('should be created', () => { it('should be created', () => {
const service: OidcOnboardService = TestBed.get(OidcOnboardService); const service: OidcOnboardService = TestBed.get(OidcOnboardService);

View File

@ -1,16 +1,51 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ClarityModule } from '@clr/angular';
import { ActivatedRoute, Router } from "@angular/router";
import { SessionService } from './../../../shared/session.service';
import { of } from 'rxjs';
import { HelmChartDetailComponent } from './chart-detail.component'; import { HelmChartDetailComponent } from './chart-detail.component';
describe('ChartDetailComponent', () => { describe('ChartDetailComponent', () => {
let component: HelmChartDetailComponent; let component: HelmChartDetailComponent;
let fixture: ComponentFixture<HelmChartDetailComponent>; let fixture: ComponentFixture<HelmChartDetailComponent>;
let fakeRouter = null;
let fakeSessionService = {
getCurrentUser: function () {
return { has_admin_role: true };
}
};
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ HelmChartDetailComponent ] declarations: [HelmChartDetailComponent],
}) schemas: [
.compileComponents(); CUSTOM_ELEMENTS_SCHEMA
],
imports: [
ClarityModule,
TranslateModule.forRoot()
],
providers: [
{
provide: ActivatedRoute, useValue: {
paramMap: of({ get: (key) => 'value' }),
snapshot: {
params: { id: 1, chart: 'chart', version: 1.0 },
data: {
projectResolver: {
role_name: 'admin'
}
}
}
}
},
{ provide: Router, useValue: fakeRouter },
{ provide: SessionService, useValue: fakeSessionService },
TranslateService
]
}).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,49 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from '@clr/angular';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { ActivatedRoute } from '@angular/router';
import { Router } from '@angular/router';
import { of } from 'rxjs';
import { SessionService } from './../../../shared/session.service';
import { ListChartVersionsComponent } from './list-chart-versions.component'; import { ListChartVersionsComponent } from './list-chart-versions.component';
describe('ListChartVersionsComponent', () => { describe('ListChartVersionsComponent', () => {
let component: ListChartVersionsComponent; let component: ListChartVersionsComponent;
let fixture: ComponentFixture<ListChartVersionsComponent>; let fixture: ComponentFixture<ListChartVersionsComponent>;
let fakeSessionService = {
getCurrentUser: function () {
return "admin";
}
};
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ ListChartVersionsComponent ] declarations: [ListChartVersionsComponent],
imports: [
ClarityModule,
TranslateModule.forRoot()
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
providers: [
TranslateService,
{
provide: ActivatedRoute, useValue: {
snapshot: {
params: {
id: 1,
chart: 'chart'
}
}
}
},
{ provide: Router, useValue: null },
{ provide: SessionService, useValue: fakeSessionService }
]
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,47 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from '@clr/angular';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { CUSTOM_ELEMENTS_SCHEMA, ChangeDetectorRef } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { SessionService } from './../../shared/session.service';
import { ListChartsComponent } from './list-charts.component'; import { ListChartsComponent } from './list-charts.component';
describe('ListChartsComponent', () => { describe('ListChartsComponent', () => {
let component: ListChartsComponent; let component: ListChartsComponent;
let fixture: ComponentFixture<ListChartsComponent>; let fixture: ComponentFixture<ListChartsComponent>;
let fakeSessionService = {
getCurrentUser: function () {
return "admin";
}
};
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ ListChartsComponent ] declarations: [ListChartsComponent],
}) imports: [
.compileComponents(); ClarityModule,
TranslateModule.forRoot()
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
providers: [
{
provide: ActivatedRoute, useValue: {
snapshot: {
parent: {
params: {
id: 1,
data: 'chart'
}
}
}
}
},
{ provide: Router, useValue: null },
{ provide: SessionService, useValue: fakeSessionService }
]
}).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,41 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from '@clr/angular';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { FormsModule } from '@angular/forms';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { AddGroupComponent } from './add-group.component'; import { AddGroupComponent } from './add-group.component';
import { OperationService } from "@harbor/ui";
import { GroupService } from "../../../group/group.service";
import { MemberService } from "./../member.service";
import { MessageHandlerService } from '../../../shared/message-handler/message-handler.service';
describe('AddGroupComponent', () => { describe('AddGroupComponent', () => {
let component: AddGroupComponent; let component: AddGroupComponent;
let fixture: ComponentFixture<AddGroupComponent>; let fixture: ComponentFixture<AddGroupComponent>;
let fakeMessageHandlerService = null;
let fakeOperationService = null;
let fakeGroupService = null;
let fakeMemberService = null;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ AddGroupComponent ] declarations: [AddGroupComponent],
}) imports: [
.compileComponents(); ClarityModule,
FormsModule,
TranslateModule.forRoot()
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
providers: [
TranslateService,
{ provide: MessageHandlerService, useValue: fakeMessageHandlerService },
{ provide: OperationService, useValue: fakeOperationService },
{ provide: GroupService, useValue: fakeGroupService },
{ provide: MemberService, useValue: fakeMemberService }
]
}).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,44 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HarborLibraryModule } from "@harbor/ui";
import { of } from "rxjs";
import { MemberService } from '../member.service';
import { AppConfigService } from "../../../app-config.service";
import { ClarityModule } from '@clr/angular';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { AddHttpAuthGroupComponent } from './add-http-auth-group.component'; import { AddHttpAuthGroupComponent } from './add-http-auth-group.component';
describe('AddHttpAuthGroupComponent', () => { describe('AddHttpAuthGroupComponent', () => {
let component: AddHttpAuthGroupComponent; let component: AddHttpAuthGroupComponent;
let fixture: ComponentFixture<AddHttpAuthGroupComponent>; let fixture: ComponentFixture<AddHttpAuthGroupComponent>;
let fakeAppConfigService = {
isHttpAuthMode: function () {
return true;
}
};
let fakeMemberService = {addGroupMember: function() {
return of(null);
}};
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ AddHttpAuthGroupComponent ] declarations: [AddHttpAuthGroupComponent],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
imports: [
ClarityModule,
HarborLibraryModule,
TranslateModule.forRoot()
],
providers: [
TranslateService,
{ provide: AppConfigService, useValue: fakeAppConfigService },
{ provide: MemberService, useValue: fakeMemberService }
],
}) })
.compileComponents(); .compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -55,7 +55,7 @@ export class AddHttpAuthGroupComponent implements OnInit {
staticBackdrop: boolean = true; staticBackdrop: boolean = true;
closable: boolean = false; closable: boolean = false;
@ViewChild('memberForm', {static: false}) @ViewChild('memberForm', {static: true})
currentForm: NgForm; currentForm: NgForm;
@ViewChild(InlineAlertComponent, {static: false}) @ViewChild(InlineAlertComponent, {static: false})

View File

@ -1,16 +1,53 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ClarityModule } from '@clr/angular';
import { ActivatedRoute, Router } from "@angular/router";
import { SessionService } from '../../shared/session.service';
import { of } from 'rxjs';
import { ProjectConfigComponent } from './project-config.component'; import { ProjectConfigComponent } from './project-config.component';
describe('ProjectConfigPageComponent', () => { describe('ProjectConfigComponent', () => {
let component: ProjectConfigComponent; let component: ProjectConfigComponent;
let fixture: ComponentFixture<ProjectConfigComponent>; let fixture: ComponentFixture<ProjectConfigComponent>;
let fakeSessionService = {
getCurrentUser: function () {
return { has_admin_role: true };
}
};
let fakeRouter = null;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ ProjectConfigComponent ] declarations: [ProjectConfigComponent],
}) schemas: [
.compileComponents(); CUSTOM_ELEMENTS_SCHEMA
],
imports: [
ClarityModule,
TranslateModule.forRoot()
],
providers: [
{
provide: ActivatedRoute, useValue: {
paramMap: of({ get: (key) => 'value' }),
snapshot: {
parent: {
params: { id: 1, chart: 'chart', version: 1.0 }
},
data: {
projectResolver: {
role_name: 'admin'
}
}
}
}
},
{ provide: Router, useValue: fakeRouter },
{ provide: SessionService, useValue: fakeSessionService },
TranslateService
]
}).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,48 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from '@clr/angular';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { AddRobotComponent } from './add-robot.component'; import { AddRobotComponent } from './add-robot.component';
import { FormsModule } from '@angular/forms';
import { RobotService } from "../robot-account.service";
import { of } from "rxjs";
import { ErrorHandler } from "@harbor/ui";
import { MessageHandlerService } from "../../../shared/message-handler/message-handler.service";
import { TranslateModule, TranslateService } from '@ngx-translate/core';
describe('AddRobotComponent', () => { describe('AddRobotComponent', () => {
let component: AddRobotComponent; let component: AddRobotComponent;
let fixture: ComponentFixture<AddRobotComponent>; let fixture: ComponentFixture<AddRobotComponent>;
let fakeRobotService = {
listRobotAccount: function () {
return of([{
name: "robot$" + 1
}, {
name: "abc"
}]);
}
};
let fakeMessageHandlerService = {
showSuccess: function() {}
};
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ AddRobotComponent ] declarations: [AddRobotComponent],
}) schemas: [
.compileComponents(); CUSTOM_ELEMENTS_SCHEMA
],
imports: [
ClarityModule,
TranslateModule.forRoot(),
FormsModule
],
providers: [
TranslateService,
ErrorHandler,
{ provide: MessageHandlerService, useValue: fakeMessageHandlerService },
{ provide: RobotService, useValue: fakeRobotService }
]
}).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,73 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ClarityModule } from '@clr/angular';
import { of } from 'rxjs';
import { ActivatedRoute, Router } from "@angular/router";
import { MessageHandlerService } from "../../shared/message-handler/message-handler.service";
import { RobotService } from "./robot-account.service";
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { ConfirmationDialogService } from "../../shared/confirmation-dialog/confirmation-dialog.service";
import { RobotAccountComponent } from './robot-account.component'; import { RobotAccountComponent } from './robot-account.component';
import {
operateChanges,
OperateInfo,
OperationService,
OperationState,
UserPermissionService,
USERSTATICPERMISSION,
ErrorHandler,
errorHandler as errorHandFn
} from "@harbor/ui";
describe('RobotAccountComponent', () => { describe('RobotAccountComponent', () => {
let component: RobotAccountComponent; let component: RobotAccountComponent;
let fixture: ComponentFixture<RobotAccountComponent>; let fixture: ComponentFixture<RobotAccountComponent>;
let robotService = {
listRobotAccount: function () {
return of([]);
}
};
let mockConfirmationDialogService = null;
let mockUserPermissionService = {
getPermission: function () {
return 1;
}
};
let mockErrorHandler = {
error: function () { }
};
let mockMessageHandlerService = null;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ RobotAccountComponent ] schemas: [
}) CUSTOM_ELEMENTS_SCHEMA
.compileComponents(); ],
imports: [
ClarityModule,
TranslateModule.forRoot()
],
providers: [
{
provide: ActivatedRoute, useValue: {
paramMap: of({ get: (key) => 'value' }),
snapshot: {
parent: {
params: { id: 1 }
},
data: 1
}
}
},
TranslateService,
{ provide: RobotService, useValue: robotService },
{ provide: ConfirmationDialogService, useClass: ConfirmationDialogService },
{ provide: UserPermissionService, useValue: mockUserPermissionService },
{ provide: ErrorHandler, useValue: mockErrorHandler },
{ provide: MessageHandlerService, useValue: mockMessageHandlerService },
OperationService
],
declarations: [RobotAccountComponent]
}).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,52 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from '@clr/angular';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { ProjectService, ErrorHandler} from '@harbor/ui';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
import { AppConfigService } from "../../app-config.service";
import { SummaryComponent } from './summary.component'; import { SummaryComponent } from './summary.component';
describe('SummaryComponent', () => { describe('SummaryComponent', () => {
let component: SummaryComponent; let component: SummaryComponent;
let fixture: ComponentFixture<SummaryComponent>; let fixture: ComponentFixture<SummaryComponent>;
let fakeAppConfigService = null;
let fakeProjectService = {
getProjectSummary: function () {
return of();
}
};
let fakeErrorHandler = null;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ SummaryComponent ] declarations: [SummaryComponent],
}) imports: [
.compileComponents(); ClarityModule,
TranslateModule.forRoot()
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
providers: [
TranslateService,
{ provide: AppConfigService, useValue: fakeAppConfigService },
{ provide: ProjectService, useValue: fakeProjectService },
{ provide: ErrorHandler, useValue: fakeErrorHandler },
{
provide: ActivatedRoute, useValue: {
paramMap: of({ get: (key) => 'value' }),
snapshot: {
parent: {
params: { id: 1 }
},
data: 1
}
}
},
]
}).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,39 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ReplicationTasksPageComponent } from './replication-tasks-page.component'; import { ReplicationTasksPageComponent } from './replication-tasks-page.component';
import { ActivatedRoute, Router } from '@angular/router';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { of } from 'rxjs';
describe('ReplicationTasksPageComponent', () => { describe('ReplicationTasksPageComponent', () => {
let component: ReplicationTasksPageComponent; let component: ReplicationTasksPageComponent;
let fixture: ComponentFixture<ReplicationTasksPageComponent>; let fixture: ComponentFixture<ReplicationTasksPageComponent>;
let mockActivatedRoute = {
snapshot: {
params: 1
}
};
let mockRouter = null;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ ReplicationTasksPageComponent ] declarations: [ReplicationTasksPageComponent],
}) schemas: [
.compileComponents(); CUSTOM_ELEMENTS_SCHEMA
],
imports: [
TranslateModule.forRoot()
],
providers: [
{
provide: ActivatedRoute, useValue: mockActivatedRoute
},
{
provide: Router, useValue: mockRouter
},
TranslateService
]
}).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {

View File

@ -1,16 +1,29 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from '@clr/angular';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { AppConfigService } from "../app-config.service";
import { VulnerabilityPageComponent } from './vulnerability-page.component'; import { VulnerabilityPageComponent } from './vulnerability-page.component';
describe('VulnerabilityPageComponent', () => { describe('VulnerabilityPageComponent', () => {
let component: VulnerabilityPageComponent; let component: VulnerabilityPageComponent;
let fixture: ComponentFixture<VulnerabilityPageComponent>; let fixture: ComponentFixture<VulnerabilityPageComponent>;
let fakeAppConfigService = null;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [ VulnerabilityPageComponent ] schemas: [
}) CUSTOM_ELEMENTS_SCHEMA
.compileComponents(); ],
imports: [
ClarityModule,
TranslateModule.forRoot()
],
providers: [
TranslateService,
{ provide: AppConfigService, useValue: fakeAppConfigService }
],
declarations: [VulnerabilityPageComponent]
}).compileComponents();
})); }));
beforeEach(() => { beforeEach(() => {