Add store tests, fix issue with pending sort to top
This commit is contained in:
parent
1ab4ee3781
commit
9e8fb616d3
@ -67,6 +67,7 @@
|
|||||||
"babel-register": "6.18.0",
|
"babel-register": "6.18.0",
|
||||||
"babel-runtime": "6.18.0",
|
"babel-runtime": "6.18.0",
|
||||||
"chai": "3.5.0",
|
"chai": "3.5.0",
|
||||||
|
"chai-as-promised": "6.0.0",
|
||||||
"chai-enzyme": "0.6.1",
|
"chai-enzyme": "0.6.1",
|
||||||
"copy-webpack-plugin": "4.0.1",
|
"copy-webpack-plugin": "4.0.1",
|
||||||
"core-js": "2.4.1",
|
"core-js": "2.4.1",
|
||||||
|
@ -45,6 +45,8 @@ export default class Store {
|
|||||||
|
|
||||||
if (bnB.eq(0)) {
|
if (bnB.eq(0)) {
|
||||||
return bnB.eq(bnA) ? 0 : 1;
|
return bnB.eq(bnA) ? 0 : 1;
|
||||||
|
} else if (bnA.eq(0)) {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bnB.comparedTo(bnA);
|
return bnB.comparedTo(bnA);
|
||||||
|
90
js/src/ui/TxList/store.spec.js
Normal file
90
js/src/ui/TxList/store.spec.js
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||||
|
// This file is part of Parity.
|
||||||
|
|
||||||
|
// Parity is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Parity is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import BigNumber from 'bignumber.js';
|
||||||
|
import sinon from 'sinon';
|
||||||
|
|
||||||
|
import Store from './store';
|
||||||
|
|
||||||
|
const SUBID = 123;
|
||||||
|
const BLOCKS = {
|
||||||
|
1: { blockhash: '0x1' },
|
||||||
|
2: { blockhash: '0x2' }
|
||||||
|
};
|
||||||
|
const TRANSACTIONS = {
|
||||||
|
'0x123': { blockNumber: new BigNumber(1) },
|
||||||
|
'0x234': { blockNumber: new BigNumber(0) },
|
||||||
|
'0x345': { blockNumber: new BigNumber(2) },
|
||||||
|
'0x456': { blockNumber: new BigNumber(0) }
|
||||||
|
};
|
||||||
|
|
||||||
|
describe.only('ui/TxList/store', () => {
|
||||||
|
let api;
|
||||||
|
let store;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
api = {
|
||||||
|
subscribe: sinon.stub().resolves(SUBID),
|
||||||
|
eth: {
|
||||||
|
getBlockByNumber: (blockNumber) => {
|
||||||
|
return Promise.resolve(BLOCKS[blockNumber]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
store = new Store(api);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('create', () => {
|
||||||
|
it('has empty storage', () => {
|
||||||
|
expect(store.blocks).to.deep.equal({});
|
||||||
|
expect(store.sortedHashes.peek()).to.deep.equal([]);
|
||||||
|
expect(store.transactions).to.deep.equal({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('subscribes to eth_blockNumber', () => {
|
||||||
|
expect(api.subscribe).to.have.been.calledWith('eth_blockNumber');
|
||||||
|
expect(store._subscriptionId).to.equal(SUBID);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('addBlocks', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
store.addBlocks(BLOCKS);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds the blocks to the list', () => {
|
||||||
|
expect(store.blocks).to.deep.equal(BLOCKS);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('addTransactions', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
store.addTransactions(TRANSACTIONS);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds all transactions to the list', () => {
|
||||||
|
expect(store.transactions).to.deep.equal(TRANSACTIONS);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sorts transactions based on blockNumber', () => {
|
||||||
|
expect(store.sortedHashes.peek()).to.deep.equal(['0x234', '0x456', '0x345', '0x123']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds pending transactions to the pending queue', () => {
|
||||||
|
expect(store._pendingHashes).to.deep.equal(['0x234', '0x456']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -22,11 +22,13 @@ es6Promise.polyfill();
|
|||||||
import 'mock-local-storage';
|
import 'mock-local-storage';
|
||||||
|
|
||||||
import chai from 'chai';
|
import chai from 'chai';
|
||||||
|
import chaiAsPromised from 'chai-as-promised';
|
||||||
import chaiEnzyme from 'chai-enzyme';
|
import chaiEnzyme from 'chai-enzyme';
|
||||||
import sinonChai from 'sinon-chai';
|
import sinonChai from 'sinon-chai';
|
||||||
import { WebSocket } from 'mock-socket';
|
import { WebSocket } from 'mock-socket';
|
||||||
import jsdom from 'jsdom';
|
import jsdom from 'jsdom';
|
||||||
|
|
||||||
|
chai.use(chaiAsPromised);
|
||||||
chai.use(chaiEnzyme());
|
chai.use(chaiEnzyme());
|
||||||
chai.use(sinonChai);
|
chai.use(sinonChai);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user