Skip to content

Commit

Permalink
Merge pull request #4 from japamat/rithm-burst-issue-16
Browse files Browse the repository at this point in the history
Throws error on burst image capture when user inputs bad expression index
  • Loading branch information
misscoded authored Jun 20, 2019
2 parents 350dd64 + 6966d03 commit 8e52f10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/actions/action-creators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ const desmosMock = {
GraphingCalculator: jest.fn(() => {
return {
asyncScreenshot: (opts, cb) => cb(''),
getExpressions: () => [{ id: 1, latex: 'x = 3' }, { id: 2, latex: '' }],
getExpressions: () => [
{ id: 1, type: 'expression', latex: 'x = 3' },
{ id: 2, latex: '' }
],
setExpression: () => null
};
})
Expand Down
6 changes: 5 additions & 1 deletion src/lib/calc-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ export const getImageData = opts =>
*/
const getExpByIndex = idx => calculator.getExpressions()[idx - 1];

// Returns an error message on failure.
/**
* Returns an error message on failure.
* Skips expressions that are not of type 'expression'
*/
export const setSliderByIndex = (idx, val) => {
const exp = getExpByIndex(idx);
if (!exp) return noSuchExpression(idx);
if (exp.type !== 'expression') return notASlider(idx);

const { id, latex } = exp;
const match = latex.match(/(.+)=/);
Expand Down

0 comments on commit 8e52f10

Please sign in to comment.