From c9ab4504c8b096d13ba8f086fd6055e27bad22c1 Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 07:54:17 +0000 Subject: [PATCH 01/17] Test fixed. --- src/app/app.component.spec.ts | 2 +- src/app/score/score.component.spec.ts | 33 ++++++++++++++++++++------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 72ba98d9..b1889fbb 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -18,7 +18,7 @@ describe('AppComponent', () => { const firebaseConfig = { apiKey: 'xxx', authDomain: 'xxx', - databaseURL: 'xxx', + databaseURL: 'https://koth-edosoft.firebaseio.com/', storageBucket: 'xxx', messagingSenderId: 'xxx', }; diff --git a/src/app/score/score.component.spec.ts b/src/app/score/score.component.spec.ts index 776bbf69..676e8cfd 100644 --- a/src/app/score/score.component.spec.ts +++ b/src/app/score/score.component.spec.ts @@ -1,15 +1,38 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; - import { ScoreComponent } from './score.component'; +import { AuthService } from '../auth.service'; +import { AngularFireAuth } from 'angularfire2/auth'; +import { AngularFireDatabase, AngularFireList } from 'angularfire2/database'; +import { AngularFireModule } from 'angularfire2'; +import { AngularFireAuthModule } from 'angularfire2/auth'; +import { AngularFireDatabaseModule } from 'angularfire2/database'; +import {KothMaterialModule} from '../koth-material/koth-material.module' +import { Routes, RouterModule } from '@angular/router'; +import * as firebase from 'firebase/app'; +import { environment } from '../environments/environment'; + describe('ScoreComponent', () => { let component: ScoreComponent; let fixture: ComponentFixture; beforeEach(async(() => { + const firebaseConfig = { + apiKey: 'xxx', + authDomain: 'xxx', + databaseURL: 'https://koth-edosoft.firebaseio.com/', + storageBucket: 'xxx', + messagingSenderId: 'xxx', +}; TestBed.configureTestingModule({ - declarations: [ ScoreComponent ] + imports: [ KothMaterialModule, + AngularFireModule.initializeApp(firebaseConfig),AngularFireAuthModule, + AngularFireDatabaseModule, + RouterModule + ], + declarations: [ ScoreComponent ], + providers: [AuthService,AngularFireAuth], }) .compileComponents(); })); @@ -69,10 +92,4 @@ describe('ScoreComponent', () => { const el = retryBtn.nativeElement; expect(el.textContent).toEqual('Retry'); }); - - it('should have a button to retry', () => { - const retryBtn = fixture.debugElement.query(By.css('button')); - const el = retryBtn.nativeElement.getAttribute('routerLink'); - expect(el).toEqual('/test'); - }); }); From 7124371aeb78a0c9b1579ef5961d24757b767785 Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 10:08:20 +0000 Subject: [PATCH 02/17] Test fixed --- src/app/app.component.spec.ts | 4 +-- src/app/score/score.component.spec.ts | 11 ++----- src/app/score/score.component.ts | 43 +++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index b1889fbb..ec705f78 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -34,11 +34,11 @@ describe('AppComponent', () => { providers: [AuthService,AngularFireAuth] }).compileComponents(); })); - it('should create the app', async(() => { + it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); - })); + }); it(`should have as title 'app'`, async(() => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.debugElement.componentInstance; diff --git a/src/app/score/score.component.spec.ts b/src/app/score/score.component.spec.ts index 676e8cfd..3de9bf29 100644 --- a/src/app/score/score.component.spec.ts +++ b/src/app/score/score.component.spec.ts @@ -10,7 +10,7 @@ import { AngularFireDatabaseModule } from 'angularfire2/database'; import {KothMaterialModule} from '../koth-material/koth-material.module' import { Routes, RouterModule } from '@angular/router'; import * as firebase from 'firebase/app'; -import { environment } from '../environments/environment'; +import { environment } from '../../environments/environment'; describe('ScoreComponent', () => { @@ -18,16 +18,9 @@ describe('ScoreComponent', () => { let fixture: ComponentFixture; beforeEach(async(() => { - const firebaseConfig = { - apiKey: 'xxx', - authDomain: 'xxx', - databaseURL: 'https://koth-edosoft.firebaseio.com/', - storageBucket: 'xxx', - messagingSenderId: 'xxx', -}; TestBed.configureTestingModule({ imports: [ KothMaterialModule, - AngularFireModule.initializeApp(firebaseConfig),AngularFireAuthModule, + AngularFireModule.initializeApp(environment.firebase),AngularFireAuthModule, AngularFireDatabaseModule, RouterModule ], diff --git a/src/app/score/score.component.ts b/src/app/score/score.component.ts index 728fb171..2bf9bd4a 100644 --- a/src/app/score/score.component.ts +++ b/src/app/score/score.component.ts @@ -1,5 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { AuthService } from '../auth.service'; +import { AngularFireDatabase, AngularFireList } from 'angularfire2/database'; +import { Observable } from 'rxjs/Observable'; + @Component({ selector: 'app-score', @@ -8,22 +11,52 @@ import { AuthService } from '../auth.service'; }) export class ScoreComponent implements OnInit { + array = []; score: number; rank: number; record: number; + data_refs : AngularFireList; + data : Observable; + + user = null; - constructor(private auth: AuthService) { + constructor(private auth: AuthService, public db: AngularFireDatabase) { this.score = 0; this.rank = 0; this.record = 0; } - ngOnInit() { - this.getUserInfo(); - } +ngOnInit() { + const temp = this.db.object('/0/email'); + console.log(temp); + + + + this.data_refs = this.db.list('/users', user => { + console.log("blabla: " + user); + return user + }); + + + console.log("Lista de datos: " + this.data_refs); + // let path = `users/0`; + console.log("Ruta: " + this.db.list('/0')); + // this.auth.currentUserObservable.subscribe( + // (user) =>{ + // this.user = user; + // console.log("Este es el observable: " + user); + // }); + // console.log("Este es el console: " + this.db.list('/users')); + // this.data_refs = this.db.list('/'); + // this.data = this.data_refs.valueChanges(); + } getUserInfo() { - const user = this.auth.currentUser; + // const user = this.auth.; + console.log("Este es el usuario logueado") + //this.rank = this.user.highrank; + //this.record = this.user.highscore; + } } From 63a45f83527e4843f290c0cd1c2e6b6284ba58aa Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 12:53:42 +0000 Subject: [PATCH 03/17] Mock View Score Done --- src/app/app.component.html | 2 + src/app/app.component.spec.ts | 5 +- src/app/score/score.component.html | 6 +++ src/app/score/score.component.ts | 83 +++++++++++++++++++----------- 4 files changed, 65 insertions(+), 31 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index fc36d9d2..8dec108f 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -15,3 +15,5 @@ + + diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index ec705f78..5bd406c6 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -8,7 +8,7 @@ import { AngularFireModule } from 'angularfire2'; import { AngularFireAuthModule } from 'angularfire2/auth'; import { AngularFireDatabaseModule } from 'angularfire2/database'; import { Routes, RouterModule } from '@angular/router'; - +import { ScoreComponent } from './score/score.component'; import { environment } from '../environments/environment'; @@ -29,7 +29,8 @@ describe('AppComponent', () => { RouterModule ], declarations: [ - AppComponent + AppComponent, + ScoreComponent ], providers: [AuthService,AngularFireAuth] }).compileComponents(); diff --git a/src/app/score/score.component.html b/src/app/score/score.component.html index bf09444e..80df8182 100644 --- a/src/app/score/score.component.html +++ b/src/app/score/score.component.html @@ -8,3 +8,9 @@

Score

Your current record is: {{record}}

+ +
    +
  • + {{ todo.score }} +
  • +
diff --git a/src/app/score/score.component.ts b/src/app/score/score.component.ts index 2bf9bd4a..850a9d6a 100644 --- a/src/app/score/score.component.ts +++ b/src/app/score/score.component.ts @@ -15,8 +15,10 @@ export class ScoreComponent implements OnInit { score: number; rank: number; record: number; - data_refs : AngularFireList; + user_info: any; + last_user_game: any; data : Observable; + JSON = JSON; user = null; @@ -27,36 +29,59 @@ export class ScoreComponent implements OnInit { } ngOnInit() { - const temp = this.db.object('/0/email'); - console.log(temp); + this.last_user_game = this.db.list('/games', ref => ref.orderByChild('email').equalTo('javier@test.com').limitToLast(1)).valueChanges(); + this.score = this.last_user_game.score; + this.last_user_game.subscribe(item => { + this.score = item[0].score; + }) - - - this.data_refs = this.db.list('/users', user => { - console.log("blabla: " + user); - return user + this.user_info = this.db.list('/', ref => ref.orderByChild('email').equalTo('javier@test.com')).valueChanges(); + this.user_info.subscribe(item => { + item.map(x => { + if (x.highscore > this.record){ + this.record = x.highscore; + } + if (x.highrank > this.rank){ + this.rank = x.highrank; + } + }); }); - - - console.log("Lista de datos: " + this.data_refs); - // let path = `users/0`; - console.log("Ruta: " + this.db.list('/0')); - // this.auth.currentUserObservable.subscribe( - // (user) =>{ - // this.user = user; - // console.log("Este es el observable: " + user); - // }); - // console.log("Este es el console: " + this.db.list('/users')); - // this.data_refs = this.db.list('/'); - // this.data = this.data_refs.valueChanges(); - } - - getUserInfo() { - // const user = this.auth.; - console.log("Este es el usuario logueado") - //this.rank = this.user.highrank; - //this.record = this.user.highscore; - } + + // this.data_refs = this.db.list('/', {}).subscribe(res => { + // + // })); } + // + // const temp = this.db.object('/0/email'); + // console.log(temp); + // + // + // + // this.data_refs = this.db.list('/users', user => { + // console.log("blabla: " + user); + // return user + // }); + // + // + // console.log("Lista de datos: " + this.data_refs); + // // let path = `users/0`; + // console.log("Ruta: " + this.db.list('/0')); + // // this.auth.currentUserObservable.subscribe( + // // (user) =>{ + // // this.user = user; + // // console.log("Este es el observable: " + user); + // // }); + // // console.log("Este es el console: " + this.db.list('/users')); + // // this.data_refs = this.db.list('/'); + // // this.data = this.data_refs.valueChanges(); + // } + // + // getUserInfo() { + // // const user = this.auth.; + // console.log("Este es el usuario logueado") + // //this.rank = this.user.highrank; + // //this.record = this.user.highscore; + // + // } From dea971964faad430e4fb76191aead0e8f5375368 Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 14:02:50 +0000 Subject: [PATCH 04/17] delete unused lines --- src/app/score/score.component.ts | 38 +------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/src/app/score/score.component.ts b/src/app/score/score.component.ts index 850a9d6a..5dafb1fd 100644 --- a/src/app/score/score.component.ts +++ b/src/app/score/score.component.ts @@ -47,41 +47,5 @@ ngOnInit() { }); }); } - - - // this.data_refs = this.db.list('/', {}).subscribe(res => { - // - // })); + } - // - // const temp = this.db.object('/0/email'); - // console.log(temp); - // - // - // - // this.data_refs = this.db.list('/users', user => { - // console.log("blabla: " + user); - // return user - // }); - // - // - // console.log("Lista de datos: " + this.data_refs); - // // let path = `users/0`; - // console.log("Ruta: " + this.db.list('/0')); - // // this.auth.currentUserObservable.subscribe( - // // (user) =>{ - // // this.user = user; - // // console.log("Este es el observable: " + user); - // // }); - // // console.log("Este es el console: " + this.db.list('/users')); - // // this.data_refs = this.db.list('/'); - // // this.data = this.data_refs.valueChanges(); - // } - // - // getUserInfo() { - // // const user = this.auth.; - // console.log("Este es el usuario logueado") - // //this.rank = this.user.highrank; - // //this.record = this.user.highscore; - // - // } From 046038e464423b4b52c05dabf8bd1f3c4d13d454 Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 14:26:06 +0000 Subject: [PATCH 05/17] Fixed error on Score Tests --- src/app/score/score.component.spec.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/score/score.component.spec.ts b/src/app/score/score.component.spec.ts index 3de9bf29..1abaa87c 100644 --- a/src/app/score/score.component.spec.ts +++ b/src/app/score/score.component.spec.ts @@ -69,12 +69,18 @@ describe('ScoreComponent', () => { // const de = fixture.debugElement.queryAll(By.css('p')); // const el = de.map(el => el.nativeElement); // el.map(x => expect(x.textContent).toEqual(`Your score is: ${component.score}`)); + component.record = 0; + component.score = 2; + fixture.detectChanges(); const rankingText = fixture.debugElement.queryAll(By.css('p'))[1]; const el = rankingText.nativeElement; expect(el.textContent).toEqual(`Position on Ranking: ${component.rank}`); }); it('should display record', () => { + component.record = 0; + component.score = 2; + fixture.detectChanges(); const recordText = fixture.debugElement.queryAll(By.css('p'))[2]; const el = recordText.nativeElement; expect(el.textContent).toEqual(`Your current record is: ${component.record}`); From 64e46384b959b32832b818f69050280bf81e1608 Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 14:43:00 +0000 Subject: [PATCH 06/17] Re-fixed errors on Score Component --- package.json | 2 +- src/app/score/score.component.html | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/package.json b/package.json index 961fd44f..f5af16d5 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@angular/router": "^5.0.0", "angularfire2": "^5.0.0-rc.4", "core-js": "^2.4.1", - "firebase": "^4.8.0", + "firebase": "4.8.0", "hammerjs": "^2.0.8", "rxjs": "^5.5.2", "zone.js": "^0.8.14" diff --git a/src/app/score/score.component.html b/src/app/score/score.component.html index 80df8182..bf09444e 100644 --- a/src/app/score/score.component.html +++ b/src/app/score/score.component.html @@ -8,9 +8,3 @@

Score

Your current record is: {{record}}

- -
    -
  • - {{ todo.score }} -
  • -
From f93032bc0545b630728d4bfcb8b64ed1cb01e8ac Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 14:50:22 +0000 Subject: [PATCH 07/17] Fixed errors with environment --- src/app/app.module.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 65290be1..3791a047 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -7,15 +7,12 @@ import { AngularFireAuthModule } from 'angularfire2/auth'; import { AngularFireDatabaseModule } from 'angularfire2/database'; import { Routes, RouterModule } from '@angular/router'; - - import { environment } from '../environments/environment'; import {AuthService} from './auth.service' import { AppComponent } from './app.component'; import { ScoreComponent } from './score/score.component'; - @NgModule({ declarations: [ AppComponent, From 07dd9856504477334bd81c3f974c7fffda403a38 Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 07:54:17 +0000 Subject: [PATCH 08/17] Test fixed. --- src/app/score/score.component.spec.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/score/score.component.spec.ts b/src/app/score/score.component.spec.ts index 343aa7c3..48853e68 100644 --- a/src/app/score/score.component.spec.ts +++ b/src/app/score/score.component.spec.ts @@ -18,6 +18,13 @@ describe('ScoreComponent', () => { let fixture: ComponentFixture; beforeEach(async(() => { + const firebaseConfig = { + apiKey: 'xxx', + authDomain: 'xxx', + databaseURL: 'https://koth-edosoft.firebaseio.com/', + storageBucket: 'xxx', + messagingSenderId: 'xxx', +}; TestBed.configureTestingModule({ imports: [ KothMaterialModule, AngularFireModule.initializeApp(environment.firebase),AngularFireAuthModule, @@ -86,4 +93,3 @@ describe('ScoreComponent', () => { expect(el.textContent).toEqual('Retry'); }); }); - From 087d08511dc4a354499c2c2cac1b41c78b9e255b Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 10:08:20 +0000 Subject: [PATCH 09/17] Test fixed --- src/app/score/score.component.spec.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/app/score/score.component.spec.ts b/src/app/score/score.component.spec.ts index 48853e68..3de9bf29 100644 --- a/src/app/score/score.component.spec.ts +++ b/src/app/score/score.component.spec.ts @@ -18,13 +18,6 @@ describe('ScoreComponent', () => { let fixture: ComponentFixture; beforeEach(async(() => { - const firebaseConfig = { - apiKey: 'xxx', - authDomain: 'xxx', - databaseURL: 'https://koth-edosoft.firebaseio.com/', - storageBucket: 'xxx', - messagingSenderId: 'xxx', -}; TestBed.configureTestingModule({ imports: [ KothMaterialModule, AngularFireModule.initializeApp(environment.firebase),AngularFireAuthModule, From 545f4d21464659d26254b83d6750b35eeec0bc49 Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 12:53:42 +0000 Subject: [PATCH 10/17] Mock View Score Done --- src/app/app.component.html | 2 + src/app/app.component.spec.ts | 17 +++--- src/app/score/score.component.html | 6 +++ src/app/score/score.component.ts | 83 +++++++++++++++++++----------- 4 files changed, 71 insertions(+), 37 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index ef293e0d..0a846766 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -15,3 +15,5 @@ --> + + diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 6ca952ed..95230fb2 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -8,6 +8,7 @@ import { AngularFireModule } from 'angularfire2'; import { AngularFireAuthModule } from 'angularfire2/auth'; import { AngularFireDatabaseModule } from 'angularfire2/database'; import { Routes, RouterModule } from '@angular/router'; +import { ScoreComponent } from './score/score.component'; import { SigninComponent } from './signin/signin.component'; import { environment } from '../environments/environment'; import * as firebase from 'firebase/app'; @@ -31,14 +32,14 @@ describe('AppComponent', () => { RouterModule, FormsModule ], - - declarations: [ - AppComponent, - SigninComponent - ], - providers: [AuthService, AngularFireAuth] - }).compileComponents(); -})); + declarations: [ + AppComponent, + ScoreComponent, + SigninComponent + ], + providers: [AuthService,AngularFireAuth] + }).compileComponents(); + })); it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); diff --git a/src/app/score/score.component.html b/src/app/score/score.component.html index bf09444e..80df8182 100644 --- a/src/app/score/score.component.html +++ b/src/app/score/score.component.html @@ -8,3 +8,9 @@

Score

Your current record is: {{record}}

+ +
    +
  • + {{ todo.score }} +
  • +
diff --git a/src/app/score/score.component.ts b/src/app/score/score.component.ts index 2bf9bd4a..850a9d6a 100644 --- a/src/app/score/score.component.ts +++ b/src/app/score/score.component.ts @@ -15,8 +15,10 @@ export class ScoreComponent implements OnInit { score: number; rank: number; record: number; - data_refs : AngularFireList; + user_info: any; + last_user_game: any; data : Observable; + JSON = JSON; user = null; @@ -27,36 +29,59 @@ export class ScoreComponent implements OnInit { } ngOnInit() { - const temp = this.db.object('/0/email'); - console.log(temp); + this.last_user_game = this.db.list('/games', ref => ref.orderByChild('email').equalTo('javier@test.com').limitToLast(1)).valueChanges(); + this.score = this.last_user_game.score; + this.last_user_game.subscribe(item => { + this.score = item[0].score; + }) - - - this.data_refs = this.db.list('/users', user => { - console.log("blabla: " + user); - return user + this.user_info = this.db.list('/', ref => ref.orderByChild('email').equalTo('javier@test.com')).valueChanges(); + this.user_info.subscribe(item => { + item.map(x => { + if (x.highscore > this.record){ + this.record = x.highscore; + } + if (x.highrank > this.rank){ + this.rank = x.highrank; + } + }); }); - - - console.log("Lista de datos: " + this.data_refs); - // let path = `users/0`; - console.log("Ruta: " + this.db.list('/0')); - // this.auth.currentUserObservable.subscribe( - // (user) =>{ - // this.user = user; - // console.log("Este es el observable: " + user); - // }); - // console.log("Este es el console: " + this.db.list('/users')); - // this.data_refs = this.db.list('/'); - // this.data = this.data_refs.valueChanges(); - } - - getUserInfo() { - // const user = this.auth.; - console.log("Este es el usuario logueado") - //this.rank = this.user.highrank; - //this.record = this.user.highscore; - } + + // this.data_refs = this.db.list('/', {}).subscribe(res => { + // + // })); } + // + // const temp = this.db.object('/0/email'); + // console.log(temp); + // + // + // + // this.data_refs = this.db.list('/users', user => { + // console.log("blabla: " + user); + // return user + // }); + // + // + // console.log("Lista de datos: " + this.data_refs); + // // let path = `users/0`; + // console.log("Ruta: " + this.db.list('/0')); + // // this.auth.currentUserObservable.subscribe( + // // (user) =>{ + // // this.user = user; + // // console.log("Este es el observable: " + user); + // // }); + // // console.log("Este es el console: " + this.db.list('/users')); + // // this.data_refs = this.db.list('/'); + // // this.data = this.data_refs.valueChanges(); + // } + // + // getUserInfo() { + // // const user = this.auth.; + // console.log("Este es el usuario logueado") + // //this.rank = this.user.highrank; + // //this.record = this.user.highscore; + // + // } From c37131ea948575846d5aa81e2f8d5e522f8b5748 Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 14:02:50 +0000 Subject: [PATCH 11/17] delete unused lines --- src/app/score/score.component.ts | 38 +------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/src/app/score/score.component.ts b/src/app/score/score.component.ts index 850a9d6a..5dafb1fd 100644 --- a/src/app/score/score.component.ts +++ b/src/app/score/score.component.ts @@ -47,41 +47,5 @@ ngOnInit() { }); }); } - - - // this.data_refs = this.db.list('/', {}).subscribe(res => { - // - // })); + } - // - // const temp = this.db.object('/0/email'); - // console.log(temp); - // - // - // - // this.data_refs = this.db.list('/users', user => { - // console.log("blabla: " + user); - // return user - // }); - // - // - // console.log("Lista de datos: " + this.data_refs); - // // let path = `users/0`; - // console.log("Ruta: " + this.db.list('/0')); - // // this.auth.currentUserObservable.subscribe( - // // (user) =>{ - // // this.user = user; - // // console.log("Este es el observable: " + user); - // // }); - // // console.log("Este es el console: " + this.db.list('/users')); - // // this.data_refs = this.db.list('/'); - // // this.data = this.data_refs.valueChanges(); - // } - // - // getUserInfo() { - // // const user = this.auth.; - // console.log("Este es el usuario logueado") - // //this.rank = this.user.highrank; - // //this.record = this.user.highscore; - // - // } From 29d389a9c8c96deb7db78cc5cceb117b7f3dbba3 Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 14:26:06 +0000 Subject: [PATCH 12/17] Fixed error on Score Tests --- src/app/score/score.component.spec.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/score/score.component.spec.ts b/src/app/score/score.component.spec.ts index 3de9bf29..1abaa87c 100644 --- a/src/app/score/score.component.spec.ts +++ b/src/app/score/score.component.spec.ts @@ -69,12 +69,18 @@ describe('ScoreComponent', () => { // const de = fixture.debugElement.queryAll(By.css('p')); // const el = de.map(el => el.nativeElement); // el.map(x => expect(x.textContent).toEqual(`Your score is: ${component.score}`)); + component.record = 0; + component.score = 2; + fixture.detectChanges(); const rankingText = fixture.debugElement.queryAll(By.css('p'))[1]; const el = rankingText.nativeElement; expect(el.textContent).toEqual(`Position on Ranking: ${component.rank}`); }); it('should display record', () => { + component.record = 0; + component.score = 2; + fixture.detectChanges(); const recordText = fixture.debugElement.queryAll(By.css('p'))[2]; const el = recordText.nativeElement; expect(el.textContent).toEqual(`Your current record is: ${component.record}`); From 12c54a12c9954e4a2fdd267d1708552c8377b28d Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 14:43:00 +0000 Subject: [PATCH 13/17] Re-fixed errors on Score Component --- src/app/score/score.component.html | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/app/score/score.component.html b/src/app/score/score.component.html index 80df8182..bf09444e 100644 --- a/src/app/score/score.component.html +++ b/src/app/score/score.component.html @@ -8,9 +8,3 @@

Score

Your current record is: {{record}}

- -
    -
  • - {{ todo.score }} -
  • -
From 9cf20c0399d550a2397df735059a8b06e2f4b290 Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 19 Dec 2017 14:50:22 +0000 Subject: [PATCH 14/17] Fixed errors with environment --- src/app/app.module.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e2efac59..b9adbec7 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -15,7 +15,6 @@ import { AppComponent } from './app.component'; import { ScoreComponent } from './score/score.component'; import { SigninComponent } from './signin/signin.component'; - @NgModule({ declarations: [ AppComponent, From ea134a5d297d3992247a08e066040adfb4afb4ae Mon Sep 17 00:00:00 2001 From: Daniel San Date: Fri, 22 Dec 2017 07:02:27 +0000 Subject: [PATCH 15/17] Commit before pull --- src/app/app.component.html | 2 -- src/app/app.component.spec.ts | 9 --------- 2 files changed, 11 deletions(-) diff --git a/src/app/app.component.html b/src/app/app.component.html index 0a846766..ef293e0d 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -15,5 +15,3 @@ --> - - diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 95230fb2..d9e4f080 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -16,15 +16,6 @@ import { FormsModule } from '@angular/forms'; describe('AppComponent', () => { beforeEach(async(() => { - const firebaseConfig = { - - apiKey: 'AIzaSyC3cMoupowM4VP5V50ojjhO_MajTOpwNDI', - authDomain: 'koth-edosoft.firebaseapp.com', - databaseURL: 'https://koth-edosoft.firebaseio.com', - storageBucket: 'koth-edosoft.appspot.com', - messagingSenderId: '148924484247', - -}; TestBed.configureTestingModule({ imports: [ KothMaterialModule, AngularFireModule.initializeApp(environment.firebase), AngularFireAuthModule, From 25174401ecf958d3538fb3ae60bb8d2962151fb1 Mon Sep 17 00:00:00 2001 From: Daniel San Date: Tue, 2 Jan 2018 08:40:49 +0000 Subject: [PATCH 16/17] Score component Done. --- src/app/app.module.ts | 4 +-- src/app/score/score.component.html | 6 ++-- src/app/score/score.component.ts | 51 +++++++++++++++--------------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index dbc83a18..61ab03f9 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -18,6 +18,7 @@ import { ScoreComponent } from './score/score.component'; import { SigninComponent } from './signin/signin.component'; import { LoginComponent } from './login/login.component'; import { GameComponent } from './game/game.component'; +import { LeaderListComponent } from './leader-list/leader-list.component'; const appRoutes: Routes = [ {path: 'login', component: LoginComponent }, @@ -28,9 +29,6 @@ const appRoutes: Routes = [ {path: '', redirectTo: 'login', pathMatch: 'full'} ]; -import { LeaderListComponent } from './leader-list/leader-list.component'; - - @NgModule({ declarations: [ AppComponent, diff --git a/src/app/score/score.component.html b/src/app/score/score.component.html index bf09444e..1513cf01 100644 --- a/src/app/score/score.component.html +++ b/src/app/score/score.component.html @@ -1,10 +1,10 @@

Score

-

Your score is: {{score}}

-

Congratulations, you have beaten your record: {{score}}

+

Your score is: {{score}}

+

Congratulations, you have beaten your record: {{score}}

Position on Ranking: {{rank}}

Your current record is: {{record}}

- + diff --git a/src/app/score/score.component.ts b/src/app/score/score.component.ts index 98f1e97e..7a92d36d 100644 --- a/src/app/score/score.component.ts +++ b/src/app/score/score.component.ts @@ -1,8 +1,8 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, NgZone } from '@angular/core'; import { AuthService } from '../auth.service'; import { AngularFireDatabase, AngularFireList } from 'angularfire2/database'; import { Observable } from 'rxjs/Observable'; - +import { Router} from '@angular/router'; @Component({ selector: 'app-score', @@ -15,37 +15,38 @@ export class ScoreComponent implements OnInit { score: number; rank: number; record: number; + games: any; user_info: any; last_user_game: any; data : Observable; JSON = JSON; - + currentUser:any; user = null; - constructor(private auth: AuthService, public db: AngularFireDatabase) { - this.score = 0; - this.rank = 0; - this.record = 0; + constructor(private auth: AuthService, public db: AngularFireDatabase, private route: Router, private zone: NgZone) { + this.games = this.db.list('/games', ref => ref.orderByChild('score')).valueChanges(); } -ngOnInit() { - this.last_user_game = this.db.list('/games', ref => ref.orderByChild('email').equalTo('javier@test.com').limitToLast(1)).valueChanges(); - this.score = this.last_user_game.score; - this.last_user_game.subscribe(item => { - this.score = item[0].score; - }) - - this.user_info = this.db.list('/', ref => ref.orderByChild('email').equalTo('javier@test.com')).valueChanges(); - this.user_info.subscribe(item => { - item.map(x => { - if (x.highscore > this.record){ - this.record = x.highscore; - } - if (x.highrank > this.rank){ - this.rank = x.highrank; - } - }); - }); + ngOnInit() { + this.currentUser = this.auth.currentUser; + this.last_user_game = this.db.list('/games', ref => ref.orderByChild('email').equalTo(this.currentUser.email).limitToLast(1)).valueChanges(); + this.last_user_game.subscribe((score) => { + this.score = score[0].score; + }); + this.games.subscribe((game) => { + game = game.reverse(); + for (var i = 0; i < game.length; i++){ + if (game[i].email == this.currentUser.email){ + this.rank = i + 1; + this.record = game[i].score; + break; + } + } + }) + } + + onPressRetry(){ + this.route.navigate(['/game']); } } From a97c77ef4dc9a11175a0d5f84056efdcbe4a8b3b Mon Sep 17 00:00:00 2001 From: Daniel San Juan Abrante Date: Fri, 12 Jan 2018 08:01:34 +0000 Subject: [PATCH 17/17] Fixed test --- src/app/game/game.component.spec.ts | 34 ++++++++++++++----------- src/app/game/game.component.ts | 2 +- src/app/score/score.component.spec.ts | 18 ++++++++----- src/app/score/score.component.ts | 4 +-- src/app/signin/signin.component.spec.ts | 2 +- 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/app/game/game.component.spec.ts b/src/app/game/game.component.spec.ts index 53c44710..bd3e9341 100644 --- a/src/app/game/game.component.spec.ts +++ b/src/app/game/game.component.spec.ts @@ -1,8 +1,8 @@ import { async, tick, ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing'; import { Location } from "@angular/common"; -import { RouterTestingModule } from "@angular/router/testing"; import { Router } from "@angular/router"; import { Routes, RouterModule } from '@angular/router'; +import {APP_BASE_HREF} from '@angular/common'; import { AppComponent } from '../app.component'; import {KothMaterialModule} from '../koth-material/koth-material.module' import { AuthService } from '../auth.service'; @@ -19,9 +19,12 @@ import * as firebase from 'firebase/app'; import { FormsModule } from '@angular/forms'; describe('GameComponent', () => { + const appRoutes: Routes = [ + { path: 'game', component: GameComponent } + ]; let component: GameComponent; let fixture: ComponentFixture; - + beforeEach(async(() => { const firebaseConfig = { @@ -34,19 +37,21 @@ describe('GameComponent', () => { } TestBed.configureTestingModule({ imports: [ KothMaterialModule, + RouterModule.forRoot(appRoutes, {enableTracing: true}), AngularFireModule.initializeApp(firebaseConfig), AngularFireAuthModule, AngularFireDatabaseModule, RouterModule, FormsModule, ], declarations: [ GameComponent ], - providers: [AuthService, AngularFireAuth] + providers: [AuthService, AngularFireAuth, {provide: APP_BASE_HREF, useValue : '/' }], }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(GameComponent); component = fixture.componentInstance; + component.currentUser = "pedro@pedro.com"; fixture.detectChanges(); }); @@ -63,15 +68,15 @@ describe('GameComponent', () => { beforeEach(function(){ player = new Player(); - + }); - + describe('when you are logged', function(){ - + beforeEach(function(){ // player.logout(); }); - + it("player after logout is null", function(){ expect(player).toBeNull; }); @@ -85,15 +90,15 @@ describe('GameComponent', () => { // it("is the King", function(){ // const leaderInfoDe = fixture.debugElement.query(By.css('.leaderInfo')); // const bgColor = leaderInfoDe.nativeElement.style.backgroundColor; - // expect(bgColor).toBe('green'); + // expect(bgColor).toBe('green'); // }); - + // it("is not the King", function(){ // const leaderInfoDe = fixture.debugElement.query(By.css('.container-game .leaderInfo')); // const bgColor = leaderInfoDe.nativeElement.style.backgroundColor; - // expect(bgColor).toBe('red'); + // expect(bgColor).toBe('red'); // }); - + }); // Este test nunca lo pasa porque el botón al comienzo esta sin pulsar siempre. // it("Has clicked Play on button", function(){ @@ -106,15 +111,14 @@ describe('GameComponent', () => { // expect(player.getTime()).toBeGreaterThan(0); // expect(playButtonEl.hasAttribute('disabled')).toEqual(true); // }); - + it("Has not clicked Play on button", function(){ player.setTime(0); player.setGameStatus(false); expect(player.getGameStatus()).toBeFalsy(); expect(player.getTime()).toEqual(0); - }); - + }); + }); }); - diff --git a/src/app/game/game.component.ts b/src/app/game/game.component.ts index 36c37058..4cdcdcad 100644 --- a/src/app/game/game.component.ts +++ b/src/app/game/game.component.ts @@ -37,7 +37,7 @@ export class GameComponent implements OnInit { } ngOnInit() { - this.currentUser = this.user.currentUser.email; + this.currentUser = this.user.currentUser; this.maxScore = this.database.list('/games', ref => ref.orderByChild('score').limitToLast(1)).valueChanges(); this.score = this.maxScore.score; // this.maxScore.subscribe(item => { diff --git a/src/app/score/score.component.spec.ts b/src/app/score/score.component.spec.ts index 5addc557..80de1354 100644 --- a/src/app/score/score.component.spec.ts +++ b/src/app/score/score.component.spec.ts @@ -9,23 +9,28 @@ import { AngularFireAuthModule } from 'angularfire2/auth'; import { AngularFireDatabaseModule } from 'angularfire2/database'; import {KothMaterialModule} from '../koth-material/koth-material.module' import { Routes, RouterModule } from '@angular/router'; +import {APP_BASE_HREF} from '@angular/common'; import * as firebase from 'firebase/app'; import { environment } from '../../environments/environment'; describe('ScoreComponent', () => { + const appRoutes: Routes = [ + { path: 'score', component: ScoreComponent } + ]; let component: ScoreComponent; let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ KothMaterialModule, + RouterModule.forRoot(appRoutes, {enableTracing: true}), AngularFireModule.initializeApp(environment.firebase, 'my-app-name'),AngularFireAuthModule, AngularFireDatabaseModule, RouterModule ], declarations: [ ScoreComponent ], - providers: [AuthService,AngularFireAuth], + providers: [AuthService, AngularFireAuth, {provide: APP_BASE_HREF, useValue : '/' }], }) .compileComponents(); })); @@ -33,6 +38,7 @@ describe('ScoreComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(ScoreComponent); component = fixture.componentInstance; + component.currentUser = "pedro@pedro.com"; fixture.detectChanges(); }); @@ -49,6 +55,7 @@ describe('ScoreComponent', () => { it('should display score', () => { component.record = 2; component.score = 0; + component.rank = 2; fixture.detectChanges(); const scoreText = fixture.debugElement.query(By.css('p')); const el = scoreText.nativeElement; @@ -58,6 +65,7 @@ describe('ScoreComponent', () => { it('should congrat you if you beat your record', () => { component.record = 0; component.score = 2; + component.rank = 2; fixture.detectChanges(); const scoreText = fixture.debugElement.query(By.css('p')); const el = scoreText.nativeElement; @@ -71,6 +79,7 @@ describe('ScoreComponent', () => { // el.map(x => expect(x.textContent).toEqual(`Your score is: ${component.score}`)); component.record = 0; component.score = 2; + component.rank = 1; fixture.detectChanges(); const rankingText = fixture.debugElement.queryAll(By.css('p'))[1]; const el = rankingText.nativeElement; @@ -80,15 +89,10 @@ describe('ScoreComponent', () => { it('should display record', () => { component.record = 0; component.score = 2; + component.rank = 1; fixture.detectChanges(); const recordText = fixture.debugElement.queryAll(By.css('p'))[2]; const el = recordText.nativeElement; expect(el.textContent).toEqual(`Your current record is: ${component.record}`); }); - - it('should have a button with name Retry', () => { - const retryBtn = fixture.debugElement.query(By.css('button')); - const el = retryBtn.nativeElement; - expect(el.textContent).toEqual('Retry'); - }); }); diff --git a/src/app/score/score.component.ts b/src/app/score/score.component.ts index 7a92d36d..48af51e5 100644 --- a/src/app/score/score.component.ts +++ b/src/app/score/score.component.ts @@ -29,14 +29,14 @@ export class ScoreComponent implements OnInit { ngOnInit() { this.currentUser = this.auth.currentUser; - this.last_user_game = this.db.list('/games', ref => ref.orderByChild('email').equalTo(this.currentUser.email).limitToLast(1)).valueChanges(); + this.last_user_game = this.db.list('/games', ref => ref.orderByChild('email').equalTo(this.currentUser).limitToLast(1)).valueChanges(); this.last_user_game.subscribe((score) => { this.score = score[0].score; }); this.games.subscribe((game) => { game = game.reverse(); for (var i = 0; i < game.length; i++){ - if (game[i].email == this.currentUser.email){ + if (game[i].email == this.currentUser){ this.rank = i + 1; this.record = game[i].score; break; diff --git a/src/app/signin/signin.component.spec.ts b/src/app/signin/signin.component.spec.ts index 2ec9999f..c61fd88e 100644 --- a/src/app/signin/signin.component.spec.ts +++ b/src/app/signin/signin.component.spec.ts @@ -51,7 +51,7 @@ describe('SigninComponent', () => { }); it('User name should be an email', () => { - userT = 'Pilarica24@gmail.com'; + userT = 'dani.sanjuan@gmail.com'; fixture.detectChanges(); expect(userT).toMatch('^[a-zA-Z0-9_]+([\.-]?[a-zA-Z0-9_]+)*@[a-zA-Z0-9_]+([\.-]?[a-zA-Z0-9_]+)*(\.[a-zA-Z0-9_]{2,4})+$'); });