Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c9ab450
Test fixed.
danielsanjuan Dec 19, 2017
7124371
Test fixed
danielsanjuan Dec 19, 2017
63a45f8
Mock View Score Done
danielsanjuan Dec 19, 2017
dea9719
delete unused lines
danielsanjuan Dec 19, 2017
046038e
Fixed error on Score Tests
danielsanjuan Dec 19, 2017
89e41e3
Merge branch 'master' into master
danielsanjuan Dec 19, 2017
72c0bef
Merge branch 'master' into master
danielsanjuan Dec 19, 2017
64e4638
Re-fixed errors on Score Component
danielsanjuan Dec 19, 2017
c597195
Merge branch 'master' of github.com:danielsanjuan/koth
danielsanjuan Dec 19, 2017
f93032b
Fixed errors with environment
danielsanjuan Dec 19, 2017
07dd985
Test fixed.
danielsanjuan Dec 19, 2017
087d085
Test fixed
danielsanjuan Dec 19, 2017
545f4d2
Mock View Score Done
danielsanjuan Dec 19, 2017
c37131e
delete unused lines
danielsanjuan Dec 19, 2017
29d389a
Fixed error on Score Tests
danielsanjuan Dec 19, 2017
12c54a1
Re-fixed errors on Score Component
danielsanjuan Dec 19, 2017
9cf20c0
Fixed errors with environment
danielsanjuan Dec 19, 2017
316f3d6
fixed errors with rebase
danielsanjuan Dec 19, 2017
ef1879b
Merge branch 'master' into master
aitorcarrera Dec 19, 2017
c17edd7
Merge branch 'master' into master
aitorcarrera Dec 19, 2017
ea134a5
Commit before pull
danielsanjuan Dec 22, 2017
7a7ce6f
merge with pull origin master
danielsanjuan Dec 22, 2017
b6cf162
All Up to date
danielsanjuan Dec 22, 2017
0fdc8d4
Merge branch 'master' of https://github.com/edosoft/koth
danielsanjuan Dec 27, 2017
2517440
Score component Done.
danielsanjuan Jan 2, 2018
a97c77e
Fixed test
Jan 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -28,9 +29,6 @@ const appRoutes: Routes = [
{path: '', redirectTo: 'login', pathMatch: 'full'}
];

import { LeaderListComponent } from './leader-list/leader-list.component';


@NgModule({
declarations: [
AppComponent,
Expand Down
34 changes: 19 additions & 15 deletions src/app/game/game.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<GameComponent>;


beforeEach(async(() => {
const firebaseConfig = {
Expand All @@ -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();
});

Expand All @@ -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;
});
Expand All @@ -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(){
Expand All @@ -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);
});
});

});

});

2 changes: 1 addition & 1 deletion src/app/game/game.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
6 changes: 3 additions & 3 deletions src/app/score/score.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<h1 class="title">Score</h1>

<p *ngIf="score <= record">Your score is: {{score}}</p>
<p *ngIf="score > record">Congratulations, you have beaten your record: {{score}}</p>
<p *ngIf="score < record">Your score is: {{score}}</p>
<p *ngIf="score >= record">Congratulations, you have beaten your record: {{score}}</p>

<p>Position on Ranking: {{rank}}</p>

<p>Your current record is: {{record}}</p>

<button class="mat-raised-button mat-primary">Retry</button>
<button (click)="onPressRetry()" class="mat-raised-button mat-primary">Retry</button>
18 changes: 11 additions & 7 deletions src/app/score/score.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,36 @@ 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<ScoreComponent>;

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();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ScoreComponent);
component = fixture.componentInstance;
component.currentUser = "pedro@pedro.com";
fixture.detectChanges();
});

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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');
});
});
51 changes: 26 additions & 25 deletions src/app/score/score.component.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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<any[]>;
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).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){
this.rank = i + 1;
this.record = game[i].score;
break;
}
}
})
}

onPressRetry(){
this.route.navigate(['/game']);
}

}
2 changes: 1 addition & 1 deletion src/app/signin/signin.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})+$');
});
Expand Down