Merge pull request #9251 from zhoumeina/fix_coverage

add more unit test
This commit is contained in:
Mia ZHOU 2019-09-25 17:25:57 +08:00 committed by GitHub
commit 5ebc3831ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 233 additions and 15 deletions

View File

@ -31,7 +31,7 @@ module.exports = function (config) {
fixWebpackSourcePaths: true,
// Omit files with no statements, no functions and no branches from the report
skipFilesWithNoCoverage: true,
skipFilesWithNoCoverage: false,
// Most reporters accept additional config options. You can pass these through the `report-config` option
'report-config': {
@ -45,13 +45,13 @@ module.exports = function (config) {
// enforce percentage thresholds
// anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode
thresholds: {
emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
emitWarning: true, // set to `true` to not fail the test command when thresholds are not met
// thresholds for all files
global: {
statements: 47,
branches: 18,
functions: 27,
lines: 47
statements: 40,
branches: 13,
functions: 26,
lines: 41
},
// thresholds per file
each: {

View File

@ -31,7 +31,7 @@ module.exports = function (config) {
fixWebpackSourcePaths: true,
// Omit files with no statements, no functions and no branches from the report
skipFilesWithNoCoverage: true,
skipFilesWithNoCoverage: false,
// Most reporters accept additional config options. You can pass these through the `report-config` option
'report-config': {
@ -45,11 +45,11 @@ module.exports = function (config) {
// enforce percentage thresholds
// anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode
thresholds: {
emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
emitWarning: true, // set to `true` to not fail the test command when thresholds are not met
// thresholds for all files
global: {
statements: 37,
branches: 20,
branches: 19,
functions: 28,
lines: 36
},

View File

@ -0,0 +1,49 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SharedModule } from '../../../shared/shared.module';
import { GcRepoService } from "../gc.service";
import { of } from 'rxjs';
import { GcViewModelFactory } from "../gc.viewmodel.factory";
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { ErrorHandler } from '../../../error-handler';
import { GcHistoryComponent } from './gc-history.component';
describe('GcHistoryComponent', () => {
let component: GcHistoryComponent;
let fixture: ComponentFixture<GcHistoryComponent>;
let fakeGcRepoService = {
getJobs: function () {
return of([]);
}
};
let fakeGcViewModelFactory = {
createJobViewModel: function (data) {
return data;
}
};
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [GcHistoryComponent],
imports: [
SharedModule,
TranslateModule.forRoot()
],
providers: [
ErrorHandler,
TranslateService,
{ provide: GcRepoService, useValue: fakeGcRepoService },
{ provide: GcViewModelFactory, useValue: fakeGcViewModelFactory }
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(GcHistoryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,41 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MessageHandlerService } from '../../shared/message-handler/message-handler.service';
import { ClarityModule } from '@clr/angular';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { UserService } from "../user.service";
import { SharedModule } from '../../shared/shared.module';
import { ChangePasswordComponent } from './change-password.component';
describe('ChangePasswordComponent', () => {
let component: ChangePasswordComponent;
let fixture: ComponentFixture<ChangePasswordComponent>;
let fakeUserService = null;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ChangePasswordComponent],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
imports: [
ClarityModule,
SharedModule,
TranslateModule.forRoot()
],
providers: [
{ provide: UserService, useValue: fakeUserService }
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ChangePasswordComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -11,13 +11,13 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {Component, ViewChild, ChangeDetectorRef} from '@angular/core';
import { Component, ViewChild, ChangeDetectorRef } from '@angular/core';
import { NgForm } from '@angular/forms';
import { InlineAlertComponent } from '../../shared/inline-alert/inline-alert.component';
import { MessageHandlerService } from '../../shared/message-handler/message-handler.service';
import {UserService} from "../user.service";
import {TranslateService} from "@ngx-translate/core";
import { UserService } from "../user.service";
import { TranslateService } from "@ngx-translate/core";
@Component({
selector: 'change-password',
@ -35,8 +35,8 @@ export class ChangePasswordComponent {
confirmPwd: string = "";
userId: number;
@ViewChild("resetPwdForm", {static: false}) resetPwdForm: NgForm;
@ViewChild(InlineAlertComponent, {static: false})
@ViewChild("resetPwdForm", { static: false }) resetPwdForm: NgForm;
@ViewChild(InlineAlertComponent, { static: false })
inlineAlert: InlineAlertComponent;
constructor(
@ -109,7 +109,7 @@ export class ChangePasswordComponent {
this.onGoing = false;
if (error.status === 400) {
this.translateService.get("USER.EXISTING_PASSWORD").subscribe(
res => {this.inlineAlert.showInlineError(res); });
res => { this.inlineAlert.showInlineError(res); });
} else {
this.inlineAlert.showInlineError(error);
}

View File

@ -0,0 +1,48 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from '@clr/angular';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { UserService } from './user.service';
import { SessionService } from '../shared/session.service';
import { MessageHandlerService } from '../shared/message-handler/message-handler.service';
import { SharedModule } from '../shared/shared.module';
import { NewUserModalComponent } from './new-user-modal.component';
describe('NewUserModalComponent', () => {
let component: NewUserModalComponent;
let fixture: ComponentFixture<NewUserModalComponent>;
let fakeSessionService = null;
let fakeUserService = null;
let fakeMessageHandlerService = {
handleError: function () { }
};
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [NewUserModalComponent],
imports: [
ClarityModule,
SharedModule,
TranslateModule.forRoot()
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
providers: [
{ provide: MessageHandlerService, useValue: fakeMessageHandlerService },
{ provide: UserService, useValue: fakeUserService },
{ provide: SessionService, useValue: fakeSessionService }
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NewUserModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,62 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from '@clr/angular';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { UserService } from './user.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ConfirmationDialogService } from '../shared/confirmation-dialog/confirmation-dialog.service';
import { MessageHandlerService } from '../shared/message-handler/message-handler.service';
import { AppConfigService } from '../app-config.service';
import { SessionService } from '../shared/session.service';
import { OperationService } from '@harbor/ui';
import { UserComponent } from './user.component';
describe('UserComponent', () => {
let component: UserComponent;
let fixture: ComponentFixture<UserComponent>;
let fakeSessionService = null;
let fakeAppConfigService = {
getConfig: function () {
return {
auth_mode: 'ldap_auth'
};
}
};
let fakeUserService = null;
let fakeMessageHandlerService = {
handleError: function () { }
};
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [UserComponent],
imports: [
ClarityModule,
TranslateModule.forRoot(),
HttpClientTestingModule
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
providers: [
TranslateService,
ConfirmationDialogService,
OperationService,
{ provide: MessageHandlerService, useValue: fakeMessageHandlerService },
{ provide: UserService, useValue: fakeUserService },
{ provide: SessionService, useValue: fakeSessionService },
{ provide: AppConfigService, useValue: fakeAppConfigService }
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UserComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,18 @@
import { TestBed, inject } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { UserService } from './user.service';
describe('UserService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule
],
providers: [UserService]
});
});
it('should be created', inject([UserService], (service: UserService) => {
expect(service).toBeTruthy();
}));
});