Clean up
This commit is contained in:
Родитель
9d9ae05e89
Коммит
be31132f61
|
@ -1,7 +1,7 @@
|
|||
const { compose } = require('redux');
|
||||
const observableToArray = require('../__jest__/observableToArray');
|
||||
|
||||
const { default: createAdapter, CLOSED, CONNECTING, OPEN } = require('../../src/index');
|
||||
const { default: createAdapter, applyEgressMiddleware, CLOSED, CONNECTING, OPEN } = require('../../src/index');
|
||||
const { default: exportDLJSInterface } = require('../../src/enhancers/exportDLJSInterface');
|
||||
|
||||
describe('exportDLJSInterface.connectionStatus$', () => {
|
||||
|
@ -24,7 +24,7 @@ describe('exportDLJSInterface.connectionStatus$', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('"open"/"error" should set connectionStatus$ accordingly', async () => {
|
||||
test.only('"open"/"error" should set connectionStatus$ accordingly', async () => {
|
||||
let interims;
|
||||
const abortController = new AbortController();
|
||||
|
||||
|
@ -60,3 +60,23 @@ describe('exportDLJSInterface.connectionStatus$', () => {
|
|||
setReadyState(OPEN);
|
||||
});
|
||||
});
|
||||
|
||||
test('setReadyState should propagate to connectionStatus$ when enhancer is placed before exportDLJSInterface()', async () => {
|
||||
const adapter = createAdapter(
|
||||
{},
|
||||
compose(
|
||||
applyEgressMiddleware(({ setReadyState }) => next => activity => {
|
||||
setReadyState(OPEN);
|
||||
|
||||
return next(activity);
|
||||
}),
|
||||
exportDLJSInterface()
|
||||
)
|
||||
);
|
||||
|
||||
const connectionStatusPromise = observableToArray(adapter.connectionStatus$, { count: 3 });
|
||||
|
||||
adapter.egress(1);
|
||||
|
||||
await expect(connectionStatusPromise).resolves.toEqual([0, 1, 2]);
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ describe('exportDLJSInterface.end', () => {
|
|||
|
||||
const adapter = createAdapter(
|
||||
{},
|
||||
compose(exportDLJSInterface(), () => () => ({ close }))
|
||||
compose(exportDLJSInterface(), next => options => ({ ...next(options), close }))
|
||||
);
|
||||
|
||||
expect(close).toHaveBeenCalledTimes(0);
|
||||
|
|
|
@ -15,7 +15,9 @@ describe('exportDLJSInterface.postActivity', () => {
|
|||
|
||||
const adapter = createAdapter(
|
||||
{},
|
||||
compose(exportDLJSInterface(), () => () => ({
|
||||
compose(exportDLJSInterface(), next => options => ({
|
||||
...next(options),
|
||||
|
||||
egress: async (activity, { progress }) => {
|
||||
await checkpoint1.pause();
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ export default function createAdapter<TActivity>(
|
|||
}
|
||||
|
||||
readyStatePropertyValue = readyState;
|
||||
|
||||
eventTarget.dispatchEvent(createEvent(readyState === ReadyState.OPEN ? 'open' : 'error'));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -28,6 +28,16 @@ export default function exportDLJSInterface(): AdapterEnhancer<IDirectLineActivi
|
|||
const adapter = next(options);
|
||||
let connectionStatusObserver: Observer<ConnectionStatus>;
|
||||
|
||||
adapter.addEventListener('open', () => {
|
||||
connectionStatusObserver.next(ConnectionStatus.Connected);
|
||||
});
|
||||
|
||||
adapter.addEventListener('error', () => {
|
||||
connectionStatusObserver.next(
|
||||
adapter.getReadyState() === ReadyState.CLOSED ? ConnectionStatus.FailedToConnect : ConnectionStatus.Connecting
|
||||
);
|
||||
});
|
||||
|
||||
return {
|
||||
...adapter,
|
||||
|
||||
|
@ -47,7 +57,9 @@ export default function exportDLJSInterface(): AdapterEnhancer<IDirectLineActivi
|
|||
}
|
||||
})();
|
||||
|
||||
return () => abortController.abort();
|
||||
return () => {
|
||||
abortController.abort();
|
||||
};
|
||||
})
|
||||
),
|
||||
|
||||
|
@ -74,28 +86,6 @@ export default function exportDLJSInterface(): AdapterEnhancer<IDirectLineActivi
|
|||
})
|
||||
.then(() => observer.complete());
|
||||
});
|
||||
},
|
||||
|
||||
setReadyState(readyState: ReadyState) {
|
||||
if (!connectionStatusObserver) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (readyState) {
|
||||
case ReadyState.CONNECTING:
|
||||
connectionStatusObserver.next(ConnectionStatus.Connecting);
|
||||
break;
|
||||
|
||||
case ReadyState.OPEN:
|
||||
connectionStatusObserver.next(ConnectionStatus.Connected);
|
||||
break;
|
||||
|
||||
case ReadyState.CLOSED:
|
||||
connectionStatusObserver.next(ConnectionStatus.FailedToConnect);
|
||||
break;
|
||||
}
|
||||
|
||||
adapter.setReadyState(readyState);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
import { Adapter, ReadyState } from './types/AdapterTypes';
|
||||
import { compose } from 'redux';
|
||||
import applyEgressMiddleware from './applyEgressMiddleware';
|
||||
import applyIngressMiddleware from './applyIngressMiddleware';
|
||||
import createAdapter from './createAdapter';
|
||||
import exportDLJSInterface from './enhancers/exportDLJSInterface';
|
||||
|
||||
export default createAdapter;
|
||||
|
||||
const { CLOSED, CONNECTING, OPEN } = ReadyState;
|
||||
|
||||
export { applyEgressMiddleware, applyIngressMiddleware, CLOSED, CONNECTING, OPEN };
|
||||
export { applyEgressMiddleware, applyIngressMiddleware, CLOSED, compose, CONNECTING, exportDLJSInterface, OPEN };
|
||||
|
||||
export type { Adapter }
|
||||
export type { Adapter };
|
||||
|
|
|
@ -9,6 +9,7 @@ let config = {
|
|||
mode: 'production',
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
library: 'ChatAdapter',
|
||||
libraryTarget: 'umd',
|
||||
path: resolve(__dirname, 'dist')
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче