Skip to content

Commit

Permalink
test cases modifies, gh-page config added
Browse files Browse the repository at this point in the history
  • Loading branch information
SooryaSoorya committed Apr 29, 2020
1 parent b22c35b commit a19b60d
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 23 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"name": "ng-movie-app",
"version": "0.0.0",
"homepage": "https://SooryaSoorya.github.io/ng-movie-app",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
"e2e": "ng e2e",
"deploy": "gh-pages -d dist"
},
"private": true,
"dependencies": {
Expand All @@ -28,10 +30,11 @@
"@angular/cli": "9.1.1",
"@angular/compiler-cli": "9.1.2",
"@angular/language-service": "9.1.2",
"@types/node": "^12.11.1",
"@types/jasmine": "3.5.0",
"@types/jasminewd2": "2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"gh-pages": "^2.2.0",
"jasmine-core": "3.5.0",
"jasmine-spec-reporter": "4.2.1",
"karma": "4.3.0",
Expand Down
13 changes: 13 additions & 0 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MovieService } from "../app/movie/services/movie.services";

describe("AppComponent", () => {
beforeEach(async(() => {
const a = setup().default();
TestBed.configureTestingModule({
imports: [
BrowserAnimationsModule,
Expand All @@ -34,3 +35,15 @@ describe("AppComponent", () => {
expect(app.title).toEqual("ng-movie-app");
});
});

function setup() {
const builder = {
default() {
return builder;
},
build() {
return new AppComponent();
}
}
return builder;
}
20 changes: 20 additions & 0 deletions src/app/loader/loader.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('LoaderComponent', () => {
let fixture: ComponentFixture<LoaderComponent>;

beforeEach(async(() => {
const a = setup().default();
TestBed.configureTestingModule({
declarations: [ LoaderComponent ]
})
Expand All @@ -22,4 +23,23 @@ describe('LoaderComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('when ngOnInit is called it should', () => {

const { build } = setup().default();
const c = build();

c.ngOnInit();
});
});

function setup() {
const builder = {
default() {
return builder;
},
build() {
return new LoaderComponent();
}
}
return builder;
}
29 changes: 29 additions & 0 deletions src/app/movie-detail/movie-detail.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe("MovieDetailComponent", () => {
let fixture: ComponentFixture<MovieDetailComponent>;

beforeEach(async(() => {
const a = setup().default();
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [MovieDetailComponent],
Expand All @@ -32,4 +33,32 @@ describe("MovieDetailComponent", () => {
it("should create", () => {
expect(component).toBeTruthy();
});
it("when ngOnInit is called it should", () => {
const { build } = setup().default();
const c = build();
c.ngOnInit();
});
it("when getMovieDetails is called it should", () => {
const { build } = setup().default();
const param = { id: "1" };
const c = build();
c.getMovieDetails(param["id"]);
});
});

function setup() {
const activatedRoute = jasmine.createSpyObj(ActivatedRoute);
const httpClientSpy = jasmine.createSpyObj("HttpClient", ["get"]);
const movieService = new MovieService(<any>httpClientSpy);
const builder = {
movieService,
activatedRoute,
default() {
return builder;
},
build() {
return new MovieDetailComponent(movieService, activatedRoute);
},
};
return builder;
}
89 changes: 79 additions & 10 deletions src/app/movie/movie.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,98 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from "@angular/common/http/testing";
import {
async,
ComponentFixture,
TestBed,
getTestBed,
fakeAsync,
tick,
} from "@angular/core/testing";
import {
HttpClientTestingModule,
HttpTestingController,
} from "@angular/common/http/testing";
import { HttpParams } from "@angular/common/http";

import { MovieComponent } from './movie.component';
import { MovieService } from "../movie/services/movie.services";
import { MovieComponent } from "./movie.component";
import { MovieService } from "./services/movie.services";
import { API_CONIG } from ".././shared/constants";

describe('MovieComponent', () => {
describe("MovieComponent", () => {
let component: MovieComponent;
let fixture: ComponentFixture<MovieComponent>;
let injector;
let movieService: {
fetchFaults: () => {
(): any;
new (): any;
subscribe: { (arg0: (_: any) => Promise<void>): void; new (): any };
};
};
let httpMock: HttpTestingController;

beforeEach(async(() => {
const a = setup().default();
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [ MovieComponent ],
providers: [MovieService]
})
.compileComponents();
declarations: [MovieComponent],
providers: [MovieService],
}).compileComponents();

injector = getTestBed();
movieService = injector.get(MovieService);
httpMock = injector.get(HttpTestingController);
}));

afterEach(() => {
httpMock.verify();
});

beforeEach(() => {
fixture = TestBed.createComponent(MovieComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
it("should create", () => {
expect(component).toBeTruthy();
});

it("when ngOnInit is called it should", () => {
const { build } = setup().default();
const c = build();
c.ngOnInit();
});

it("should get the faults", fakeAsync(() => {
const results = { data: [] };
const moviesEndpoint = `${API_CONIG.API_ENDPOINT}?apikey=${API_CONIG.API_KEY}`;
const dummyHosts = [
{_items: 'Hosts list'}
];
const dummyParams = new HttpParams()
.append('where', JSON.stringify({'_is_template': false}))
.append('max_results', JSON.stringify(25));

const req = httpMock.expectOne(
(req) => req.method === "GET" && req.url === moviesEndpoint
);
expect(req.request.params.get("where")).toEqual('{"_is_template":false}');
req.flush(dummyHosts);
}));


});

function setup() {
const httpClientSpy = jasmine.createSpyObj("HttpClient", ["get"]);
const movieService = new MovieService(<any>httpClientSpy);
const builder = {
movieService,
default() {
return builder;
},
build() {
return new MovieComponent(movieService);
},
};
return builder;
}
3 changes: 1 addition & 2 deletions src/app/movie/movie.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ export class MovieComponent implements OnInit {
}

onNavMenuChange(movies: Movie[]) {
console.log("onNavMenuChange", movies);
this.movies = movies;
}

showLoading(loading: boolean) {
public showLoading(loading: boolean) {
this.loading = loading;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/nav-menu/nav-menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<nav class="ngma-navigation">
<ul>
<li *ngFor="let genre of objectKeys(movieGenre)">
<a [ngClass]="{'active': genre.toLowerCase() == selectedGenre}" (click)="changeMenuItem($event)"
<a class="ngma-menugenre" [ngClass]="{'active': genre.toLowerCase() == selectedGenre}" (click)="changeMenuItem($event)"
href="#">
{{genre}}
</a>
Expand Down
53 changes: 45 additions & 8 deletions src/app/nav-menu/nav-menu.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
import { HttpClientTestingModule } from "@angular/common/http/testing";

import { NavMenuComponent } from './nav-menu.component';
import { NavMenuComponent } from "./nav-menu.component";
import { MovieService } from "../movie/services/movie.services";
import { DebugElement, ElementRef } from "@angular/core";
import { By } from "@angular/platform-browser";

describe('NavMenuComponent', () => {
describe("NavMenuComponent", () => {
let component: NavMenuComponent;
let fixture: ComponentFixture<NavMenuComponent>;
let debugEl: DebugElement;
let menuItem: ElementRef;

beforeEach(async(() => {
const a = setup().default();
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [ NavMenuComponent ],
providers: [MovieService]
})
.compileComponents();
declarations: [NavMenuComponent],
providers: [MovieService],
}).compileComponents();
}));

beforeEach(() => {
Expand All @@ -23,7 +27,40 @@ describe('NavMenuComponent', () => {
fixture.detectChanges();
});

it('should create', () => {
it("should create", () => {
expect(component).toBeTruthy();
});
it("when ngOnInit is called it should", () => {
const { build } = setup().default();
const c = build();
c.ngOnInit();
});
it("when changeMenuItem is called it should", () => {
var event = {
type: "click",
stopPropagation: function () {},
preventDefault: function () {},
target: { innerText: "Action" },
};
console.log("ElementRef", event);
const { build } = setup().default();
const c = build();
fixture.detectChanges();
c.changeMenuItem(event);
});
});

function setup() {
const httpClientSpy = jasmine.createSpyObj("HttpClient", ["get"]);
const movieService = new MovieService(<any>httpClientSpy);
const builder = {
movieService,
default() {
return builder;
},
build() {
return new NavMenuComponent(movieService);
},
};
return builder;
}
18 changes: 18 additions & 0 deletions src/app/no-data/no-data.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('NoDataComponent', () => {
let fixture: ComponentFixture<NoDataComponent>;

beforeEach(async(() => {
const a = setup().default();
TestBed.configureTestingModule({
declarations: [ NoDataComponent ]
})
Expand All @@ -22,4 +23,21 @@ describe('NoDataComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('when ngOnInit is called it should', () => {
const { build } = setup().default();
const c = build();
c.ngOnInit();
});
});

function setup() {
const builder = {
default() {
return builder;
},
build() {
return new NoDataComponent();
}
}
return builder;
}
21 changes: 21 additions & 0 deletions src/app/search-bar/search-bar.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("SearchBarComponent", () => {
let fixture: ComponentFixture<SearchBarComponent>;

beforeEach(async(() => {
const a = setup().default();
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [SearchBarComponent],
Expand All @@ -25,4 +26,24 @@ describe("SearchBarComponent", () => {
it("should create", () => {
expect(component).toBeTruthy();
});
it('when ngOnInit is called it should', () => {
const { build } = setup().default();
const c = build();
c.ngOnInit();
});
});

function setup() {
const httpClientSpy = jasmine.createSpyObj("HttpClient", ["get"]);
const movieService = new MovieService(<any>httpClientSpy);
const builder = {
movieService,
default() {
return builder;
},
build() {
return new SearchBarComponent(movieService);
}
}
return builder;
}
Loading

0 comments on commit a19b60d

Please sign in to comment.