some test cases in self component 66/106966/1
authorIndrijeet kumar <indriku1@in.ibm.com>
Fri, 1 May 2020 01:36:33 +0000 (07:06 +0530)
committerIndrijeet kumar <indriku1@in.ibm.com>
Fri, 1 May 2020 01:36:38 +0000 (07:06 +0530)
some test cases in self component

Issue-ID: PORTAL-813
Change-Id: Ie070d510adf1eaf4125d459f76032d7482a1629d
Signed-off-by: Indrijeet Kumar <indriku1@in.ibm.com>
ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/ext/profile/self/self.component.spec.ts

index 5178b52..52bb01f 100644 (file)
@@ -48,29 +48,30 @@ import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
 import { UserService } from 'src/app/shared/services/user/user.service';
 import { Observable } from 'rxjs';
-import { ActivatedRoute } from '@angular/router';
 import { RouterTestingModule } from '@angular/router/testing';
 import { ModalDismissReasons, NgbModule } from '@ng-bootstrap/ng-bootstrap';
 import { ProfileService } from '../profile.service';
 import { InformationModalComponent } from 'src/app/modals/information-modal/information-modal.component';
 import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
+import { ErrorModalComponent } from 'src/app/modals/error-modal/error-modal.component';
+import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
 
 describe('SelfComponent', () => {
   let component: SelfComponent;
   let fixture: ComponentFixture<SelfComponent>;
   let userService:UserService;
   let profileService:ProfileService;
-  let tableobj:any=JSON.stringify({"errormessage":"DummyError","stacktrace":"trace"});
-  let data={"data":'{"profile":\'{"data":"data"}\'}'};
-  //var _element={"_element":true};
   var _element={"_element":{"selected":true}}
  
-  
-
   beforeEach(async(() => {
     TestBed.configureTestingModule({
       schemas: [CUSTOM_ELEMENTS_SCHEMA],
-      declarations: [ SelfComponent,InformationModalComponent ],
+      declarations: [ 
+        SelfComponent,
+        InformationModalComponent,
+        ErrorModalComponent,
+        ConfirmationModalComponent
+      ],
       imports: [
         ReactiveFormsModule, 
         FormsModule,
@@ -85,7 +86,10 @@ describe('SelfComponent', () => {
     })
     TestBed.overrideModule(BrowserDynamicTestingModule,{
       set:{
-        entryComponents:[InformationModalComponent ]
+        entryComponents:[
+          InformationModalComponent,
+          ErrorModalComponent,
+          ConfirmationModalComponent]
       }
     })
     .compileComponents();
@@ -103,9 +107,6 @@ describe('SelfComponent', () => {
     expect(component).toBeTruthy();
   });
 
-  // it('should test assignProfileDetails method',()=>{
-  //   component.assignProfileDetails(data);
-  // })
 
   describe('should test ngOnInit method',()=>{
     it('should test subscribe',()=>{
@@ -133,9 +134,46 @@ describe('SelfComponent', () => {
     expect(spy).toHaveBeenCalled();
   })
 
-  // // it('should test saveProfile method',()=>{
-  // //   component.saveProfile()
-  // // })
+  it('should test saveProfile method first if condition',()=>{
+    component.oriProfile={"loginId":"loginId1"};
+    component.profile.loginId="loginId2";
+    component.saveProfile()
+  })
+
+  it('should test saveProfile method second if condition',()=>{
+    component.oriProfile={
+                          "loginId":"loginId",
+                          "loginPwd":"loginPwd1"
+                        };
+    component.profile.loginId="loginId";
+    component.profile.loginPwd="loginPwd2"
+    component.saveProfile()
+  })
+
+  it('should test saveProfile method',()=>{
+    component.oriProfile={
+                          "loginId":"loginId",
+                          "loginPwd":"loginPwd"
+                        };
+    component.profile.loginId="loginId";
+    component.profile.loginPwd="loginPwd";
+    component.stateList=[{"value":"value"}];
+    component.profile.state="value";
+    component.ociCountries=[{"value":"India"}];
+    component.profile.country="India";
+    component.ociTimeZones=[{"value":"Indian"}];
+    component.profile.timeZoneId="Indian";
+    component.postData={
+    profile: "profile",
+    selectedCountry:"selectedCountry",
+    selectedState:"selectedState",
+    selectedTimeZone:"selectedTimeZone"
+        };
+    component.profileId="profileId";
+    let spy= spyOn(profileService,'saveProfile').and.returnValue(Observable.of('your object'));
+    component.saveProfile()
+    expect(spy).toHaveBeenCalled();
+  });
 
   it('should test toggleRoles method',()=>{
     component.ociavailableRoles=[{"ociavailableRoles":"ociavailableRoles"}];