Created
July 9, 2019 11:07
-
-
Save icodejs/24026622cb4b7f954dcc4f80130078df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
SELECT_MIDI_CONTROLLER, | |
SELECT_NUMBER_OF_KEYBOARD_OCTAVES, | |
SET_WEB_MIDI_SUPPORTED, | |
} from './action-types'; | |
export const initialState = { | |
selectedDeviceName: 'APC Key 25', | |
webMidiSupported: false, | |
}; | |
function seePianoKeyApp(state = initialState, action) { | |
switch (action.type) { | |
case SELECT_MIDI_CONTROLLER: | |
return { | |
...state, | |
selectedDeviceName: action.selectedDeviceName | |
}; | |
case SELECT_NUMBER_OF_KEYBOARD_OCTAVES: | |
return { | |
...state, | |
numberOfKeyboardOctaves: action.numberOfKeyboardOctaves | |
} | |
case SET_WEB_MIDI_SUPPORTED: | |
return { | |
...state, | |
webMidiSupported: action.webMidiSupported, | |
}; | |
default: | |
return state; | |
} | |
} | |
export default seePianoKeyApp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import reducer, { initialState } from './reducer'; | |
import * as types from './action-types'; | |
describe('reducer', () => { | |
it('should return initial state', () => { | |
expect(reducer(undefined, {})).toEqual(initialState); | |
}); | |
it('should handle SELECT_MIDI_CONTROLLER', () => { | |
const fakeMidiController = 'fake-controller'; | |
expect( | |
reducer(undefined, { | |
type: types.SELECT_MIDI_CONTROLLER, | |
selectedDeviceName: fakeMidiController, | |
}), | |
).toEqual({ | |
...initialState, | |
selectedDeviceName: fakeMidiController, | |
}); | |
}); | |
it('should handle SELECT_NUMBER_OF_KEYBOARD_OCTAVES', () => { | |
const fakeNumberOfOctaves = 'fake-controller'; | |
expect( | |
reducer(undefined, { | |
type: types.SELECT_NUMBER_OF_KEYBOARD_OCTAVES, | |
numberOfKeyboardOctaves: fakeNumberOfOctaves, | |
}), | |
).toEqual({ | |
...initialState, | |
numberOfKeyboardOctaves: fakeNumberOfOctaves, | |
}); | |
}); | |
it('should handle SET_WEB_MIDI_SUPPORTED', () => { | |
expect( | |
reducer(undefined, { | |
type: types.SET_WEB_MIDI_SUPPORTED, | |
webMidiSupported: true, | |
}), | |
).toEqual({ | |
...initialState, | |
webMidiSupported: true, | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment