-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: apply code review changes.
- Loading branch information
Showing
7 changed files
with
124 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { assertPoint, assertDuration } = require('./assertArgument'); | ||
|
||
function mapLongPressArguments(optionalPointOrDuration, optionalDuration) { | ||
let point = null; | ||
let duration = null; | ||
|
||
try { | ||
if (optionalPointOrDuration !== undefined) { | ||
assertPoint(optionalPointOrDuration); | ||
point = optionalPointOrDuration; | ||
|
||
if (optionalDuration !== undefined) { | ||
assertDuration(optionalDuration); | ||
duration = optionalDuration; | ||
} | ||
} else if (optionalDuration !== undefined) { | ||
assertDuration(optionalDuration); | ||
duration = optionalDuration; | ||
} | ||
} catch (e) { | ||
throw new Error(`longPress accepts either a duration (number) or a point ({x: number, y: number}) as ` + | ||
`its first argument, and optionally a duration (number) as its second argument. Error: ${e.message}`); | ||
} | ||
|
||
return { point, duration }; | ||
} | ||
|
||
module.exports = mapLongPressArguments; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const mapLongPressArguments = require('./mapLongPressArguments'); | ||
describe('mapLongPressArguments', () => { | ||
it('should return { point: { x: 1, y: 2 }, duration: 3 } for { x: 1, y: 2 }, 3', () => { | ||
expect(mapLongPressArguments({ x: 1, y: 2 }, 3)).toEqual({ point: { x: 1, y: 2 }, duration: 3 }); | ||
}); | ||
|
||
it('should return { point: { x: 1, y: 2 }, duration: null } for { x: 1, y: 2 }', () => { | ||
expect(mapLongPressArguments({ x: 1, y: 2 })).toEqual({ point: { x: 1, y: 2 }, duration: null }); | ||
}); | ||
|
||
it('should return { point: null, duration: 3 } for null, 3', () => { | ||
expect(mapLongPressArguments(null, 3)).toEqual({ point: null, duration: 3 }); | ||
}); | ||
|
||
it('should return { point: null, duration: 3 } for 3', () => { | ||
expect(mapLongPressArguments(3)).toEqual({ point: null, duration: 3 }); | ||
}); | ||
|
||
it('should return { point: null, duration: null } for no arguments', () => { | ||
expect(mapLongPressArguments()).toEqual({ point: null, duration: null }); | ||
}); | ||
|
||
it('should throw for invalid point', () => { | ||
expect(() => mapLongPressArguments({ x: 1 })).toThrowError('point should be an object with x and y properties, but got {"x":1}'); | ||
}); | ||
|
||
it('should throw for invalid duration', () => { | ||
expect(() => mapLongPressArguments({ x: 1, y: 2 }, '3')).toThrowError('duration should be a number, but got 3 (string)'); | ||
}); | ||
}); |