From 798efbd57f4561b086660ace63c917b4573a8aa9 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Mon, 27 Apr 2020 10:04:58 -0400 Subject: [PATCH] MM-22089 set default prevent double tap to 1s for ChannelInfo modal (#4133) * MM-22089 set default prevent double tap to 1s * Increase tap debounce delay for ChannelInfo modal action Co-authored-by: Amit Uttam --- app/screens/channel/channel_base.js | 2 +- app/utils/tap.test.js | 48 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 app/utils/tap.test.js diff --git a/app/screens/channel/channel_base.js b/app/screens/channel/channel_base.js index a865b5bd3..f8e16bc31 100644 --- a/app/screens/channel/channel_base.js +++ b/app/screens/channel/channel_base.js @@ -188,7 +188,7 @@ export default class ChannelBase extends PureComponent { showModal(screen, title, null, options); }); - }); + }, 1000); handleAutoComplete = (value) => { if (this.postTextbox?.current) { diff --git a/app/utils/tap.test.js b/app/utils/tap.test.js new file mode 100644 index 000000000..2bb3062f9 --- /dev/null +++ b/app/utils/tap.test.js @@ -0,0 +1,48 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import {preventDoubleTap} from './tap'; + +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(); + }, 300); + }); +});