class googleUser {
getAuthResponse(){
return {
id_token:'idtoken'
}
}
getBasicProfile() {
return {
getName(){
return 'name'
},
getEmail(){
},
getId(){
return 'id'
}
}
}
}
let compOnInit = null;
function resetCompOnInit(comp) {
if (compOnInit == null) {
compOnInit = comp.ngOnInit;
comp.ngOnInit = function() {};
} else {
comp.ngOnInit = compOnInit;
compOnInit = null;
}
}
describe("Integration::Component", () => {
it('button click should call Attach Sign In event', async(() => {
const { comp, fixture, de, el, btn } = setup();
resetCompOnInit(comp);
fixture.detectChanges();
comp.loadAuth = function(){
return null;
}
comp.loadAuth();
class auth2 {
attachClickHandler(btn, {}, callBack){
return callBack(of(new googleUser()))
}
}
comp.auth2 = new auth2();
spyOn(comp.auth2, "attachClickHandler").and.returnValue(of(new googleUser()));
btn.addEventListener("click", ()=>{comp.attachSignin(btn)}, false);
resetCompOnInit(comp);
btn.click();
fixture.whenStable().then(() => {
comp.attachSignin(btn).then(profile=>{
console.log(195, profile)
}).catch(err=>{
console.log(197, err)
})
});
}));
//
function setup() {
TestBed.configureTestingModule({
providers: [],
declarations: [
AppComponent
]
});
const fixture = TestBed.createComponent(AppComponent);
const comp = fixture.componentInstance;
const de = fixture.debugElement;
const el = de.nativeElement;
const btn = el.querySelector("#google-login");
window["gapi"] = {
load(auth2, callback) {
return null;
},
auth2() {
function init(gapiInit){
return null
}
},
};
return { comp, fixture, de, el, btn };
}
});