Unverified Commit 461a9d32 authored by harishkumar gangula's avatar harishkumar gangula Committed by GitHub
Browse files

Merge pull request #2859 from santoshilimi/release-2.6.2

Issue #SB-15834 feat: Unit test cases for component and service for report other issue(raise ticket)
parents 4706d621 d8e1b541
master Dark_theme SB-25589 SB-28090 aws_fileRead contributions dependabot/npm_and_yarn/src/app/client/decode-uri-component-0.2.2 dependabot/npm_and_yarn/src/app/decode-uri-component-0.2.2 dependabot/npm_and_yarn/src/app/express-4.17.3 dependabot/npm_and_yarn/src/app/jsonwebtoken-9.0.0 dependabot/npm_and_yarn/src/desktop/OpenRAP/decode-uri-component-0.2.2 dependabot/npm_and_yarn/src/desktop/OpenRAP/express-4.17.3 dependabot/npm_and_yarn/src/desktop/OpenRAP/jsonwebtoken-9.0.0 dependabot/npm_and_yarn/src/desktop/OpenRAP/qs-6.5.3 dependabot/npm_and_yarn/src/desktop/decode-uri-component-0.2.2 dependabot/npm_and_yarn/src/desktop/express-4.17.3 dependabot/npm_and_yarn/src/desktop/jsonwebtoken-9.0.0 dependabot/npm_and_yarn/src/desktop/qs-6.10.3 filters_5.1.1 gcp gcp_test keshavprasadms-patch-1 keshavprasadms-patch-2 release-2.10.0 release-2.10.1 release-2.10.2 release-2.10.3 release-2.6.0 release-2.6.0-loadtest release-2.6.5 release-2.6.6 release-2.7.0 release-2.8.0 release-2.8.1 release-2.8.10 release-2.8.11 release-2.8.12 release-2.8.2 release-2.8.3 release-2.8.4 release-2.8.5 release-2.8.6 release-2.8.7 release-2.8.8 release-2.8.9 release-2.9.0 release-3.0 release-3.0-merge release-3.0.0 release-3.0.1 release-3.0.2 release-3.0.3 release-3.0.4 release-3.0.4-sso release-3.1.0 release-3.1.1 release-3.1.2 release-3.2.0 release-3.2.1 release-3.2.10 release-3.2.11 release-3.2.12 release-3.2.13 release-3.2.14 release-3.2.2 release-3.2.3 release-3.2.4 release-3.3.0 release-3.3.0-telemetry-fix release-3.3.1 release-3.3.2 release-3.4.0 release-3.4.1 release-3.4.2 release-3.4.3 release-3.4.4 release-3.4.5 release-3.4.6 release-3.4.7 release-3.5.0 release-3.5.1 release-3.5.2 release-3.5.3 release-3.6.0 release-3.6.1 release-3.6.5 release-3.6.6 release-3.7.0 release-3.7.1 release-3.7.2 release-3.8.0 release-3.8.1 release-3.8.2 release-3.8.3 release-3.9.0 release-3.9.1 release-3.9.2 release-3.9.3 release-4.0.0 release-4.0.1 release-4.0.2 release-4.1 release-4.1.0 release-4.1.1 release-4.10.0 release-4.10.0.1 release-4.10.1 release-4.10.2 release-4.10.2.1 release-4.10.2.2 release-4.10.3 release-4.2.0 release-4.2.1 release-4.3.0 release-4.3.1 release-4.4.0 release-4.4.1 release-4.5.0 release-4.5.1 release-4.5.2 release-4.6.0 release-4.7.0 release-4.7.1 release-4.8.0 release-4.8.5 release-4.9.0 release-4.9.1 release-5.0.0 release-5.0.0.1 release-5.0.0.2 release-5.0.0.3 release-5.0.1 release-5.0.2 release-5.1.0 release-5.1.1 release-sonarcloud revert-3718-copypi revert-3842-release-2.8.7 revert-3890-release-2.8.9 revert-4427-player-cache-issue revert-4537-SB-19763 revert-5244-sh-809 revert-5260-SB-table-3.3.0 revert-8284-release-5.0.0 sharathkashyap-patch-1 Tags unavailable
No related merge requests found
Showing with 152 additions and 16 deletions
+152 -16
......@@ -13,6 +13,7 @@ import { ResourceService } from 'src/app/modules/shared';
import { LibraryFiltersComponent } from '../library-filters/library-filters.component';
import { SuiModule } from 'ng2-semantic-ui';
import { of, throwError } from 'rxjs';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
describe('LibraryComponent', () => {
......@@ -42,6 +43,7 @@ describe('LibraryComponent', () => {
ToasterService,
ResourceService,
OrgDetailsService],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
.compileComponents();
}));
......
......@@ -50,8 +50,8 @@
</div>
</div>
<div class="sb-modal-actions" *ngIf='!issueReportedSuccessfully'>
<button class="sb-btn sb-btn-normal sb-btn-primary" (click)="submitIssue()"
<div class="sb-modal-actions" *ngIf='!issueReportedSuccessfully' >
<button class="sb-btn sb-btn-normal sb-btn-primary" (click)="submitIssue()"
[disabled]="reportOtherissueForm.invalid">
{{resourceService.frmelmnts?.lbl?.submitIssueButton}}
</button>
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { FormBuilder } from '@angular/forms';
import { OfflineReportIssuesComponent } from './offline-report-issues.component';
xdescribe('OfflineReportIssuesComponent', () => {
import { ResourceService, SharedModule } from '@sunbird/shared';
import { of, throwError } from 'rxjs';
import { SuiModalModule } from 'ng2-semantic-ui';
import { OfflineReportIssuesService } from '../../services';
import { NO_ERRORS_SCHEMA, DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
describe('OfflineReportIssuesComponent', () => {
let component: OfflineReportIssuesComponent;
let fixture: ComponentFixture<OfflineReportIssuesComponent>;
let resourceServiceStub;
beforeEach(async(() => {
resourceServiceStub = {
instance: 'sunbird',
frmelmnts: {
lbl: {
issueReportedSuccessfuly: 'Issue reported successfully',
issueReportedSuccessfulySubNote: 'Note: Your report will be automatically sent to {instance} while online.',
errorWhileGeneratingTicket: 'Unable to raise ticket. please try again after some times.'
}
}
};
TestBed.configureTestingModule({
declarations: [ OfflineReportIssuesComponent ]
declarations: [OfflineReportIssuesComponent],
imports: [SuiModalModule, HttpClientTestingModule, SharedModule.forRoot()],
providers: [
{ provide: ResourceService, useValue: resourceServiceStub },
OfflineReportIssuesService,
FormBuilder,
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(OfflineReportIssuesComponent);
component = fixture.componentInstance;
component.instance = '';
fixture.detectChanges();
});
it('should call createReportOtherissueForm method', () => {
spyOn(component, 'createReportOtherissueForm');
component.ngOnInit();
expect(component.createReportOtherissueForm).toHaveBeenCalled();
spyOn(component, 'setValidators');
});
it('should open report issue modal when you click on Report other issue button', () => {
spyOn(component, 'openModal');
const openModal: DebugElement = fixture.debugElement;
const buttonQuerySelector = openModal.query(By.css('button.sb-btn-outline-primary'));
const button: HTMLElement = buttonQuerySelector.nativeElement;
button.click();
fixture.whenStable().then(() => {
expect(component.issueReportedSuccessfully).toBeDefined();
expect(component.openReportIssueModal).toBeDefined();
it('should create', () => {
expect(component).toBeTruthy();
});
});
it('should throw email validation error ', () => {
spyOn(component, 'setValidators');
component.ngOnInit();
let errors = {};
const email = component.reportOtherissueForm.controls['email'];
email.setValue('');
errors = email.errors || {};
expect(errors['required']).toBeTruthy();
expect(component.reportOtherissueForm.invalid).toBeTruthy();
});
it('should throw description validation error ', () => {
spyOn(component, 'setValidators');
component.ngOnInit();
let errors = {};
const description = component.reportOtherissueForm.controls['description'];
description.setValue('');
errors = description.errors || {};
expect(errors['required']).toBeTruthy();
expect(component.reportOtherissueForm.invalid).toBeTruthy();
});
it('should show success message when successfully ticket has been raised ', () => {
const offlineReportIssuesService = TestBed.get(OfflineReportIssuesService);
spyOn(offlineReportIssuesService, 'reportOtherIssue').and.returnValue(of('true'));
component.submitIssue();
expect(component.issueReportedSuccessfully).toBeDefined();
expect(component.isDisplayLoader).toBeDefined();
spyOn(component, 'createReportOtherissueForm');
});
it('should throw error an when unable raise ticket ', () => {
const offlineReportIssuesService = TestBed.get(OfflineReportIssuesService);
spyOn(offlineReportIssuesService, 'reportOtherIssue').and.returnValue(of('false'));
component.submitIssue();
expect(component.toasterService.error(resourceServiceStub.frmelmnts.lbl.errorWhileGeneratingTicket));
});
});
......@@ -2,4 +2,5 @@ export * from './connection-service/connection.service';
export * from './content-manager/content-manager.service';
export * from './electron-dialog/electron-dialog.service';
export * from './app-update/app-update.service';
export * from './offline-report-issues/offline-report-issues.service';
export * from './onboarding/onboarding.service';
export const response = {
reportOtherIssueStatusSuccess: {
'success': {
'id': 'issue reported successfully',
'ver': '1.0',
'ts': '2019-11-21T05:26:13.711Z',
'params': {
'resmsgid': 'e37178c2-9838-487b-b133-69a82b6d35ba',
'msgid': 'be134526-3d2b-4b5d-a7c1-7f307a31305f',
'status': 'successful',
'err': null,
'errmsg': null
},
'responseCode': 'OK',
'result': {}
}
},
reportOtherIssueStatusError: {
'error': {
'id': 'api.desktop.reportIssue',
'ver': '1.0',
'ts': '2019-10-25T09:39:51.560Z',
'params': {
'resmsgid': '9652a082-9677-4ccf-91e9-f138fd80c410',
'msgid': 'c246387b-a3a6-4a98-b150-73b1bbab7665',
'status': 'failed',
'err': 'ERR_INTERNAL_SERVER_ERROR',
'errmsg': 'Error while processing the request'
},
'responseCode': 'INTERNAL_SERVER_ERROR',
'result': {}
}
}
};
import { TestBed } from '@angular/core/testing';
import { SharedModule, ResourceService } from '@sunbird/shared';
import { SharedModule } from '@sunbird/shared';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { OfflineReportIssuesService } from './offline-report-issues.service';
import { PublicDataService } from '@sunbird/core';
import { CacheService } from 'ng2-cache-service';
import { of, throwError as observableThrowError } from 'rxjs';
import { response } from '../offline-report-issues/offline-report-issues.service.spec.data';
describe('OfflineReportIssuesService', () => {
beforeEach(() => TestBed.configureTestingModule({
imports: [HttpClientTestingModule, SharedModule.forRoot()]
imports: [HttpClientTestingModule, SharedModule.forRoot()],
providers: [OfflineReportIssuesService,
PublicDataService, CacheService]
}));
it('should be created', () => {
it('should be call report other issue method and successfully raise ticket case', () => {
const service: OfflineReportIssuesService = TestBed.get(OfflineReportIssuesService);
const params = {
email: 'sample@emal.com',
description: 'sample description'
};
spyOn(service, 'reportOtherIssue').and.callFake(() => of(response.reportOtherIssueStatusSuccess.success));
service.reportOtherIssue(params).subscribe(data => {
expect(data).toBe(response.reportOtherIssueStatusSuccess.success);
});
});
it('should be call report other issue method and error while submiting raise ticket case', () => {
const service: OfflineReportIssuesService = TestBed.get(OfflineReportIssuesService);
expect(service).toBeTruthy();
const params = {
email: 'sample@emal.com',
description: 'sample description'
};
spyOn(service, 'reportOtherIssue').and.returnValue(observableThrowError(response.reportOtherIssueStatusError.error));
service.reportOtherIssue(params).subscribe(data => {
}, err => {
expect(err).toBe(response.reportOtherIssueStatusError.error);
});
});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment