forked from Ivasoft/mattermost-mobile
(cherry picked from commit ae43ba1187)
Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
This commit is contained in:
@@ -82,7 +82,12 @@ public class RNPasteableActionCallback implements ActionMode.Callback {
|
||||
return null;
|
||||
}
|
||||
|
||||
String text = item.getText().toString();
|
||||
CharSequence chars = item.getText();
|
||||
if (chars == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String text = chars.toString();
|
||||
if (text.length() > 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,17 @@ export class PasteableTextInput extends React.PureComponent {
|
||||
}
|
||||
}
|
||||
|
||||
getLastSubscriptionKey = () => {
|
||||
const subscriptions = OnPasteEventEmitter._subscriber._subscriptionsForType.onPaste?.filter((sub) => sub); // eslint-disable-line no-underscore-dangle
|
||||
return subscriptions?.length && subscriptions[subscriptions.length - 1].key;
|
||||
}
|
||||
|
||||
onPaste = (event) => {
|
||||
const lastSubscriptionKey = this.getLastSubscriptionKey();
|
||||
if (this.subscription.key !== lastSubscriptionKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
let data = null;
|
||||
let error = null;
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ import {PasteableTextInput} from './index';
|
||||
const nativeEventEmitter = new NativeEventEmitter();
|
||||
|
||||
describe('PasteableTextInput', () => {
|
||||
const emit = jest.spyOn(EventEmitter, 'emit');
|
||||
|
||||
test('should render pasteable text input', () => {
|
||||
const onPaste = jest.fn();
|
||||
const text = 'My Text';
|
||||
@@ -24,12 +26,11 @@ describe('PasteableTextInput', () => {
|
||||
test('should call onPaste props if native onPaste trigger', () => {
|
||||
const event = {someData: 'data'};
|
||||
const text = 'My Text';
|
||||
const onPaste = jest.spyOn(EventEmitter, 'emit');
|
||||
shallow(
|
||||
<PasteableTextInput>{text}</PasteableTextInput>,
|
||||
);
|
||||
nativeEventEmitter.emit('onPaste', event);
|
||||
expect(onPaste).toHaveBeenCalledWith(PASTE_FILES, null, event);
|
||||
expect(emit).toHaveBeenCalledWith(PASTE_FILES, null, event);
|
||||
});
|
||||
|
||||
test('should remove onPaste listener when unmount', () => {
|
||||
@@ -43,4 +44,16 @@ describe('PasteableTextInput', () => {
|
||||
component.instance().componentWillUnmount();
|
||||
expect(mockRemove).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('should emit PASTE_FILES event only for last subscription', () => {
|
||||
const component1 = shallow(<PasteableTextInput/>);
|
||||
const instance1 = component1.instance();
|
||||
const component2 = shallow(<PasteableTextInput/>);
|
||||
const instance2 = component2.instance();
|
||||
|
||||
instance1.onPaste();
|
||||
expect(emit).not.toHaveBeenCalled();
|
||||
instance2.onPaste();
|
||||
expect(emit).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user