@yoroi/exchange
Version:
The Exchange package of Yoroi SDK
113 lines (112 loc) • 3.53 kB
JavaScript
;
var _state = require("./state");
describe('State Actions', () => {
it('unknown', () => {
const action = {
type: 'UNKNOWN'
};
try {
(0, _state.exchangeReducer)(_state.exchangeDefaultState, action);
fail('it should crash before');
} catch (e) {
expect(e.message).toEqual('ExchangeFormReducer invalid action');
}
});
describe('OrderTypeChanged', () => {
it('changes order type but does not change provider id', () => {
const action = {
type: _state.ExchangeActionType.OrderTypeChanged,
orderType: 'sell'
};
const state = (0, _state.exchangeReducer)({
..._state.exchangeDefaultState,
orderType: 'buy',
amount: {
disabled: false,
value: 2000000,
displayValue: '2',
error: 'fake-error'
},
canExchange: true
}, action);
expect(state.orderType).toBe('sell');
expect(state.amount).toEqual(_state.exchangeDefaultState.amount);
expect(state.canExchange).toEqual(_state.exchangeDefaultState.canExchange);
});
it('changes order type to buy and changes provider id', () => {
const action = {
type: _state.ExchangeActionType.OrderTypeChanged,
orderType: 'buy'
};
const state = (0, _state.exchangeReducer)({
..._state.exchangeDefaultState,
orderType: 'sell',
providerId: 'banxa',
providerSuggestedByOrderType: {
buy: 'encryptus',
sell: 'banxa'
}
}, action);
expect(state.orderType).toBe('buy');
expect(state.providerId).toBe('encryptus');
});
it('changes order type to sell and changes provider id', () => {
const action = {
type: _state.ExchangeActionType.OrderTypeChanged,
orderType: 'sell'
};
const state = (0, _state.exchangeReducer)({
..._state.exchangeDefaultState,
orderType: 'buy',
providerId: 'encryptus',
providerSuggestedByOrderType: {
buy: 'encryptus',
sell: 'banxa'
}
}, action);
expect(state.orderType).toBe('sell');
expect(state.providerId).toBe('banxa');
});
});
describe('AmountInputChanged', () => {
it('changes values', () => {
const action = {
type: _state.ExchangeActionType.AmountInputChanged,
amount: {
disabled: false,
value: 2000000,
displayValue: '2',
error: 'fake-error'
},
canExchange: false
};
const state = (0, _state.exchangeReducer)(_state.exchangeDefaultState, action);
expect(state.amount).toEqual(action.amount);
expect(state.canExchange).toEqual(action.canExchange);
});
});
describe('ProviderIdChanged', () => {
it('changes values', () => {
const action = {
type: _state.ExchangeActionType.ProviderIdChanged,
providerId: 'encryptus'
};
const amount = {
disabled: false,
value: 2000000,
displayValue: '2',
error: 'fake-error'
};
const state = (0, _state.exchangeReducer)({
..._state.exchangeDefaultState,
amount,
canExchange: true,
providerId: 'banxa'
}, action);
expect(state.amount).toEqual(_state.exchangeDefaultState.amount);
expect(state.canExchange).toBe(_state.exchangeDefaultState.canExchange);
expect(state.providerId).toBe('encryptus');
});
});
});
//# sourceMappingURL=state.test.js.map