-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve conflicts in files for test cases #74
Changes from 11 commits
76294a1
326a7d5
ea40ba4
76a4771
caff967
2cf951f
798de14
8adfe21
c2496f4
1f09639
d6743b3
140b0ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,49 +22,103 @@ | |
* @author Vitaliy Fedoriv | ||
*/ | ||
|
||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core'; | ||
|
||
import {OwnerAddComponent} from './owner-add.component'; | ||
import { async, ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core'; | ||
import {FormsModule} from '@angular/forms'; | ||
import {Router} from '@angular/router'; | ||
import {OwnerService} from '../owner.service'; | ||
import {RouterTestingModule} from '@angular/router/testing'; | ||
import {RouterStub} from '../../testing/router-stubs'; | ||
import {Owner} from '../owner'; | ||
import {Observable, of} from 'rxjs'; | ||
import { OwnerAddComponent } from "./owner-add.component"; | ||
import { By } from "@angular/platform-browser"; | ||
import { OwnersRoutingModule } from "../owners-routing.module"; | ||
import { OwnerListComponent } from "../owner-list/owner-list.component"; | ||
|
||
class OwnserServiceStub { | ||
|
||
addOwner(owner: Owner): Observable<Owner> { | ||
return of(owner); | ||
} | ||
} | ||
|
||
describe('OwnerAddComponent', () => { | ||
describe("OwnerAddComponent", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linting should be apply |
||
let component: OwnerAddComponent; | ||
let fixture: ComponentFixture<OwnerAddComponent>; | ||
let router: Router; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [OwnerAddComponent], | ||
schemas: [CUSTOM_ELEMENTS_SCHEMA], | ||
imports: [FormsModule, RouterTestingModule], | ||
providers: [ | ||
{provide: OwnerService, useClass: OwnserServiceStub}, | ||
{provide: Router, useClass: RouterStub} | ||
] | ||
}) | ||
.compileComponents(); | ||
{ provide: OwnerService, useClass: OwnserServiceStub }, | ||
{ provide: Router, useClass: RouterStub }, | ||
], | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(OwnerAddComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
router = TestBed.get(Router); | ||
}); | ||
|
||
it('should create OwnerAddComponent', () => { | ||
it("should create OwnerAddComponent", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it("First Name check invalid", async(() => { | ||
fixture.whenStable().then(() => { | ||
let firstName = component.ownerForm.controls["firstName"]; | ||
expect(firstName.valid).toBeFalsy(); | ||
expect(component.ownerForm.valid).toBeFalsy(); | ||
firstName.setValue("J"); | ||
expect(firstName.errors["minlength"]).toBeTruthy(); | ||
firstName.setValue("John"); | ||
expect(firstName.errors).toBeFalsy(); | ||
}); | ||
})); | ||
|
||
it("First Name check invalid", async(() => { | ||
fixture.whenStable().then(() => { | ||
let lastName = component.ownerForm.controls["lastName"]; | ||
expect(lastName.valid).toBeFalsy(); | ||
expect(component.ownerForm.valid).toBeFalsy(); | ||
lastName.setValue("S"); | ||
expect(lastName.errors["minlength"]).toBeTruthy(); | ||
lastName.setValue("Smith"); | ||
expect(lastName.errors).toBeFalsy(); | ||
}); | ||
})); | ||
|
||
it("check form submission is successful", async(() => { | ||
fixture.whenStable().then(() => { | ||
let firstName = component.ownerForm.form.controls["firstName"]; | ||
let lastName = component.ownerForm.form.controls["lastName"]; | ||
|
||
firstName.setValue("Mary"); | ||
lastName.setValue("John"); | ||
let ownerServiceStub = new OwnserServiceStub(); | ||
let owner = { | ||
id: 0, | ||
firstName: "Mary", | ||
lastName: "John", | ||
address: "", | ||
city: "", | ||
telephone: "", | ||
pets: [], | ||
}; | ||
let buttons = fixture.debugElement.queryAll(By.css("button")); | ||
let addButton = buttons[1].nativeElement; | ||
addButton.click(); | ||
spyOn(router, "navigate"); | ||
spyOn(component, "gotoOwnersList").and.callThrough(); | ||
component.gotoOwnersList(); | ||
expect(router.navigate).toHaveBeenCalledWith(["/owners"]); | ||
}); | ||
})); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,11 @@ | |
* @author Vitaliy Fedoriv | ||
*/ | ||
|
||
import {Component, OnInit} from '@angular/core'; | ||
import {Component, OnInit, ViewChild} from '@angular/core'; | ||
import {OwnerService} from '../owner.service'; | ||
import {Owner} from '../owner'; | ||
import {Router} from '@angular/router'; | ||
import { NgForm } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'app-owner-add', | ||
|
@@ -32,6 +33,7 @@ import {Router} from '@angular/router'; | |
}) | ||
export class OwnerAddComponent implements OnInit { | ||
|
||
@ViewChild("ownerForm", { static: true }) ownerForm: NgForm; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you introduced the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it was throwing error as ownerForm not found in component ts file |
||
owner: Owner; | ||
errorMessage: string; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why disabling random?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To run the test cases in order without random seed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you fall on errors due to random execution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No i did not..i have removed now in latest commit.