Fixed the test cases,added sonar config
[portal.git] / portal-FE-common / src / app / pages / users / users.component.spec.ts
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
39
40 import { UsersComponent } from './users.component';
41 import { HttpClientTestingModule } from '@angular/common/http/testing';
42 import { FormsModule } from '@angular/forms';
43 import { NgMaterialModule } from 'src/app/ng-material-module';
44 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
45 import { NewUserModalComponent } from './new-user-modal/new-user-modal.component';
46 import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
47 import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
48 import { BulkUserComponent } from './bulk-user/bulk-user.component';
49 import { ConfirmationModalComponent } from 'src/app/modals/confirmation-modal/confirmation-modal.component';
50 import { Component, Input } from '@angular/core';
51
52 describe('UsersComponent', () => {
53   let component: UsersComponent;
54   let fixture: ComponentFixture<UsersComponent>;
55
56   beforeEach(async(() => {
57     TestBed.configureTestingModule({
58       declarations: [ UsersComponent, NewUserModalComponent,BulkUserComponent,ConfirmationModalComponent,AppSearchUsersStubComponent,AppUsersdetailsFormStubComponent],
59       imports:[HttpClientTestingModule,FormsModule,NgMaterialModule,BrowserAnimationsModule,NgbModule.forRoot()]
60     }).overrideModule(BrowserDynamicTestingModule, { set: { entryComponents: [NewUserModalComponent,BulkUserComponent,ConfirmationModalComponent] } })
61     .compileComponents();
62   }));
63
64   beforeEach(() => {
65     fixture = TestBed.createComponent(UsersComponent);
66     component = fixture.componentInstance;
67     fixture.detectChanges();
68   });
69
70   it('should create', () => {
71     expect(component).toBeTruthy();
72   });
73
74   it('openAddNewUserModal should return stubbed value', () => {
75     spyOn(component, 'openAddNewUserModal').and.callThrough();
76     component.openAddNewUserModal();
77     expect(component.openAddNewUserModal).toHaveBeenCalledWith();
78   });
79   it('openExistingUserModal should return stubbed value', () => {
80     spyOn(component, 'openExistingUserModal').and.callThrough();
81     let user ={"firstName":"FirstTestName","lastName":"LastTestName","orgUserId":""};
82     component.openExistingUserModal(user);
83     expect(component.openExistingUserModal).toHaveBeenCalledWith(user);
84   });
85
86   it('openBulkUserUploadModal should return stubbed value', () => {
87     spyOn(component, 'openBulkUserUploadModal').and.callThrough();
88     component.openBulkUserUploadModal();
89     expect(component.openBulkUserUploadModal).toHaveBeenCalledWith();
90   });
91   it('applyDropdownFilter should return stubbed value', () => {
92     spyOn(component, 'applyDropdownFilter').and.callThrough();
93     let _appValue= {"value":"select-application"};
94     component.applyDropdownFilter(_appValue);
95     expect(component.applyDropdownFilter).toHaveBeenCalledWith(_appValue);
96     _appValue= {"value":"Test"};
97     component.applyDropdownFilter(_appValue);
98     expect(component.applyDropdownFilter).toHaveBeenCalledWith(_appValue);
99   });
100   it('applyFilter should return stubbed value', () => {
101     spyOn(component, 'applyFilter').and.callThrough();
102     component.applyFilter("Test");
103     expect(component.applyFilter).toHaveBeenCalledWith("Test");
104   });
105   it('getAdminApps should return stubbed value', () => {
106     spyOn(component, 'getAdminApps').and.callThrough();
107     component.getAdminApps();
108     expect(component.getAdminApps).toHaveBeenCalledWith();
109   });
110 });
111
112 @Component({selector: 'app-search-users', template: ''})
113 class AppSearchUsersStubComponent {
114 @Input() searchTitle:any;
115 @Input() isSystemUser:boolean;
116 @Input() placeHolder:any;
117
118
119 }
120 @Component({selector: 'app-user-details-form', template: ''})
121 class AppUsersdetailsFormStubComponent {
122
123 }
124