diff --git a/.eslintrc.react.yml b/.eslintrc.react.yml index f50647a56a..05564d3999 100644 --- a/.eslintrc.react.yml +++ b/.eslintrc.react.yml @@ -41,9 +41,6 @@ rules: - error - multiline-multiprop react/jsx-handler-names: error - react/jsx-indent: - - error - - 2 react/jsx-indent-props: - error - 2 diff --git a/__tests__/__image_snapshots__/html/activity-add-decorate-js-activity-middleware-adds-a-custom-activity-with-decoration-1-snap.png b/__tests__/__image_snapshots__/html/activity-add-decorate-js-activity-middleware-adds-a-custom-activity-with-decoration-1-snap.png new file mode 100644 index 0000000000..c54f67c97d Binary files /dev/null and b/__tests__/__image_snapshots__/html/activity-add-decorate-js-activity-middleware-adds-a-custom-activity-with-decoration-1-snap.png differ diff --git a/__tests__/__image_snapshots__/html/activity-add-js-activity-middleware-adds-a-custom-activity-1-snap.png b/__tests__/__image_snapshots__/html/activity-add-js-activity-middleware-adds-a-custom-activity-1-snap.png new file mode 100644 index 0000000000..32b60c2722 Binary files /dev/null and b/__tests__/__image_snapshots__/html/activity-add-js-activity-middleware-adds-a-custom-activity-1-snap.png differ diff --git a/__tests__/__image_snapshots__/html/activity-decorate-js-activity-middleware-decorates-an-activity-by-text-1-snap.png b/__tests__/__image_snapshots__/html/activity-decorate-js-activity-middleware-decorates-an-activity-by-text-1-snap.png new file mode 100644 index 0000000000..a53af0f1e6 Binary files /dev/null and b/__tests__/__image_snapshots__/html/activity-decorate-js-activity-middleware-decorates-an-activity-by-text-1-snap.png differ diff --git a/__tests__/__image_snapshots__/html/activity-remove-js-activity-middleware-removes-an-activity-by-text-1-snap.png b/__tests__/__image_snapshots__/html/activity-remove-js-activity-middleware-removes-an-activity-by-text-1-snap.png new file mode 100644 index 0000000000..3bfe0d3d87 Binary files /dev/null and b/__tests__/__image_snapshots__/html/activity-remove-js-activity-middleware-removes-an-activity-by-text-1-snap.png differ diff --git a/__tests__/__image_snapshots__/html/activity-remove-replace-js-activity-middleware-removes-activity-and-replaces-activity-1-snap.png b/__tests__/__image_snapshots__/html/activity-remove-replace-js-activity-middleware-removes-activity-and-replaces-activity-1-snap.png new file mode 100644 index 0000000000..565f149717 Binary files /dev/null and b/__tests__/__image_snapshots__/html/activity-remove-replace-js-activity-middleware-removes-activity-and-replaces-activity-1-snap.png differ diff --git a/__tests__/__image_snapshots__/html/activity-replace-js-activity-middleware-replaces-an-activity-by-text-1-snap.png b/__tests__/__image_snapshots__/html/activity-replace-js-activity-middleware-replaces-an-activity-by-text-1-snap.png new file mode 100644 index 0000000000..517d85e6e3 Binary files /dev/null and b/__tests__/__image_snapshots__/html/activity-replace-js-activity-middleware-replaces-an-activity-by-text-1-snap.png differ diff --git a/__tests__/__image_snapshots__/html/activity-replace-remove-js-activity-middleware-replaces-activity-and-removes-activity-1-snap.png b/__tests__/__image_snapshots__/html/activity-replace-remove-js-activity-middleware-replaces-activity-and-removes-activity-1-snap.png new file mode 100644 index 0000000000..a0284de124 Binary files /dev/null and b/__tests__/__image_snapshots__/html/activity-replace-remove-js-activity-middleware-replaces-activity-and-removes-activity-1-snap.png differ diff --git a/__tests__/__image_snapshots__/html/use-create-activity-renderer-decorate-js-activity-middleware-hooks-decorates-an-activity-when-used-with-use-create-activity-renderer-1-snap.png b/__tests__/__image_snapshots__/html/use-create-activity-renderer-decorate-js-activity-middleware-hooks-decorates-an-activity-when-used-with-use-create-activity-renderer-1-snap.png new file mode 100644 index 0000000000..9997253cf4 Binary files /dev/null and b/__tests__/__image_snapshots__/html/use-create-activity-renderer-decorate-js-activity-middleware-hooks-decorates-an-activity-when-used-with-use-create-activity-renderer-1-snap.png differ diff --git a/__tests__/__image_snapshots__/html/use-render-attachment-decorate-js-activity-middleware-hooks-decorates-an-activity-when-used-with-use-render-attachment-1-snap.png b/__tests__/__image_snapshots__/html/use-render-attachment-decorate-js-activity-middleware-hooks-decorates-an-activity-when-used-with-use-render-attachment-1-snap.png new file mode 100644 index 0000000000..ae91db40d7 Binary files /dev/null and b/__tests__/__image_snapshots__/html/use-render-attachment-decorate-js-activity-middleware-hooks-decorates-an-activity-when-used-with-use-render-attachment-1-snap.png differ diff --git a/__tests__/html/middleware/shim-v1-v2/activity.add.decorate.html b/__tests__/html/middleware/shim-v1-v2/activity.add.decorate.html new file mode 100644 index 0000000000..b4f154398c --- /dev/null +++ b/__tests__/html/middleware/shim-v1-v2/activity.add.decorate.html @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/shim-v1-v2/activity.add.decorate.js b/__tests__/html/middleware/shim-v1-v2/activity.add.decorate.js new file mode 100644 index 0000000000..613003a438 --- /dev/null +++ b/__tests__/html/middleware/shim-v1-v2/activity.add.decorate.js @@ -0,0 +1,6 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('adds a custom activity with decoration', () => + runHTML('./middleware/shim-v1-v2/activity.add.decorate.html')); +}); diff --git a/__tests__/html/middleware/shim-v1-v2/activity.remove.replace.html b/__tests__/html/middleware/shim-v1-v2/activity.remove.replace.html new file mode 100644 index 0000000000..0870b1c8b1 --- /dev/null +++ b/__tests__/html/middleware/shim-v1-v2/activity.remove.replace.html @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/shim-v1-v2/activity.remove.replace.js b/__tests__/html/middleware/shim-v1-v2/activity.remove.replace.js new file mode 100644 index 0000000000..11948f47e6 --- /dev/null +++ b/__tests__/html/middleware/shim-v1-v2/activity.remove.replace.js @@ -0,0 +1,6 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('removes activity and replaces activity', () => + runHTML('./middleware/shim-v1-v2/activity.remove.replace.html')); +}); diff --git a/__tests__/html/middleware/shim-v1-v2/activity.replace.remove.html b/__tests__/html/middleware/shim-v1-v2/activity.replace.remove.html new file mode 100644 index 0000000000..5b506fa250 --- /dev/null +++ b/__tests__/html/middleware/shim-v1-v2/activity.replace.remove.html @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/shim-v1-v2/activity.replace.remove.js b/__tests__/html/middleware/shim-v1-v2/activity.replace.remove.js new file mode 100644 index 0000000000..cea7bf1d39 --- /dev/null +++ b/__tests__/html/middleware/shim-v1-v2/activity.replace.remove.js @@ -0,0 +1,6 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('replaces activity and removes activity', () => + runHTML('./middleware/shim-v1-v2/activity.replace.remove.html')); +}); diff --git a/__tests__/html/middleware/shim-v2-v1/activity.add.decorate.html b/__tests__/html/middleware/shim-v2-v1/activity.add.decorate.html new file mode 100644 index 0000000000..729c86d308 --- /dev/null +++ b/__tests__/html/middleware/shim-v2-v1/activity.add.decorate.html @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/shim-v2-v1/activity.add.decorate.js b/__tests__/html/middleware/shim-v2-v1/activity.add.decorate.js new file mode 100644 index 0000000000..d21e8532aa --- /dev/null +++ b/__tests__/html/middleware/shim-v2-v1/activity.add.decorate.js @@ -0,0 +1,6 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('adds a custom activity with decoration', () => + runHTML('./middleware/shim-v2-v1/activity.add.decorate.html')); +}); diff --git a/__tests__/html/middleware/shim-v2-v1/activity.remove.replace.html b/__tests__/html/middleware/shim-v2-v1/activity.remove.replace.html new file mode 100644 index 0000000000..74cf30a265 --- /dev/null +++ b/__tests__/html/middleware/shim-v2-v1/activity.remove.replace.html @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/shim-v2-v1/activity.remove.replace.js b/__tests__/html/middleware/shim-v2-v1/activity.remove.replace.js new file mode 100644 index 0000000000..0349320ddd --- /dev/null +++ b/__tests__/html/middleware/shim-v2-v1/activity.remove.replace.js @@ -0,0 +1,6 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('removes activity and replaces activity', () => + runHTML('./middleware/shim-v2-v1/activity.remove.replace.html')); +}); diff --git a/__tests__/html/middleware/shim-v2-v1/activity.replace.remove.html b/__tests__/html/middleware/shim-v2-v1/activity.replace.remove.html new file mode 100644 index 0000000000..1e979bc361 --- /dev/null +++ b/__tests__/html/middleware/shim-v2-v1/activity.replace.remove.html @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/shim-v2-v1/activity.replace.remove.js b/__tests__/html/middleware/shim-v2-v1/activity.replace.remove.js new file mode 100644 index 0000000000..cf60737d01 --- /dev/null +++ b/__tests__/html/middleware/shim-v2-v1/activity.replace.remove.js @@ -0,0 +1,6 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('replaces activity and removes activity', () => + runHTML('./middleware/shim-v2-v1/activity.replace.remove.html')); +}); diff --git a/__tests__/html/middleware/v1/activity.add.decorate.html b/__tests__/html/middleware/v1/activity.add.decorate.html new file mode 100644 index 0000000000..90c55afe17 --- /dev/null +++ b/__tests__/html/middleware/v1/activity.add.decorate.html @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v1/activity.add.decorate.js b/__tests__/html/middleware/v1/activity.add.decorate.js new file mode 100644 index 0000000000..74729e1c03 --- /dev/null +++ b/__tests__/html/middleware/v1/activity.add.decorate.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('adds a custom activity with decoration', () => runHTML('./middleware/v1/activity.add.decorate.html')); +}); diff --git a/__tests__/html/middleware/v1/activity.add.html b/__tests__/html/middleware/v1/activity.add.html new file mode 100644 index 0000000000..948bd070eb --- /dev/null +++ b/__tests__/html/middleware/v1/activity.add.html @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v1/activity.add.js b/__tests__/html/middleware/v1/activity.add.js new file mode 100644 index 0000000000..abb4b42361 --- /dev/null +++ b/__tests__/html/middleware/v1/activity.add.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('adds a custom activity', () => runHTML('./middleware/v1/activity.add.html')); +}); diff --git a/__tests__/html/middleware/v1/activity.decorate.html b/__tests__/html/middleware/v1/activity.decorate.html new file mode 100644 index 0000000000..1d142573fc --- /dev/null +++ b/__tests__/html/middleware/v1/activity.decorate.html @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v1/activity.decorate.js b/__tests__/html/middleware/v1/activity.decorate.js new file mode 100644 index 0000000000..e46641c143 --- /dev/null +++ b/__tests__/html/middleware/v1/activity.decorate.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('decorates an activity by text', () => runHTML('./middleware/v1/activity.decorate.html')); +}); diff --git a/__tests__/html/middleware/v1/activity.remove.html b/__tests__/html/middleware/v1/activity.remove.html new file mode 100644 index 0000000000..8ce1f94136 --- /dev/null +++ b/__tests__/html/middleware/v1/activity.remove.html @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v1/activity.remove.js b/__tests__/html/middleware/v1/activity.remove.js new file mode 100644 index 0000000000..6f365b7ef9 --- /dev/null +++ b/__tests__/html/middleware/v1/activity.remove.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('removes an activity by text', () => runHTML('./middleware/v1/activity.remove.html')); +}); diff --git a/__tests__/html/middleware/v1/activity.remove.replace.html b/__tests__/html/middleware/v1/activity.remove.replace.html new file mode 100644 index 0000000000..30d1a5f0a9 --- /dev/null +++ b/__tests__/html/middleware/v1/activity.remove.replace.html @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v1/activity.remove.replace.js b/__tests__/html/middleware/v1/activity.remove.replace.js new file mode 100644 index 0000000000..e38e292a41 --- /dev/null +++ b/__tests__/html/middleware/v1/activity.remove.replace.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('removes activity and replaces activity', () => runHTML('./middleware/v1/activity.remove.replace.html')); +}); diff --git a/__tests__/html/middleware/v1/activity.replace.html b/__tests__/html/middleware/v1/activity.replace.html new file mode 100644 index 0000000000..dd6152006d --- /dev/null +++ b/__tests__/html/middleware/v1/activity.replace.html @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v1/activity.replace.js b/__tests__/html/middleware/v1/activity.replace.js new file mode 100644 index 0000000000..1a3efce9b0 --- /dev/null +++ b/__tests__/html/middleware/v1/activity.replace.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('replaces an activity by text', () => runHTML('./middleware/v1/activity.replace.html')); +}); diff --git a/__tests__/html/middleware/v1/activity.replace.remove.html b/__tests__/html/middleware/v1/activity.replace.remove.html new file mode 100644 index 0000000000..c5c5daf7d7 --- /dev/null +++ b/__tests__/html/middleware/v1/activity.replace.remove.html @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v1/activity.replace.remove.js b/__tests__/html/middleware/v1/activity.replace.remove.js new file mode 100644 index 0000000000..e427c63f21 --- /dev/null +++ b/__tests__/html/middleware/v1/activity.replace.remove.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('replaces activity and removes activity', () => runHTML('./middleware/v1/activity.replace.remove.html')); +}); diff --git a/__tests__/html/middleware/v1/useCreateActivityRenderer.decorate.html b/__tests__/html/middleware/v1/useCreateActivityRenderer.decorate.html new file mode 100644 index 0000000000..f9118dc6be --- /dev/null +++ b/__tests__/html/middleware/v1/useCreateActivityRenderer.decorate.html @@ -0,0 +1,104 @@ + + + + + + + + + + + + + +
+ + + diff --git a/__tests__/html/middleware/v1/useCreateActivityRenderer.decorate.js b/__tests__/html/middleware/v1/useCreateActivityRenderer.decorate.js new file mode 100644 index 0000000000..eb44aadd44 --- /dev/null +++ b/__tests__/html/middleware/v1/useCreateActivityRenderer.decorate.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware hooks', () => { + test('decorates an activity when used with useCreateActivityRenderer', () => runHTML('./middleware/v1/useCreateActivityRenderer.decorate.html')); +}); diff --git a/__tests__/html/middleware/v1/useRenderAttachment.decorate.html b/__tests__/html/middleware/v1/useRenderAttachment.decorate.html new file mode 100644 index 0000000000..9cff64a74f --- /dev/null +++ b/__tests__/html/middleware/v1/useRenderAttachment.decorate.html @@ -0,0 +1,106 @@ + + + + + + + + + + + + + +
+ + + diff --git a/__tests__/html/middleware/v1/useRenderAttachment.decorate.js b/__tests__/html/middleware/v1/useRenderAttachment.decorate.js new file mode 100644 index 0000000000..b85efbbcd4 --- /dev/null +++ b/__tests__/html/middleware/v1/useRenderAttachment.decorate.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware hooks', () => { + test('decorates an activity when used with useRenderAttachment', () => runHTML('./middleware/v1/useRenderAttachment.decorate.html')); +}); \ No newline at end of file diff --git a/__tests__/html/middleware/v2/activity.add.decorate.html b/__tests__/html/middleware/v2/activity.add.decorate.html new file mode 100644 index 0000000000..516b94b620 --- /dev/null +++ b/__tests__/html/middleware/v2/activity.add.decorate.html @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v2/activity.add.decorate.js b/__tests__/html/middleware/v2/activity.add.decorate.js new file mode 100644 index 0000000000..680476bbb8 --- /dev/null +++ b/__tests__/html/middleware/v2/activity.add.decorate.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('adds a custom activity with decoration', () => runHTML('./middleware/v2/activity.add.decorate.html')); +}); diff --git a/__tests__/html/middleware/v2/activity.add.html b/__tests__/html/middleware/v2/activity.add.html new file mode 100644 index 0000000000..8e0d95abea --- /dev/null +++ b/__tests__/html/middleware/v2/activity.add.html @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v2/activity.add.js b/__tests__/html/middleware/v2/activity.add.js new file mode 100644 index 0000000000..81d0090642 --- /dev/null +++ b/__tests__/html/middleware/v2/activity.add.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('adds a custom activity', () => runHTML('./middleware/v2/activity.add.html')); +}); diff --git a/__tests__/html/middleware/v2/activity.decorate.html b/__tests__/html/middleware/v2/activity.decorate.html new file mode 100644 index 0000000000..bc1f66b0f2 --- /dev/null +++ b/__tests__/html/middleware/v2/activity.decorate.html @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v2/activity.decorate.js b/__tests__/html/middleware/v2/activity.decorate.js new file mode 100644 index 0000000000..52861f0946 --- /dev/null +++ b/__tests__/html/middleware/v2/activity.decorate.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('decorates an activity by text', () => runHTML('./middleware/v2/activity.decorate.html')); +}); diff --git a/__tests__/html/middleware/v2/activity.remove.html b/__tests__/html/middleware/v2/activity.remove.html new file mode 100644 index 0000000000..cddf687508 --- /dev/null +++ b/__tests__/html/middleware/v2/activity.remove.html @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v2/activity.remove.js b/__tests__/html/middleware/v2/activity.remove.js new file mode 100644 index 0000000000..afdbb0a95a --- /dev/null +++ b/__tests__/html/middleware/v2/activity.remove.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('removes an activity by text', () => runHTML('./middleware/v2/activity.remove.html')); +}); diff --git a/__tests__/html/middleware/v2/activity.remove.replace.html b/__tests__/html/middleware/v2/activity.remove.replace.html new file mode 100644 index 0000000000..969bbabb2b --- /dev/null +++ b/__tests__/html/middleware/v2/activity.remove.replace.html @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v2/activity.remove.replace.js b/__tests__/html/middleware/v2/activity.remove.replace.js new file mode 100644 index 0000000000..84b6af87df --- /dev/null +++ b/__tests__/html/middleware/v2/activity.remove.replace.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('removes activity and replaces activity', () => runHTML('./middleware/v2/activity.remove.replace.html')); +}); diff --git a/__tests__/html/middleware/v2/activity.replace.html b/__tests__/html/middleware/v2/activity.replace.html new file mode 100644 index 0000000000..56da585d29 --- /dev/null +++ b/__tests__/html/middleware/v2/activity.replace.html @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v2/activity.replace.js b/__tests__/html/middleware/v2/activity.replace.js new file mode 100644 index 0000000000..190b3d4d51 --- /dev/null +++ b/__tests__/html/middleware/v2/activity.replace.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('replaces an activity by text', () => runHTML('./middleware/v2/activity.replace.html')); +}); diff --git a/__tests__/html/middleware/v2/activity.replace.remove.html b/__tests__/html/middleware/v2/activity.replace.remove.html new file mode 100644 index 0000000000..70059ea186 --- /dev/null +++ b/__tests__/html/middleware/v2/activity.replace.remove.html @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/__tests__/html/middleware/v2/activity.replace.remove.js b/__tests__/html/middleware/v2/activity.replace.remove.js new file mode 100644 index 0000000000..de9df1eb94 --- /dev/null +++ b/__tests__/html/middleware/v2/activity.replace.remove.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware', () => { + test('replaces activity and removes activity', () => runHTML('./middleware/v2/activity.replace.remove.html')); +}); diff --git a/__tests__/html/middleware/v2/activityGrouping.customMiddleware.html b/__tests__/html/middleware/v2/activityGrouping.customMiddleware.html new file mode 100644 index 0000000000..0e498d37f3 --- /dev/null +++ b/__tests__/html/middleware/v2/activityGrouping.customMiddleware.html @@ -0,0 +1,194 @@ + + + + + + + + + + +
+ + + diff --git a/__tests__/html/middleware/v2/activityGrouping.customMiddleware.js b/__tests__/html/middleware/v2/activityGrouping.customMiddleware.js new file mode 100644 index 0000000000..c4b940fa79 --- /dev/null +++ b/__tests__/html/middleware/v2/activityGrouping.customMiddleware.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity grouping', () => { + test('should accept valid or invalid custom middleware', () => runHTML('./middleware/v2/activityGrouping.customMiddleware.html')); +}); diff --git a/__tests__/html/middleware/v2/useCreateActivityRenderer.decorate.html b/__tests__/html/middleware/v2/useCreateActivityRenderer.decorate.html new file mode 100644 index 0000000000..2fe8a90936 --- /dev/null +++ b/__tests__/html/middleware/v2/useCreateActivityRenderer.decorate.html @@ -0,0 +1,104 @@ + + + + + + + + + + + + + +
+ + + diff --git a/__tests__/html/middleware/v2/useCreateActivityRenderer.decorate.js b/__tests__/html/middleware/v2/useCreateActivityRenderer.decorate.js new file mode 100644 index 0000000000..7364e91156 --- /dev/null +++ b/__tests__/html/middleware/v2/useCreateActivityRenderer.decorate.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware hooks', () => { + test('decorates an activity when used with useCreateActivityRenderer', () => runHTML('./middleware/v2/useCreateActivityRenderer.decorate.html')); +}); diff --git a/__tests__/html/middleware/v2/useRenderAttachment.decorate.html b/__tests__/html/middleware/v2/useRenderAttachment.decorate.html new file mode 100644 index 0000000000..e986a0b24a --- /dev/null +++ b/__tests__/html/middleware/v2/useRenderAttachment.decorate.html @@ -0,0 +1,105 @@ + + + + + + + + + + + + + +
+ + + diff --git a/__tests__/html/middleware/v2/useRenderAttachment.decorate.js b/__tests__/html/middleware/v2/useRenderAttachment.decorate.js new file mode 100644 index 0000000000..9c8a4d581b --- /dev/null +++ b/__tests__/html/middleware/v2/useRenderAttachment.decorate.js @@ -0,0 +1,5 @@ +/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ + +describe('activity middleware hooks', () => { + test('decorates an activity when used with useRenderAttachment', () => runHTML('./middleware/v2/useRenderAttachment.decorate.html')); +}); diff --git a/packages/api/src/hooks/Composer.tsx b/packages/api/src/hooks/Composer.tsx index 6ae1f9340d..61111c119d 100644 --- a/packages/api/src/hooks/Composer.tsx +++ b/packages/api/src/hooks/Composer.tsx @@ -71,6 +71,8 @@ import { SendBoxToolbarMiddlewareProvider, type SendBoxToolbarMiddleware } from import Tracker from './internal/Tracker'; import WebChatAPIContext, { type WebChatAPIContextType } from './internal/WebChatAPIContext'; import WebChatReduxContext, { useDispatch } from './internal/WebChatReduxContext'; +import { isV2Middleware } from '../utils/v2Middleware'; + import defaultSelectVoice from './internal/defaultSelectVoice'; import applyMiddleware, { forLegacyRenderer as applyMiddlewareForLegacyRenderer, @@ -86,6 +88,7 @@ import observableToPromise from './utils/observableToPromise'; // @ts-ignore import PrecompiledGlobalize from '../external/PrecompiledGlobalize'; import { parseUIState } from './validation/uiState'; +import { ActivityMiddlewareProvider } from '../providers/ActivityMiddleware/ActivityMiddleware'; // List of Redux actions factory we are hoisting as Web Chat functions const DISPATCHERS = { @@ -407,6 +410,11 @@ const ComposerCore = ({ [telemetryDimensionsRef] ); + const isUsingActivityMiddlewareV2 = useMemo( + () => singleToArray(activityMiddleware).some(md => isV2Middleware(md)), + [activityMiddleware] + ); + const patchedActivityRenderer = useMemo( () => applyMiddlewareForRenderer( @@ -573,7 +581,8 @@ const ComposerCore = ({ typingIndicatorRenderer: patchedTypingIndicatorRenderer, uiState, userID, - username + username, + isUsingActivityMiddlewareV2 }), [ cardActionContext, @@ -600,29 +609,31 @@ const ComposerCore = ({ renderMarkdown, scrollToEndButtonRenderer, sendTypingIndicator, - telemetryDimensionsRef, trackDimension, uiState, userID, - username + username, + isUsingActivityMiddlewareV2 ] ); return ( - - - - - - {typeof children === 'function' ? children(context) : children} - - - - - - - {onTelemetry && } + + + + + + + {typeof children === 'function' ? children(context) : children} + + + + + + + {onTelemetry && } + ); }; diff --git a/packages/api/src/hooks/internal/WebChatAPIContext.ts b/packages/api/src/hooks/internal/WebChatAPIContext.ts index b7e6041e6e..b46b03c51d 100644 --- a/packages/api/src/hooks/internal/WebChatAPIContext.ts +++ b/packages/api/src/hooks/internal/WebChatAPIContext.ts @@ -86,6 +86,7 @@ export type WebChatAPIContextType = { uiState: 'blueprint' | 'disabled' | undefined; userID?: string; username?: string; + isUsingActivityMiddlewareV2: boolean; }; const context = createContext(undefined); diff --git a/packages/api/src/hooks/useCreateActivityRenderer.ts b/packages/api/src/hooks/useCreateActivityRenderer.ts index 55fb552223..831a69e179 100644 --- a/packages/api/src/hooks/useCreateActivityRenderer.ts +++ b/packages/api/src/hooks/useCreateActivityRenderer.ts @@ -1,8 +1,18 @@ -import { ActivityComponentFactory } from '../types/ActivityMiddleware'; +import { type ActivityComponentFactory } from '../types/ActivityMiddleware'; import useCreateActivityRendererInternal from './internal/useCreateActivityRendererInternal'; +import useWebChatAPIContext from './internal/useWebChatAPIContext'; +import { useCreateActivityRendererV2 } from '../providers/ActivityMiddleware/ActivityMiddleware'; // The newer useCreateActivityRenderer() hook does not support override renderAttachment(). // Only the deprecated useRenderActivity() hook support overriding renderAttachment(). export default function useCreateActivityRenderer(): ActivityComponentFactory { - return useCreateActivityRendererInternal(); + const useActivityRendererV1 = useCreateActivityRendererInternal(); + const useActivityRendererV2 = useCreateActivityRendererV2(); + const { isUsingActivityMiddlewareV2 } = useWebChatAPIContext(); + + if (isUsingActivityMiddlewareV2) { + return useActivityRendererV2; + } + + return useActivityRendererV1; } diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 47ad86b2de..674ef0d913 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -43,6 +43,7 @@ import TypingIndicatorMiddleware, { type RenderTypingIndicator } from './types/T import { type WebSpeechPonyfill } from './types/WebSpeechPonyfill'; import { type WebSpeechPonyfillFactory } from './types/WebSpeechPonyfillFactory'; +import { v2Middleware } from './utils/v2Middleware'; const buildTool = process.env.build_tool; const moduleFormat = process.env.module_format; const version = process.env.npm_package_version; @@ -61,6 +62,7 @@ export { initSendBoxToolbarMiddleware, localize, normalizeStyleOptions, + v2Middleware, version }; diff --git a/packages/api/src/providers/ActivityMiddleware/ActivityMiddleware.tsx b/packages/api/src/providers/ActivityMiddleware/ActivityMiddleware.tsx new file mode 100644 index 0000000000..739821bec9 --- /dev/null +++ b/packages/api/src/providers/ActivityMiddleware/ActivityMiddleware.tsx @@ -0,0 +1,53 @@ +import React, { ReactNode, useMemo } from 'react'; +import { OneOrMany, singleToArray } from 'botframework-webchat-core'; +import { createChainOfResponsibility } from 'react-chain-of-responsibility'; +import ActivityMiddleware, { + ActivityComponentFactory, + ActivityComponentFactoryOptions, + ActivityProps +} from '../../types/ActivityMiddleware'; +import { applyV2MiddlewareShim, middlewareTypeShim } from '../../utils/v2Middleware'; +import useWebChatAPIContext from '../../hooks/internal/useWebChatAPIContext'; + +const { Provider: ActivityMiddlewareProviderInner, useBuildComponentCallback } = createChainOfResponsibility< + ActivityComponentFactoryOptions, + ActivityProps & ActivityComponentFactoryOptions +>(); + +type ActivityMiddlewareProviderProps = Readonly<{ + middleware: OneOrMany; + children?: ReactNode | undefined; +}>; + +const ActivityMiddlewareProvider = ({ middleware, children }: ActivityMiddlewareProviderProps) => { + const { isUsingActivityMiddlewareV2 } = useWebChatAPIContext(); + return ( + + {children} + + ); +}; + +ActivityMiddlewareProvider.displayName = 'ActivityMiddlewareProvider'; + +function useCreateActivityRendererV2(): ActivityComponentFactory { + const enhancer = useBuildComponentCallback(); + return useMemo( + () => createActivityRendererOptions => { + const Component = enhancer(createActivityRendererOptions); + + if (!Component) { + return false; + } + + return props => ; + }, + [enhancer] + ); +} + +export { ActivityMiddlewareProvider, useCreateActivityRendererV2 }; diff --git a/packages/api/src/types/ActivityMiddleware.ts b/packages/api/src/types/ActivityMiddleware.ts index 341ca3285a..e673b4d324 100644 --- a/packages/api/src/types/ActivityMiddleware.ts +++ b/packages/api/src/types/ActivityMiddleware.ts @@ -33,4 +33,4 @@ type ActivityMiddleware = () => ActivityEnhancer; export default ActivityMiddleware; -export type { ActivityComponentFactory, LegacyActivityRenderer }; +export type { ActivityProps, ActivityComponentFactoryOptions, ActivityComponentFactory, LegacyActivityRenderer }; diff --git a/packages/api/src/utils/v2Middleware.tsx b/packages/api/src/utils/v2Middleware.tsx new file mode 100644 index 0000000000..54ff8f77a9 --- /dev/null +++ b/packages/api/src/utils/v2Middleware.tsx @@ -0,0 +1,60 @@ +import * as React from 'react'; +import useRenderAttachment from '../hooks/useRenderAttachment'; + +const v2MiddlewareSymbol = Symbol('WebChat-v2-middleware'); + +export function isV2Middleware(fn: any) { + return fn instanceof Function && v2MiddlewareSymbol in fn; +} + +export function v2Middleware any>(fn: F): F { + return Object.assign(fn, { [v2MiddlewareSymbol]: true }); +} + +// TODO: improve types in code bellow + +function v2MiddlewareShim(v1Middleware, middlewareTypeHandler) { + return (...init: S) => { + const enhancer = v1Middleware(...init); + return next => { + // handle calling next from v1 in v2 + const nextShim = (props, ...args) => { + if (args.length) { + throw new Error('Additional arguments in next() are not supported when using v2 middlewares'); + } + const Next = next(props); + if (!Next) { + return false; + } + return middlewareTypeHandler.v1(Next); + }; + const fn = enhancer(nextShim); + return props => { + const result = fn(props); + if (!result) { + return false; + } + return middlewareTypeHandler.v2(result); + }; + }; + }; +} + +export const middlewareTypeShim = { + activity: { + v2: result => + function ActivityRendererShim(props) { + // renderAttachmentOverride is not supported anymore + const renderAttachment = useRenderAttachment(); + return result instanceof Function ? result(renderAttachment, props) : result; + }, + v1: Next => + function renderActivity(legacyRenderAttachment, props) { + return ; + } + } +} as const; + +export function applyV2MiddlewareShim(middlewaress, shimType) { + return middlewaress.map(md => (isV2Middleware(md) ? md : v2MiddlewareShim(md, shimType))); +} diff --git a/packages/bundle/src/module/exports-minimal.ts b/packages/bundle/src/module/exports-minimal.ts index 246ac57436..2c313ce6bc 100644 --- a/packages/bundle/src/module/exports-minimal.ts +++ b/packages/bundle/src/module/exports-minimal.ts @@ -1,4 +1,4 @@ -import { StrictStyleOptions, StyleOptions } from 'botframework-webchat-api'; +import { StrictStyleOptions, StyleOptions, v2Middleware } from 'botframework-webchat-api'; import * as apiDecorator from 'botframework-webchat-api/decorator'; import { WebChatDecorator } from 'botframework-webchat-component/decorator'; import { Constants, createStore, createStoreWithDevTools, createStoreWithOptions } from 'botframework-webchat-core'; @@ -74,6 +74,7 @@ export { ReactWebChat, renderWebChat, testIds, + v2Middleware, version, withEmoji }; diff --git a/packages/bundle/src/module/exports.ts b/packages/bundle/src/module/exports.ts index ea1a5cff41..361ec8c9fc 100644 --- a/packages/bundle/src/module/exports.ts +++ b/packages/bundle/src/module/exports.ts @@ -46,6 +46,7 @@ export { decorator, internal, testIds, + v2Middleware, version } from './exports-minimal';