Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throws error on burst image capture when user inputs bad expression index #4

Merged
merged 4 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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