Commit e7f8ac64 authored by Meina Zhou's avatar Meina Zhou
Browse files

add unit test


Signed-off-by: default avatarMeina Zhou <meinaz@vmware.com>
parent d277e713
......@@ -7,6 +7,8 @@
"start": "ng serve --ssl true --ssl-key ssl/server.key --ssl-cert ssl/server.crt --host 0.0.0.0 --proxy-config proxy.config.json",
"lint": "tslint \"src/**/*.ts\"",
"lint:lib": "tslint \"lib/**/*.ts\" -e \"lib/dist/**/*\" ",
"lint_fix": "tslint --fix \"src/**/*.ts\"",
"lint:lib_fix": "tslint --fix \"lib/**/*.ts\" -e \"lib/dist/**/*\" ",
"test": "ng test --code-coverage",
"test:watch": "ng test --code-coverage --watch",
"test:debug": "ng test --code-coverage --source-map false",
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AccountSettingsModalComponent } from './account-settings-modal.component';
import { SessionService } from "../../shared/session.service";
import { MessageHandlerService } from "../../shared/message-handler/message-handler.service";
import { SearchTriggerService } from "../../base/global-search/search-trigger.service";
import { AccountSettingsModalService } from './account-settings-modal-service.service';
import { CUSTOM_ELEMENTS_SCHEMA, ChangeDetectorRef } from '@angular/core';
import { ClarityModule } from "@clr/angular";
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { FormsModule } from '@angular/forms';
describe('AccountSettingsModalComponent', () => {
let component: AccountSettingsModalComponent;
let fixture: ComponentFixture<AccountSettingsModalComponent>;
let fakeSessionService = {
getCurrentUser: function () {
return { has_admin_role: true };
}
};
let fakeMessageHandlerService = null;
let fakeSearchTriggerService = null;
let fakeAccountSettingsModalService = null;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AccountSettingsModalComponent],
imports: [
RouterTestingModule,
ClarityModule,
TranslateModule.forRoot(),
FormsModule
],
providers: [
ChangeDetectorRef,
TranslateService,
{ provide: SessionService, useValue: fakeSessionService },
{ provide: MessageHandlerService, useValue: fakeMessageHandlerService },
{ provide: SearchTriggerService, useValue: fakeSearchTriggerService },
{ provide: AccountSettingsModalService, useValue: fakeAccountSettingsModalService }
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AccountSettingsModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { ForgotPasswordComponent } from './forgot-password.component';
import { ClarityModule } from "@clr/angular";
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { PasswordSettingService } from '../password-setting.service';
describe('ForgotPasswordComponent', () => {
let component: ForgotPasswordComponent;
let fixture: ComponentFixture<ForgotPasswordComponent>;
let fakePasswordSettingService = null;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ForgotPasswordComponent],
imports: [
FormsModule,
ClarityModule,
TranslateModule.forRoot()
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
TranslateService,
{ provide: PasswordSettingService, useValue: fakePasswordSettingService }
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ForgotPasswordComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PasswordSettingService } from './password-setting.service';
import { SessionService } from '../../shared/session.service';
import { MessageHandlerService } from '../../shared/message-handler/message-handler.service';
import { PasswordSettingComponent } from './password-setting.component';
import { ClarityModule } from "@clr/angular";
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { FormsModule } from '@angular/forms';
import { InlineAlertComponent } from '../../shared/inline-alert/inline-alert.component';
describe('PasswordSettingComponent', () => {
let component: PasswordSettingComponent;
let fixture: ComponentFixture<PasswordSettingComponent>;
let fakePasswordSettingService = null;
let fakeSessionService = null;
let fakeMessageHandlerService = null;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ClarityModule,
TranslateModule.forRoot(),
FormsModule
],
declarations: [PasswordSettingComponent, InlineAlertComponent],
providers: [
TranslateService,
{ provide: PasswordSettingService, useValue: fakePasswordSettingService },
{ provide: SessionService, useValue: fakeSessionService },
{ provide: MessageHandlerService, useValue: fakeMessageHandlerService }
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PasswordSettingComponent);
component = fixture.componentInstance;
component.inlineAlert =
TestBed.createComponent(InlineAlertComponent).componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { TestBed, inject } from '@angular/core/testing';
import { PasswordSettingService } from './password-setting.service';
xdescribe('PasswordSettingService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [PasswordSettingService]
});
});
it('should be created', inject([PasswordSettingService], (service: PasswordSettingService) => {
expect(service).toBeTruthy();
}));
});
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { ResetPasswordComponent } from './reset-password.component';
import { FormsModule } from '@angular/forms';
import { PasswordSettingService } from '../password-setting.service';
import { RouterTestingModule } from '@angular/router/testing';
import { MessageHandlerService } from '../../../shared/message-handler/message-handler.service';
describe('ResetPasswordComponent', () => {
let component: ResetPasswordComponent;
let fixture: ComponentFixture<ResetPasswordComponent>;
let fakePasswordSettingService = null;
let fakeMessageHandlerService = null;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
FormsModule,
RouterTestingModule
],
declarations: [ResetPasswordComponent],
providers: [
TranslateService,
{ provide: PasswordSettingService, useValue: fakePasswordSettingService },
{ provide: MessageHandlerService, useValue: fakeMessageHandlerService },
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ResetPasswordComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { UserService } from '../../user/user.service';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { MessageService } from '../../global-message/message.service';
import { RouterTestingModule } from '@angular/router/testing';
import { SignUpPageComponent } from './sign-up-page.component';
import { FormsModule } from '@angular/forms';
import { NewUserFormComponent } from '../../shared/new-user-form/new-user-form.component';
import { SessionService } from '../../shared/session.service';
describe('SignUpPageComponent', () => {
let component: SignUpPageComponent;
let fixture: ComponentFixture<SignUpPageComponent>;
let fakeUserService = null;
let fakeSessionService = null;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SignUpPageComponent, NewUserFormComponent],
imports: [
FormsModule,
RouterTestingModule,
TranslateModule.forRoot()
],
providers: [
MessageService,
TranslateService,
{ provide: UserService, useValue: fakeUserService },
{ provide: SessionService, useValue: fakeSessionService },
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SignUpPageComponent);
component = fixture.componentInstance;
component.newUserForm =
TestBed.createComponent(NewUserFormComponent).componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ClarityModule } from "@clr/angular";
import { SignUpComponent } from './sign-up.component';
import { SessionService } from '../../shared/session.service';
import { UserService } from '../../user/user.service';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { NewUserFormComponent } from '../../shared/new-user-form/new-user-form.component';
import { FormsModule } from '@angular/forms';
describe('SignUpComponent', () => {
let component: SignUpComponent;
let fixture: ComponentFixture<SignUpComponent>;
let fakeSessionService = null;
let fakeUserService = null;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SignUpComponent, NewUserFormComponent],
imports: [
FormsModule,
ClarityModule,
TranslateModule.forRoot()
],
providers: [
TranslateService,
{ provide: SessionService, useValue: fakeSessionService },
{ provide: UserService, useValue: fakeUserService }
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SignUpComponent);
component = fixture.componentInstance;
component.newUserForm =
TestBed.createComponent(NewUserFormComponent).componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { TestBed, inject } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { CookieService } from 'ngx-cookie';
import { AppConfigService } from './app-config.service';
describe('AppConfigService', () => {
let fakeCookieService = {
get: function (key) {
return key;
}
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [AppConfigService,
{ provide: CookieService, useValue: fakeCookieService }]
});
});
it('should be created', inject([AppConfigService], (service: AppConfigService) => {
expect(service).toBeTruthy();
}));
});
......@@ -13,47 +13,70 @@
// limitations under the License.
/* tslint:disable:no-unused-variable */
// import { TestBed, async, ComponentFixture } from '@angular/core/testing';
// import { AppComponent } from './app.component';
// import { HomeComponent } from "./home/home.component";
// import { AboutComponent } from "./about/about.component";
// import { ClarityModule } from "@clr/angular";
// import { ROUTING } from "./app.routing";
// import { APP_BASE_HREF } from "@angular/common";
// describe('AppComponent', () => {
// let fixture: ComponentFixture<any>;
// let compiled: any;
// beforeEach(() => {
// TestBed.configureTestingModule({
// declarations: [
// AppComponent,
// AboutComponent,
// HomeComponent
// ],
// imports: [
// ClarityModule,
// ROUTING
// ],
// providers: [{provide: APP_BASE_HREF, useValue: '/'}]
// });
// fixture = TestBed.createComponent(AppComponent);
// fixture.detectChanges();
// compiled = fixture.nativeElement;
// });
// afterEach(() => {
// fixture.destroy();
// });
// it('should create the app', async(() => {
// expect(compiled).toBeTruthy();
// }));
// });
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { Title } from '@angular/platform-browser';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { CookieService } from 'ngx-cookie';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { SessionService } from './shared/session.service';
import { AppConfigService } from './app-config.service';
import { AppComponent } from './app.component';
import { ClarityModule } from "@clr/angular";
import { APP_BASE_HREF } from "@angular/common";
describe('AppComponent', () => {
let fixture: ComponentFixture<any>;
let compiled: any;
let fakeCookieService = null;
let fakeSessionService = {
getCurrentUser: function () {
return { has_admin_role: true };
}
};
let fakeAppConfigService = {
isIntegrationMode: function () {
return true;
}
};
let fakeTitle = {
setTitle: function () {
}
};
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
imports: [
ClarityModule,
TranslateModule.forRoot()
],
providers: [
TranslateService,
{ provide: APP_BASE_HREF, useValue: '/' },
{ provide: CookieService, useValue: fakeCookieService },
{ provide: SessionService, useValue: fakeSessionService },
{ provide: AppConfigService, useValue: fakeAppConfigService },
{ provide: Title, useValue: fakeTitle },
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});
fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
compiled = fixture.nativeElement;
});
afterEach(() => {
fixture.destroy();
});
it('should create the app', async(() => {
expect(compiled).toBeTruthy();
}));
});
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FooterComponent } from './footer.component';
describe('FooterComponent', () => {
let component: FooterComponent;
let fixture: ComponentFixture<FooterComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [FooterComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FooterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { GlobalSearchComponent } from './global-search.component';
xdescribe('GlobalSearchComponent', () => {
let component: GlobalSearchComponent;
let fixture: ComponentFixture<GlobalSearchComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [GlobalSearchComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(GlobalSearchComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { TestBed, inject } from '@angular/core/testing';
import { GlobalSearchService } from './global-search.service';
xdescribe('GlobalSearchService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [GlobalSearchService]
});
});
it('should be created', inject([GlobalSearchService], (service: GlobalSearchService) => {
expect(service).toBeTruthy();
}));
});
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SearchResultComponent } from './search-result.component';
xdescribe('SearchResultComponent', () => {
let component: SearchResultComponent;
let fixture: ComponentFixture<SearchResultComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SearchResultComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SearchResultComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { TestBed, inject } from '@angular/core/testing';
import { SearchTriggerService } from './search-trigger.service';
describe('SearchTriggerService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [SearchTriggerService]
});
});
it('should be created', inject([SearchTriggerService], (service: SearchTriggerService) => {
expect(service).toBeTruthy();
}));
});
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HarborShellComponent } from './harbor-shell.component';