Skip to content
This repository was archived by the owner on Jul 6, 2020. It is now read-only.

Unit tests written for Improving the Coverage #295

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9d471fd
testing_the_tests_written
Kajol-Kumari Feb 21, 2020
5baf0dd
added_some_more_tests
Kajol-Kumari Feb 22, 2020
b2e0a92
added_some_more_tests
Kajol-Kumari Feb 22, 2020
1ea9787
unit_tests_for_endpoint_service_added
Kajol-Kumari Feb 22, 2020
59b3ce8
unit_tests_for_app_component_added
Kajol-Kumari Feb 22, 2020
79edde2
unit_test_for_host-analytics_component_added
Kajol-Kumari Feb 22, 2020
b640d52
added_challengelist_component_test
Kajol-Kumari Feb 22, 2020
62a15a3
component_unit_tests_Added
Kajol-Kumari Feb 22, 2020
caeee34
global_service_test_improved
Kajol-Kumari Feb 24, 2020
c8f2a7e
challenge_service_test_added
Kajol-Kumari Feb 24, 2020
58b1c52
challenge_service_test_build_fixed
Kajol-Kumari Feb 24, 2020
21ea47a
tests_improved
Kajol-Kumari Feb 26, 2020
dd8baf4
removed extra files
Kajol-Kumari Feb 26, 2020
0aa324b
tests_improved
Kajol-Kumari Feb 27, 2020
2c5fd8d
test_improved
Kajol-Kumari Feb 27, 2020
4577b9a
test_for_challenge_create_component_added
Kajol-Kumari Feb 28, 2020
bdc97b5
test_for_contact_component
Kajol-Kumari Mar 6, 2020
f727c22
host_analytics_test_improved
Kajol-Kumari Mar 7, 2020
774c7bf
app_component_test_improved
Kajol-Kumari Mar 9, 2020
e8bb07b
app_component_test_improved
Kajol-Kumari Mar 9, 2020
af236af
app_component_test
Kajol-Kumari Mar 9, 2020
b627c8e
privacy_policy_component_test_improved
Kajol-Kumari Mar 9, 2020
2e70550
privacy_policy_component_test_improved
Kajol-Kumari Mar 9, 2020
37fa8da
privacy_policy_component_test_improved
Kajol-Kumari Mar 9, 2020
844e4f7
host_analytic_test_improved
Kajol-Kumari Mar 10, 2020
1780746
challengelist_component_test_improved
Kajol-Kumari Mar 10, 2020
ff0dcf7
auth_omponent_test_improved
Kajol-Kumari Mar 10, 2020
efa8d2b
challengelist_component_test_improved
Kajol-Kumari Mar 10, 2020
2cdae8a
signup_component_test_improved
Kajol-Kumari Mar 10, 2020
52e131f
teamlist_component_test_added
Kajol-Kumari Mar 10, 2020
316b492
challenge_create_test_improved
Kajol-Kumari Mar 10, 2020
d59fe7d
fix_spacing_and_suggested_changes
Kajol-Kumari May 21, 2020
3dcb306
Merge branch 'master' of https://github.com/Cloud-CV/EvalAI-ngx into …
Kajol-Kumari May 23, 2020
28f265f
Merge branch 'master' of https://github.com/Cloud-CV/EvalAI-ngx into …
Kajol-Kumari May 31, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Location } from '@angular/common';
import { TestBed, fakeAsync, tick, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router';
import { Router, NavigationEnd } from '@angular/router';
import { GlobalService } from './services/global.service';
import { AuthService } from './services/auth.service';
import { EndpointsService } from './services/endpoints.service';
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('AppComponent', () => {

}));

// Mocking promis
// Mocking promise
it('fakeAsync works', fakeAsync(() => {
const promise = new Promise((resolve) => {
setTimeout(resolve, 10);
Expand All @@ -84,4 +84,20 @@ describe('AppComponent', () => {
const app = compFixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it('should scroll event listener', async(() => {
const compFixture = TestBed.createComponent(AppComponent);
compFixture.componentInstance.onWindowScroll() ;
}));
it('should initialize the component', async(() => {
const compFixture = TestBed.createComponent(AppComponent);
compFixture.componentInstance.ngOnInit() ;
}));
it('should destroy the component', async(() => {
const compFixture = TestBed.createComponent(AppComponent);
compFixture.componentInstance.ngOnDestroy() ;
}));
it('should scroll up', async(() => {
const compFixture = TestBed.createComponent(AppComponent);
compFixture.componentInstance.scrollUp() ;
}));
});
3 changes: 3 additions & 0 deletions src/app/components/about/about.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ describe('AboutComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call ngOninit', () => {
component.ngOnInit();
});
});
1 change: 1 addition & 0 deletions src/app/components/analytics/analytics.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ describe('AnalyticsComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';

import { HostAnalyticsComponent } from './host-analytics.component';
import {ApiService} from '../../../services/api.service';
Expand All @@ -8,11 +8,10 @@ import {GlobalService} from '../../../services/global.service';
import {RouterTestingModule} from '@angular/router/testing';
import {HttpClientModule} from '@angular/common/http';
import {Routes} from '@angular/router';
import {DashboardComponent} from '../../dashboard/dashboard.component';
import {LoginComponent} from '../../auth/login/login.component';
import {NotFoundComponent} from '../../not-found/not-found.component';
import {WindowService} from '../../../services/window.service';
import {FormsModule} from '@angular/forms';
import { Observable } from 'rxjs';


const routes: Routes = [
Expand All @@ -32,7 +31,7 @@ const routes: Routes = [
];



let Observer: (observer) => void;
describe('HostAnalyticsComponent', () => {
let component: HostAnalyticsComponent;
let fixture: ComponentFixture<HostAnalyticsComponent>;
Expand All @@ -55,4 +54,93 @@ describe('HostAnalyticsComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should show HostTeam', inject([ApiService, GlobalService], (service: ApiService, service2: GlobalService) => {
spyOn(service, 'getUrl').and.returnValue(new Observable((observer) => {
observer.next({'status' : 200});
observer.complete();
return {unsubscribe() {}};
}));
fixture.detectChanges();
spyOn(service2, 'showToast').and.callThrough();
component.getHostTeam();
expect(service.getUrl).toHaveBeenCalled();
expect(service2.showToast).not.toHaveBeenCalled();
}));
it('should give error for HostTeam', inject([ApiService, GlobalService], (service: ApiService, service2: GlobalService) => {
const err = {
'status': 403,
'error': 'error'
};
spyOn(service, 'getUrl').and.returnValue(new Observable((observer) => {
observer.error(err);
return {unsubscribe() {}};
}));
fixture.detectChanges();
spyOn(service2, 'showToast').and.callThrough();
component.getHostTeam();
err['status'] = 401;
component.getHostTeam();
expect(service.getUrl).toHaveBeenCalled();
expect(service2.showToast).toHaveBeenCalled();
}));
it('should show challenge Host', inject([ApiService, GlobalService], (service: ApiService, service2: GlobalService) => {
spyOn(service, 'getUrl').and.returnValue(new Observable((observer) => {
observer.next({'results': []});
observer.complete();
return { unsubscribe() {}};
}));
fixture.detectChanges();
component.getChallengeHost();
expect(service.getUrl).toHaveBeenCalled();
}));
it('should show challenge Analysis', inject([ApiService, GlobalService, EndpointsService],
(service: ApiService, service2: GlobalService, service3: EndpointsService) => {
const result = {
'participant_team_count': 1,
'results': [{'id': '1'}],
'challenge_phase': '1',
'last_submission_timestamp_in_challenge_phase': '2020-03-10',
'status': 403,
'error': 'err'
};
spyOn(service, 'getUrl').and.returnValue(new Observable((observer) => {
observer.next(result);
observer.error(result);
observer.complete();
return {unsubscribe() {}};
}));
fixture.detectChanges();
spyOn(service2, 'startLoader').and.callThrough();
spyOn(service3, 'teamCountAnalyticsURL').and.callThrough();
component.showChallengeAnalysis();
component.challengeId = '1';
component.challengeList = [{'id': 1}];
component.showChallengeAnalysis();
expect(service2.startLoader).toHaveBeenCalled();
expect(service.getUrl).toHaveBeenCalled();
expect(service3.teamCountAnalyticsURL).toHaveBeenCalled();
}));
it('should download challenge participant team', inject([EndpointsService, ApiService],
(service: EndpointsService, service2: ApiService) => {
const result = {
'results' : [{'id': '1'}],
'error': {'error': 'Test Error'}
};
Observer = (observer) => {
observer.next(result);
observer.error(result);
observer.next(result);
observer.complete();
return {unsubscribe() {}};
};
spyOn(service2, 'getUrl').and.returnValue(new Observable (Observer));
fixture.detectChanges();
spyOn(service, 'downloadParticipantsAnalyticsURL').and.callThrough();
component.challengeId = '1';
component.downloadChallengeParticipantTeams();
expect(service.downloadParticipantsAnalyticsURL).toHaveBeenCalled();
expect(service2.getUrl).toHaveBeenCalled();
}));


});
3 changes: 3 additions & 0 deletions src/app/components/auth/auth.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ describe('AuthComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should navigate to a certail url', () => {
expect(component.navigateTo('/')).toBeUndefined();
});
});
56 changes: 52 additions & 4 deletions src/app/components/auth/login/login.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
import { LoginComponent } from './login.component';
import { InputComponent } from '../../utility/input/input.component';
import { RouterTestingModule } from '@angular/router/testing';
Expand All @@ -11,6 +10,25 @@ import { WindowService } from '../../../services/window.service';
import { ApiService } from '../../../services/api.service';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { Routes } from '@angular/router';
import { NotFoundComponent } from '../../not-found/not-found.component';
import { Observable } from 'rxjs';

const routes: Routes = [
{
path: '',
component: LoginComponent,
},
{
path: '404',
component: NotFoundComponent,
},
{
path: '**',
redirectTo: '/404',
pathMatch: 'full'
}
];


describe('LoginComponent', () => {
Expand All @@ -19,15 +37,15 @@ describe('LoginComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoginComponent, InputComponent ],
declarations: [ LoginComponent, InputComponent, NotFoundComponent ],
providers: [
GlobalService,
AuthService,
WindowService,
ApiService,
EndpointsService
],
imports: [ RouterTestingModule, HttpClientModule, FormsModule ],
imports: [ RouterTestingModule.withRoutes(routes), HttpClientModule, FormsModule ],
schemas: [ NO_ERRORS_SCHEMA ]
})
.compileComponents();
Expand All @@ -42,4 +60,34 @@ describe('LoginComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call ngAfterViewInit', () => {
expect(component.ngAfterViewInit()).toBe();
});
it('should call userLogin without error', inject([ApiService], (service2: ApiService) => {
spyOn(service2, 'postUrl').and.returnValue(new Observable((observation) => {
observation.next({'token': [{}]});
observation.complete();
return {unsubscribe() {}};
}));
fixture.detectChanges();
component.userLogin(false);
component.userLogin(true);
expect(service2.postUrl).toHaveBeenCalled();
}));
it(' should call userLogin with error' , inject([ApiService], (service: ApiService) => {
let err = {};
spyOn(service, 'postUrl').and.returnValue(new Observable((observation) => {
observation.error(err);
return {unsubscribe() {}};
}));
fixture.detectChanges();
component.userLogin(true);
err = {'status': 400};
fixture.detectChanges();
component.userLogin(true);
err = {'status': 400, 'error': {'non_field_errirs': ['Testing Error']}};
fixture.detectChanges();
component.userLogin(true);
expect(service.postUrl).toHaveBeenCalled();
}));
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';

import { ResetPasswordConfirmComponent } from './reset-password-confirm.component';
import {RouterTestingModule} from '@angular/router/testing';
Expand All @@ -9,6 +9,8 @@ import {AuthService} from '../../../services/auth.service';
import {WindowService} from '../../../services/window.service';
import {ApiService} from '../../../services/api.service';
import {EndpointsService} from '../../../services/endpoints.service';
import { Observable } from 'rxjs';


describe('ResetPasswordConfirmComponent', () => {
let component: ResetPasswordConfirmComponent;
Expand Down Expand Up @@ -38,4 +40,45 @@ describe('ResetPasswordConfirmComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should confirm reset password', inject([ApiService], (service: ApiService) => {
spyOn(service, 'postUrl').and.returnValue(new Observable((observation) => {
observation.next({'data': {'detail': 'detail_goes_here'}});
observation.complete();
return {unsubscribe() {}};
}));
fixture.detectChanges();
component.resetPasswordConfirm(false);
component.resetPasswordConfirm(true);
expect(service.postUrl).toHaveBeenCalled();
}));
it('should call confirmresetPasswordwith error', inject([ApiService], (service: ApiService) => {
let err = {};
spyOn(service, 'postUrl').and.returnValue(new Observable((observation) => {
observation.error(err);
return {unsubscribe() {}};
}));
fixture.detectChanges();
component.resetPasswordConfirm(true);
err = {'status': 400};
fixture.detectChanges();
component.resetPasswordConfirm(true);

err = {'status': 400, 'error': {'non_field_errors': ['Testing']}};
fixture.detectChanges();
component.resetPasswordConfirm(true);

err = {'status': 400, 'error': {'token': ['Testing']}};
fixture.detectChanges();
component.resetPasswordConfirm(true);

err = {'status': 400, 'error': {'new_password1': ['Testing']}};
fixture.detectChanges();
component.resetPasswordConfirm(true);

err = {'status': 400, 'error': {'new_password2': ['Testing']}};
fixture.detectChanges();
component.resetPasswordConfirm(true);
expect(service.postUrl).toHaveBeenCalled();

}));
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';

import {ResetPasswordComponent} from './reset-password.component';
import {FormsModule} from '@angular/forms';
Expand All @@ -8,6 +8,7 @@ import {EndpointsService} from '../../../services/endpoints.service';
import {ApiService} from '../../../services/api.service';
import {HttpClientModule} from '@angular/common/http';
import {RouterTestingModule} from '@angular/router/testing';
import { Observable } from 'rxjs';

describe('ResetPasswordComponent', () => {
let component: ResetPasswordComponent;
Expand All @@ -31,4 +32,25 @@ describe('ResetPasswordComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should reset password with valid parameters', inject([ApiService], (service: ApiService) => {
spyOn(service, 'postUrl').and.returnValue(new Observable((observation) => {
observation.next({'detail': 'testing_detail_goes_here'});
observation.complete();
return {unsubscribe() {}};
}));
fixture.detectChanges();
component.resetPassword(false);
component.resetPassword(true);
expect(service.postUrl).toHaveBeenCalled();
}));
it('should call resetPassword function with error', inject([ApiService], (service: ApiService) => {
const error = {};
spyOn(service, 'postUrl').and.returnValue(new Observable((observation) => {
observation.error(error);
return {unsubscribe() {}};
}));
fixture.detectChanges();
component.resetPassword(true);
expect(service.postUrl).toHaveBeenCalled();
}));
});
Loading