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 <changingrainbows@gmail.com>
This commit is contained in:
Elias Nahum 2020-04-27 10:04:58 -04:00 committed by GitHub
parent 20c290fbdc
commit 798efbd57f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 1 deletions

View file

@ -188,7 +188,7 @@ export default class ChannelBase extends PureComponent {
showModal(screen, title, null, options);
});
});
}, 1000);
handleAutoComplete = (value) => {
if (this.postTextbox?.current) {

48
app/utils/tap.test.js Normal file
View file

@ -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);
});
});