Skip to content

Commit

Permalink
test(karma): update ui unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri authored and irmana committed Jun 9, 2018
1 parent ae264ae commit 52121f4
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import { FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { Router, ActivatedRoute } from '@angular/router';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { of } from 'rxjs/observable/of';
import { of } from 'rxjs';

import { AppBuildDetailsComponent } from './app-build-details.component';
import { ApiService } from '../../services/api.service';
import { AuthService } from '../../services/auth.service';
import { SocketService } from '../../services/socket.service';
import { NotificationService } from '../../services/notification.service';
import { TimeService } from '../../services/time.service';
import { Observable } from 'rxjs/Observable';
import { ToTimePipe } from '../../pipes/to-time.pipe';
import * as buildData from '../../../testing/xhr-data/build.json';
import * as buildTagData from '../../../testing/xhr-data/build-tag.json';
Expand Down
3 changes: 1 addition & 2 deletions src/app/components/app-job/app-job.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { Router, ActivatedRoute } from '@angular/router';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { of } from 'rxjs/observable/of';
import { of } from 'rxjs';

import { AppJobComponent } from './app-job.component';
import { ApiService } from '../../services/api.service';
import { AuthService } from '../../services/auth.service';
import { SocketService } from '../../services/socket.service';
import { TimeService } from '../../services/time.service';
import { Observable } from 'rxjs/Observable';
import { ToTimePipe } from '../../pipes/to-time.pipe';
import * as jobData from '../../../testing/xhr-data/job.json';
import * as jobTagData from '../../../testing/xhr-data/job-tag.json';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class AppRepositoriesComponent implements OnInit {
this.repositories = repositories;
this.repositories.forEach((repo: any, i) => {
this.apiService.getBadge(repo.id).subscribe(badge => {
if (badge.ok) {
if (badge.ok && badge._body && typeof badge._body === 'string') {
this.repositories[i].status_badge = badge._body.replace(/url\(/g, 'url(' + document.location.href);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { Router, ActivatedRoute } from '@angular/router';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { of } from 'rxjs/observable/of';
import { of } from 'rxjs';

import { AppRepositoryComponent } from './app-repository.component';
import { AppHeaderComponent } from '../app-header/app-header.component';
Expand All @@ -16,8 +16,7 @@ import { AuthService } from '../../services/auth.service';
import { SocketService } from '../../services/socket.service';
import { ConfigService } from '../../services/config.service';
import { NotificationService } from '../../services/notification.service';
import { NgUploaderModule } from 'ngx-uploader';
import { Observable } from 'rxjs/Observable';
import { NgxUploaderModule } from 'ngx-uploader';
import { SafeHtmlPipe } from '../../pipes/safe-html.pipe';
import * as buildsData from '../../../testing/xhr-data/builds.json';
import * as repositoryData from '../../../testing/xhr-data/repository.json';
Expand Down Expand Up @@ -53,7 +52,7 @@ describe('Repository Component', () => {

beforeEach(async(() => {
fixture = TestBed.configureTestingModule({
imports: [NgUploaderModule, FormsModule, RouterTestingModule, HttpModule],
imports: [NgxUploaderModule, FormsModule, RouterTestingModule, HttpModule],
declarations: [AppRepositoryComponent, AppHeaderComponent, AppToggleComponent, SafeHtmlPipe],
schemas: [NO_ERRORS_SCHEMA],
providers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export class AppRepositoryComponent implements OnInit, OnDestroy {

fetchBadge(): void {
this.api.getBadge(parseInt(this.id, 10)).subscribe(event => {
if (event.ok) {
if (event.ok && event._body && typeof event._body === 'string') {
this.statusBadge = event._body.replace(/ \r/g, '').replace(/url\(/g, 'url(' + document.location.href).trim();
}
});
Expand Down
3 changes: 1 addition & 2 deletions src/app/components/app-team/app-team.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import { FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { Router, ActivatedRoute } from '@angular/router';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { of } from 'rxjs/observable/of';
import { of } from 'rxjs';

import { AppTeamComponent } from './app-team.component';
import { AppSelectboxComponent } from '../app-selectbox/app-selectbox.component';
import { ApiService } from '../../services/api.service';
import { AuthService } from '../../services/auth.service';
import { SocketService } from '../../services/socket.service';
import { ConfigService } from '../../services/config.service';
import { Observable } from 'rxjs/Observable';
import * as usersData from '../../../testing/xhr-data/users.json';

describe('Team Component', () => {
Expand Down
7 changes: 3 additions & 4 deletions src/app/components/app-user/app-user.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { Router, ActivatedRoute } from '@angular/router';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { of } from 'rxjs/observable/of';
import { of } from 'rxjs';

import { AppUserComponent } from './app-user.component';
import { AppHeaderComponent } from '../app-header/app-header.component';
Expand All @@ -16,8 +16,7 @@ import { AuthService } from '../../services/auth.service';
import { SocketService } from '../../services/socket.service';
import { ConfigService } from '../../services/config.service';
import { NotificationService } from '../../services/notification.service';
import { NgUploaderModule } from 'ngx-uploader';
import { Observable } from 'rxjs/Observable';
import { NgxUploaderModule } from 'ngx-uploader';
import * as userData from '../../../testing/xhr-data/user.json';
import * as repositoriesData from '../../../testing/xhr-data/repositories.json';

Expand All @@ -27,7 +26,7 @@ describe('User Component', () => {

beforeEach(async(() => {
fixture = TestBed.configureTestingModule({
imports: [NgUploaderModule, FormsModule, RouterTestingModule, HttpModule],
imports: [NgxUploaderModule, FormsModule, RouterTestingModule, HttpModule],
declarations: [AppUserComponent, AppHeaderComponent, AppToggleComponent],
schemas: [NO_ERRORS_SCHEMA],
providers: [
Expand Down
10 changes: 3 additions & 7 deletions src/app/services/api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { HttpModule, Http, XHRBackend, Response, ResponseOptions } from '@angula
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { ApiService } from './api.service';
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/catch';
import * as buildsData from '../../testing/xhr-data/builds.json';

describe('API Service (mockBackend)', () => {
Expand Down Expand Up @@ -53,10 +50,9 @@ describe('API Service (mockBackend)', () => {
it('should have expected fake builds (then)', async(inject([], () => {
backend.connections.subscribe((c: MockConnection) => c.mockRespond(response));

service.getBuilds(5, 0, 'all').toPromise()
.then(builds => {
expect(builds.length).toBe(fakeBuilds.length, 'should have expected no. of builds');
});
service.getBuilds(5, 0, 'all').subscribe(builds => {
expect(builds.length).toBe(fakeBuilds.length, 'should have expected no. of builds');
});
})));

});
Expand Down

0 comments on commit 52121f4

Please sign in to comment.