Skip to content

Commit

Permalink
chore: convert 2 more test files to remove given and switch to TS (#882)
Browse files Browse the repository at this point in the history
* chore: convert more given tests to TS

* no given for toolbar tests

* convert and fix toolbar tests
  • Loading branch information
pauldambra authored Nov 9, 2023
1 parent 3284071 commit 62d40fb
Show file tree
Hide file tree
Showing 4 changed files with 285 additions and 289 deletions.
83 changes: 0 additions & 83 deletions src/__tests__/extensions/rageclick.js

This file was deleted.

86 changes: 86 additions & 0 deletions src/__tests__/extensions/rageclick.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import RageClick from '../../extensions/rageclick'

describe('RageClick()', () => {
let instance: RageClick

describe('when enabled', () => {
beforeEach(() => {
instance = new RageClick(true)
})

it('identifies some rage clicking', () => {
const detection = [
instance.isRageClick(0, 0, 10),
instance.isRageClick(10, 10, 20),
instance.isRageClick(5, 5, 40), // triggers rage click
instance.isRageClick(5, 5, 50), // does not re-trigger
]

expect(detection).toEqual([false, false, true, false])
})

it('identifies some rage clicking when time delta has passed', () => {
const detection = [
instance.isRageClick(0, 0, 10),
instance.isRageClick(10, 10, 20),
instance.isRageClick(5, 5, 40), // triggers rage click
// these next three don't trigger
// because you need to move past threshold before triggering again
instance.isRageClick(5, 5, 80),
instance.isRageClick(5, 5, 100),
instance.isRageClick(5, 5, 110),
// moving past the time threshold resets the counter
instance.isRageClick(5, 5, 1120),
instance.isRageClick(5, 5, 1121),
instance.isRageClick(5, 5, 1122), // triggers rage click
]

expect(detection).toEqual([false, false, true, false, false, false, false, false, true])
})

it('identifies some rage clicking when pixel delta has passed', () => {
const detection = [
instance.isRageClick(0, 0, 10),
instance.isRageClick(10, 10, 20),
instance.isRageClick(5, 5, 40), // triggers rage click
// these next three don't trigger
// because you need to move past threshold before triggering again
instance.isRageClick(5, 5, 80),
instance.isRageClick(5, 5, 100),
instance.isRageClick(5, 5, 110),
// moving past the pixel threshold resets the counter
instance.isRageClick(36, 5, 120),
instance.isRageClick(36, 5, 130),
instance.isRageClick(36, 5, 140), // triggers rage click
]

expect(detection).toEqual([false, false, true, false, false, false, false, false, true])
})

it('does not capture clicks too far apart (time)', () => {
instance.isRageClick(5, 5, 10)
instance.isRageClick(5, 5, 20)
const rageClickDetected = instance.isRageClick(5, 5, 4000)

expect(rageClickDetected).toBeFalsy()
})

it('does not capture clicks too far apart (space)', () => {
instance.isRageClick(0, 0, 10)
instance.isRageClick(10, 10, 20)
const rageClickDetected = instance.isRageClick(50, 10, 40)

expect(rageClickDetected).toBeFalsy()
})
})

test('does not capture rage clicks when disabled', () => {
instance = new RageClick(false)

instance.isRageClick(5, 5, 10)
instance.isRageClick(5, 5, 20)
const rageClickDetected = instance.isRageClick(5, 5, 40)

expect(rageClickDetected).toBeFalsy()
})
})
206 changes: 0 additions & 206 deletions src/__tests__/extensions/toolbar.js

This file was deleted.

Loading

0 comments on commit 62d40fb

Please sign in to comment.