From 4efba77c698516d60310e302d2a4d566b3ddc2a8 Mon Sep 17 00:00:00 2001 From: * <8> Date: Fri, 5 Aug 2022 17:54:29 +0800 Subject: [PATCH 1/2] Match-id-811ec747208f5b0bb20f60c085e1cd4fb03fc3e1 --- .../adapters/ReduxAdapterPromiseMiddleware.js | 85 ------------------- 1 file changed, 85 deletions(-) diff --git a/scripts/__tests__/HorizonXText/adapters/ReduxAdapterPromiseMiddleware.js b/scripts/__tests__/HorizonXText/adapters/ReduxAdapterPromiseMiddleware.js index 509706cf..3c4a8f11 100644 --- a/scripts/__tests__/HorizonXText/adapters/ReduxAdapterPromiseMiddleware.js +++ b/scripts/__tests__/HorizonXText/adapters/ReduxAdapterPromiseMiddleware.js @@ -9,88 +9,3 @@ export const promise = store => next => action => { store._horizonXstore.$queue.dispatch(action); return result; }; - -export function createPromise(config = {}) { - const defaultTypes = [ActionType.Pending, ActionType.Fulfilled, ActionType.Rejected]; - const PROMISE_TYPE_SUFFIXES = config.promiseTypeSuffixes || defaultTypes; - const PROMISE_TYPE_DELIMITER = config.promiseTypeDelimiter || '_'; - - return store => { - const { dispatch } = store; - - return next => action => { - /** - * Instantiate variables to hold: - * (1) the promise - * (2) the data for optimistic updates - */ - let promise; - let data; - - /** - * There are multiple ways to dispatch a promise. The first step is to - * determine if the promise is defined: - * (a) explicitly (action.payload.promise is the promise) - * (b) implicitly (action.payload is the promise) - * (c) as an async function (returns a promise when called) - * - * If the promise is not defined in one of these three ways, we don't do - * anything and move on to the next middleware in the middleware chain. - */ - - // Step 1a: Is there a payload? - if (action.payload) { - const PAYLOAD = action.payload; - - // Step 1.1: Is the promise implicitly defined? - if (isPromise(PAYLOAD)) { - promise = PAYLOAD; - } - - // Step 1.2: Is the promise explicitly defined? - else if (isPromise(PAYLOAD.promise)) { - promise = PAYLOAD.promise; - data = PAYLOAD.data; - } - - // Step 1.3: Is the promise returned by an async function? - else if (typeof PAYLOAD === 'function' || typeof PAYLOAD.promise === 'function') { - promise = PAYLOAD.promise ? PAYLOAD.promise() : PAYLOAD(); - data = PAYLOAD.promise ? PAYLOAD.data : undefined; - - // Step 1.3.1: Is the return of action.payload a promise? - if (!isPromise(promise)) { - // If not, move on to the next middleware. - return next({ - ...action, - payload: promise, - }); - } - } - - // Step 1.4: If there's no promise, move on to the next middleware. - else { - return next(action); - } - - // Step 1b: If there's no payload, move on to the next middleware. - } else { - return next(action); - } - - /** - * Instantiate and define constants for: - * (1) the action type - * (2) the action meta - */ - const TYPE = action.type; - const META = action.meta; - - /** - * Instantiate and define constants for the action type suffixes. - * These are appended to the end of the action type. - */ - const [PENDING, FULFILLED, REJECTED] = PROMISE_TYPE_SUFFIXES; - }; - }; -} From 601182d475ddf02d19a092a7f35c9de2def70414 Mon Sep 17 00:00:00 2001 From: * <8> Date: Fri, 5 Aug 2022 17:57:27 +0800 Subject: [PATCH 2/2] Match-id-50e3930da8f62898ab4eca420f3c4aeef6244979 --- .../__tests__/EventTest/KeyboardEvent.test.js | 98 +++++-------------- 1 file changed, 24 insertions(+), 74 deletions(-) diff --git a/scripts/__tests__/EventTest/KeyboardEvent.test.js b/scripts/__tests__/EventTest/KeyboardEvent.test.js index 094cb1fe..ccc29222 100644 --- a/scripts/__tests__/EventTest/KeyboardEvent.test.js +++ b/scripts/__tests__/EventTest/KeyboardEvent.test.js @@ -1,8 +1,17 @@ import * as Horizon from '@cloudsop/horizon/index.ts'; -import { getLogUtils } from '../jest/testUtils'; +import {getLogUtils} from '../jest/testUtils'; describe('Keyboard Event', () => { const LogUtils = getLogUtils(); + const getKeyboardEvent = (type, keyCode, code, charCode) => { + return new KeyboardEvent(type, { + keyCode: keyCode ?? undefined, + code: code ?? undefined, + charCode: charCode ?? undefined, + bubbles: true, + cancelable: true, + }); + }; it('keydown,keypress,keyup的keycode,charcode', () => { const node = Horizon.render( @@ -16,26 +25,12 @@ describe('Keyboard Event', () => { />, container, ); - node.dispatchEvent( - new KeyboardEvent('keydown', { - keyCode: 50, - code: 'Digit2', - bubbles: true, - cancelable: true, - }), - ); - node.dispatchEvent( - new KeyboardEvent('keyup', { - keyCode: 50, - code: 'Digit2', - bubbles: true, - cancelable: true, - }), - ); + node.dispatchEvent(getKeyboardEvent('keydown', 50, 'Digit2')); + node.dispatchEvent(getKeyboardEvent('keyup', 50, 'Digit2')); expect(LogUtils.getAndClear()).toEqual([ 'onKeyDown: keycode: 50,charcode: 0', - 'onKeyUp: keycode: 50,charcode: 0' + 'onKeyUp: keycode: 50,charcode: 0', ]); }); @@ -48,17 +43,10 @@ describe('Keyboard Event', () => { />, container, ); - node.dispatchEvent( - new KeyboardEvent('keypress', { - charCode: 50, - code: 'Digit2', - bubbles: true, - cancelable: true, - }), - ); + node.dispatchEvent(getKeyboardEvent('keypress', undefined, 'Digit2', 50)); expect(LogUtils.getAndClear()).toEqual([ - 'onKeyPress: keycode: 0,charcode: 50' + 'onKeyPress: keycode: 0,charcode: 50', ]); }); @@ -71,15 +59,9 @@ describe('Keyboard Event', () => { />, container, ); - node.dispatchEvent( - new KeyboardEvent('keypress', { - charCode: 13, - bubbles: true, - cancelable: true, - }), - ); + node.dispatchEvent(getKeyboardEvent('keypress', undefined, undefined, 13)); expect(LogUtils.getAndClear()).toEqual([ - 'onKeyPress: keycode: 0,charcode: 13' + 'onKeyPress: keycode: 0,charcode: 13', ]); }); @@ -98,22 +80,8 @@ describe('Keyboard Event', () => { />, container, ); - node.dispatchEvent( - new KeyboardEvent('keydown', { - code: 'Digit2', - bubbles: true, - cancelable: true, - }), - ); - - node.dispatchEvent( - new KeyboardEvent('keypress', { - keyCode: 50, - code: 'Digit2', - bubbles: true, - cancelable: true, - }), - ); + node.dispatchEvent(getKeyboardEvent('keydown', undefined, 'Digit2')); + node.dispatchEvent(getKeyboardEvent('keypress', undefined, 'Digit2', 50)); node.dispatchEvent( new KeyboardEvent('keyup', { @@ -126,7 +94,7 @@ describe('Keyboard Event', () => { expect(LogUtils.getAndClear()).toEqual([ 'onKeyDown: code: Digit2', 'onKeyPress: code: Digit2', - 'onKeyUp: code: Digit2' + 'onKeyUp: code: Digit2', ]); }); @@ -149,32 +117,14 @@ describe('Keyboard Event', () => { />, container, ); + div.dispatchEvent(getKeyboardEvent('keydown', 40)); + div.dispatchEvent(getKeyboardEvent('keyup', 40)); + div.dispatchEvent(getKeyboardEvent('keypress', 40)); - div.dispatchEvent( - new KeyboardEvent('keydown', { - keyCode: 40, - bubbles: true, - cancelable: true, - }), - ); - div.dispatchEvent( - new KeyboardEvent('keyup', { - keyCode: 40, - bubbles: true, - cancelable: true, - }), - ); - div.dispatchEvent( - new KeyboardEvent('keypress', { - charCode: 40, - bubbles: true, - cancelable: true, - }), - ); expect(LogUtils.getAndClear()).toEqual([ 'keydown handle', 'keyup handle', - 'keypress handle' + 'keypress handle', ]); }); });