removed old blocks page; udpated tests; added test script

This commit is contained in:
Darren Nelsen 2018-03-12 13:54:22 -04:00
parent 3b2e65e5ad
commit 264a379285
8 changed files with 33 additions and 117 deletions

View File

@ -66,4 +66,4 @@
"node": ">=8"
},
"license": "MIT"
}
}

View File

@ -1,29 +1,45 @@
import { InsightApp } from './app.component';
import { MenuMock, NavMock, PlatformMock, SplashMock, StatusMock } from '../mocks';
import { TestBed, getTestBed, inject, async } from '@angular/core/testing';
import { Platform } from 'ionic-angular';
import { NavMock } from '../mocks';
import { BroadcastTxPage } from '../pages';
let instance: InsightApp = null;
import { PopoverController, MenuController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
describe('InsightApp', () => {
let injector: TestBed;
let app: InsightApp;
beforeEach(() => {
instance = new InsightApp((<any> new PlatformMock), (<any> new MenuMock), (<any>new SplashMock()), (<any>new StatusMock()));
instance['nav'] = (<any>new NavMock());
TestBed.configureTestingModule({
providers: [
PopoverController,
InsightApp,
Platform,
MenuController,
SplashScreen,
StatusBar
]
});
injector = getTestBed();
app = injector.get(InsightApp);
app['nav'] = (<any>new NavMock());
});
it('initializes with four possible pages', () => {
expect(instance['pages'].length).toEqual(4);
it('initializes with three possible pages', () => {
expect(app['pages'].length).toEqual(3);
});
it('initializes with a root page', () => {
expect(instance['rootPage']).not.toBe(null);
expect(app['rootPage']).not.toBe(null);
});
it('opens a page', () => {
spyOn(instance['menu'], 'close');
spyOn(instance['nav'], 'setRoot');
instance.openPage(instance['pages'][1]);
expect(instance['menu']['close']).toHaveBeenCalled();
expect(instance['nav'].setRoot).toHaveBeenCalledWith(BroadcastTxPage);
spyOn(app['menu'], 'close');
spyOn(app['nav'], 'setRoot');
app.openPage(app['pages'][1]);
expect(app['menu']['close']).toHaveBeenCalled();
});
});

View File

@ -1,32 +0,0 @@
<ion-header>
<head-nav [title]="'Blocks'"></head-nav>
</ion-header>
<ion-content padding>
<ion-grid>
<ion-row>
<ion-col><b>Height</b></ion-col>
<ion-col><b>Timestamp</b></ion-col>
<ion-col text-right><b>Transactions</b></ion-col>
<ion-col><b>Mined By</b></ion-col>
<ion-col text-right><b>Size</b></ion-col>
</ion-row>
<ion-row *ngFor="let block of blocks | async">
<ion-col>
<a (click)="goToBlock(block.hash)">{{block.height}}</a>
</ion-col>
<ion-col>
{{ block.timestamp * 1000 | date:'medium' }}
</ion-col>
<ion-col text-right>
{{block.transactionCount}}
</ion-col>
<ion-col>
<a *ngIf="block.poolName" href="{{block.url}}">{{block.poolName}}</a>
</ion-col>
<ion-col text-right>
{{ block.size }}
</ion-col>
</ion-row>
</ion-grid>
</ion-content>

View File

@ -1,3 +0,0 @@
.blocksPage {
}

View File

@ -1,31 +0,0 @@
import { ComponentFixture, async } from '@angular/core/testing';
import { TestUtils } from '../../test';
import { BlocksPage } from './blocksPage';
let fixture: ComponentFixture<BlocksPage> = null;
let instance: any = null;
describe('Blocks', () => {
beforeEach(async(() => TestUtils.beforeEachCompiler([BlocksPage]).then(compiled => {
fixture = compiled.fixture;
instance = compiled.instance;
fixture.detectChanges();
})));
afterEach(() => {
fixture.destroy();
});
it('initializes', () => {
expect(instance).toBeTruthy();
});
/*
it('has a search method', () => {
spyOn(instance, 'search');
instance.search();
expect(instance.search).toHaveBeenCalled();
});
*/
});

View File

@ -1,35 +0,0 @@
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Observable } from 'rxjs';
import { Block } from '../../models';
import { BlocksService } from '../../services';
/**
* @deprecated Use BlocksPage from ../blocks/blocks
*/
@Component({
templateUrl: './blocksPage.html'
})
export class BlocksPage {
public title: string;
public blocks: Observable<Block[]>;
constructor(private navCtrl: NavController, private blocksService: BlocksService) {
// TODO Put loading spinner on page
this.title = 'Blocks';
this.blocks = blocksService.latestBlocks;
this.blocks.subscribe((blocks) => {
console.log('blocks', blocks);
});
blocksService.getLatestBlocks();
}
public goToBlock(blockHash: string): void {
this.navCtrl.push('block-detail', {
'blockHash': blockHash
});
}
}

View File

@ -20,7 +20,7 @@ export class CurrencyProvider {
private loading: boolean;
constructor(public http: Http, private api: ApiProvider) {
this.defaultCurrency = 'BCH';
this.defaultCurrency = 'BTC';
this.currencySymbol = this.defaultCurrency;
}

View File

@ -21,7 +21,8 @@
"postinstall": "run-s install-app",
"install-app": "cd app && npm install",
"start": "run-s watch-app",
"watch-app": "cd app && npm start"
"watch-app": "cd app && npm start",
"test": "cd app && ng test --code-coverage"
},
"dependencies": {},
"devDependencies": {