mattermost-mobile/app/utils/tap/index.test.ts
Daniel Espino García 0c4a42a06a
Remove tand prevent double tap (#9078)
* Remove the t function and all wrong uses of preventDoubleTap

* Fix existing typo

* Fix tests

* Address comments

* Fix test
2025-08-25 12:03:01 +02:00

49 lines
1.4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {preventDoubleTap} from './index';
/*eslint max-nested-callbacks: 0 */
describe('Prevent double tap', () => {
it('should prevent double taps within the 300ms default', (done) => {
const testFunction = jest.fn();
const test = preventDoubleTap(testFunction);
test();
test();
expect(testFunction).toHaveBeenCalledTimes(1);
setTimeout(() => {
test();
expect(testFunction).toHaveBeenCalledTimes(1);
done();
}, 100);
});
it('should prevent double taps within 1 second', (done) => {
const testFunction = jest.fn();
const test = preventDoubleTap(testFunction, 1000);
test();
test();
expect(testFunction).toHaveBeenCalledTimes(1);
setTimeout(() => {
test();
expect(testFunction).toHaveBeenCalledTimes(1);
done();
}, 900);
});
it('should register multiple taps when done > 300ms apart', (done) => {
const testFunction = jest.fn();
const test = preventDoubleTap(testFunction);
test();
test();
expect(testFunction).toHaveBeenCalledTimes(1);
setTimeout(() => {
test();
expect(testFunction).toHaveBeenCalledTimes(2);
done();
}, 750);
});
});