Skip to content

Instantly share code, notes, and snippets.

@nikfrank
Last active June 1, 2017 20:19
Show Gist options
  • Save nikfrank/693775357f636969341443d4d2c60d1c to your computer and use it in GitHub Desktop.
Save nikfrank/693775357f636969341443d4d2c60d1c to your computer and use it in GitHub Desktop.
React user scenario with multiple events
import pegScore from '../util/pegScore';
it('disallows stack tipping', () => {
// set up redux store and connect a device component to it
const stores = bootStores( [ networkMiddleware(networkHandlers) ] );
const { getDevice } = connectDeviceFactory( stores );
const { appStore } = stores;
const handInitState = Pegging.initState.merge({
hands: [
[
{ rank:11, suit:0 },
{ rank:11, suit:1 },
{ rank:11, suit:2 },
{ rank:11, suit:3 },
],
[
{ rank:12, suit:0 },
{ rank:12, suit:1 },
{ rank:12, suit:2 },
{ rank:1, suit:3 },
],
],
nextToPlay: 0,
});
const dataPath = [];
const PeggingDevice = getDevice(Pegging, dataPath, handInitState);
const p = mount(
<PeggingDevice />
);
return Promise.resolve()
.then( ()=> p.find(Card) )
.then( getNextState(
appStore,
cards => cards.at(1).simulate('click')
) ).then(toJS)
.then( rejectify( state => {
// computer and human have each played a card
expect( state.played ).toHaveLength( 2 );
expect( state.hands[0] ).toHaveLength( 3 );
expect( state.hands[1] ).toHaveLength( 3 );
}) )
.then( getNextState(appStore) ).then(toJS) // computer plays another card automatically
.then( rejectify( state => {
expect( pegScore(state.played).count ).toEqual( 30 ); // only cribbage players will understand this
expect( state.played ).toHaveLength( 3 );
expect( state.hands[0] ).toHaveLength( 2 );
expect( state.hands[1] ).toHaveLength( 3 );
}) )
.then( ()=> p.find(Card) )
.then( getNextState(
appStore,
cards => cards.at(3).simulate('click') // here we try to play a card we aren't allowed to
) ).then(toJS)
.then( rejectify( state => {
// should block playing card that'd tip the stack
expect( state.played ).toHaveLength( 3 );
}) )
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment