diff --git a/CHANGELOG.md b/CHANGELOG.md index c0697b7d45..e27fca9b38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - PR [#2544](https://github.com/microsoft/BotFramework-WebChat/pull/2544): `useAvatarForBot`, `useAvatarForUser` - PR [#2547](https://github.com/microsoft/BotFramework-WebChat/pull/2547): `useEmitTypingIndicator`, `usePeformCardAction`, `usePostActivity`, `useSendEvent`, `useSendFiles`, `useSendMessage`, `useSendMessageBack`, `useSendPostBack` - PR [#2548](https://github.com/microsoft/BotFramework-WebChat/pull/2548): `useDisabled` + - PR [#2552](https://github.com/microsoft/BotFramework-WebChat/pull/2552): `useFocusSendBox`, `useScrollToEnd`, `useSendBoxValue`, `useSubmitSendBox`, `useTextBoxSubmit`, `useTextBoxValue` - Fixes [#2597](https://github.com/microsoft/BotFramework-WebChat/issues/2597). Modify `watch` script to `start` and add `tableflip` script for throwing `node_modules`, by [@corinagum](https://github.com/corinagum) in PR [#2598](https://github.com/microsoft/BotFramework-WebChat/pull/2598) ### Fixed diff --git a/__tests__/__image_snapshots__/chrome-docker/use-scroll-to-end-js-calling-scroll-to-end-should-scroll-to-end-1-snap.png b/__tests__/__image_snapshots__/chrome-docker/use-scroll-to-end-js-calling-scroll-to-end-should-scroll-to-end-1-snap.png new file mode 100644 index 0000000000..590e734502 Binary files /dev/null and b/__tests__/__image_snapshots__/chrome-docker/use-scroll-to-end-js-calling-scroll-to-end-should-scroll-to-end-1-snap.png differ diff --git a/__tests__/__image_snapshots__/chrome-docker/use-scroll-to-end-js-calling-scroll-to-end-should-scroll-to-end-2-snap.png b/__tests__/__image_snapshots__/chrome-docker/use-scroll-to-end-js-calling-scroll-to-end-should-scroll-to-end-2-snap.png new file mode 100644 index 0000000000..1fa1739fd7 Binary files /dev/null and b/__tests__/__image_snapshots__/chrome-docker/use-scroll-to-end-js-calling-scroll-to-end-should-scroll-to-end-2-snap.png differ diff --git a/__tests__/__image_snapshots__/chrome-docker/use-submit-send-box-js-calling-submit-send-box-should-send-the-message-in-send-box-1-snap.png b/__tests__/__image_snapshots__/chrome-docker/use-submit-send-box-js-calling-submit-send-box-should-send-the-message-in-send-box-1-snap.png new file mode 100644 index 0000000000..0461587e99 Binary files /dev/null and b/__tests__/__image_snapshots__/chrome-docker/use-submit-send-box-js-calling-submit-send-box-should-send-the-message-in-send-box-1-snap.png differ diff --git a/__tests__/hooks/useFocusSendBox.js b/__tests__/hooks/useFocusSendBox.js new file mode 100644 index 0000000000..3f3eb32317 --- /dev/null +++ b/__tests__/hooks/useFocusSendBox.js @@ -0,0 +1,19 @@ +import { timeouts } from '../constants.json'; + +import sendBoxTextBoxFocused from '../setup/conditions/sendBoxTextBoxFocused'; +import uiConnected from '../setup/conditions/uiConnected'; + +// selenium-webdriver API doc: +// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html + +jest.setTimeout(timeouts.test); + +test('calling emitTypingIndicator should send a typing activity', async () => { + const { driver, pageObjects } = await setupWebDriver(); + + await driver.wait(uiConnected(), timeouts.directLine); + + await pageObjects.runHook('useFocusSendBox', [], fn => fn()); + + await driver.wait(sendBoxTextBoxFocused(), timeouts.ui); +}); diff --git a/__tests__/hooks/useScrollToEnd.js b/__tests__/hooks/useScrollToEnd.js new file mode 100644 index 0000000000..0fd74f2a4c --- /dev/null +++ b/__tests__/hooks/useScrollToEnd.js @@ -0,0 +1,34 @@ +import { imageSnapshotOptions, timeouts } from '../constants.json'; + +import minNumActivitiesShown from '../setup/conditions/minNumActivitiesShown'; +import scrollToBottomButtonVisible from '../setup/conditions/scrollToBottomButtonVisible'; +import scrollToBottomCompleted from '../setup/conditions/scrollToBottomCompleted'; +import uiConnected from '../setup/conditions/uiConnected'; + +// selenium-webdriver API doc: +// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html + +jest.setTimeout(timeouts.test); + +test('calling scrollToEnd should scroll to end', async () => { + const { driver, pageObjects } = await setupWebDriver(); + + await driver.wait(uiConnected(), timeouts.directLine); + + await pageObjects.sendMessageViaSendBox('help'); + await driver.wait(minNumActivitiesShown(2), timeouts.directLine); + await driver.wait(scrollToBottomCompleted(), timeouts.scrollToBottom); + + await driver.executeScript(() => { + document.querySelector('[role="log"] > *').scrollTop = 0; + }); + + await driver.wait(scrollToBottomButtonVisible(), timeouts.ui); + + expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions); + + await pageObjects.runHook('useScrollToEnd', [], scrollToEnd => scrollToEnd()); + await driver.wait(scrollToBottomCompleted(), timeouts.scrollToBottom); + + expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions); +}); diff --git a/__tests__/hooks/useSendBoxValue.js b/__tests__/hooks/useSendBoxValue.js new file mode 100644 index 0000000000..0ab161c23f --- /dev/null +++ b/__tests__/hooks/useSendBoxValue.js @@ -0,0 +1,26 @@ +import { timeouts } from '../constants.json'; + +import uiConnected from '../setup/conditions/uiConnected'; + +// selenium-webdriver API doc: +// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html + +jest.setTimeout(timeouts.test); + +test('getter should get the send box text', async () => { + const { driver, pageObjects } = await setupWebDriver(); + + await driver.wait(uiConnected(), timeouts.directLine); + + await pageObjects.typeOnSendBox('Hello, World!'); + await expect(pageObjects.runHook('useSendBoxValue', [], result => result[0])).resolves.toBe('Hello, World!'); +}); + +test('setter should set the send box text', async () => { + const { driver, pageObjects } = await setupWebDriver(); + + await driver.wait(uiConnected(), timeouts.directLine); + + await pageObjects.runHook('useSendBoxValue', [], result => result[1]('Hello, World!')); + await expect(pageObjects.getSendBoxText()).resolves.toBe('Hello, World!'); +}); diff --git a/__tests__/hooks/useSubmitSendBox.js b/__tests__/hooks/useSubmitSendBox.js new file mode 100644 index 0000000000..d6a8255c28 --- /dev/null +++ b/__tests__/hooks/useSubmitSendBox.js @@ -0,0 +1,24 @@ +import { imageSnapshotOptions, timeouts } from '../constants.json'; + +import minNumActivitiesShown from '../setup/conditions/minNumActivitiesShown'; +import uiConnected from '../setup/conditions/uiConnected'; + +// selenium-webdriver API doc: +// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html + +jest.setTimeout(timeouts.test); + +test('calling submitSendBox should send the message in send box', async () => { + const { driver, pageObjects } = await setupWebDriver(); + + await driver.wait(uiConnected(), timeouts.directLine); + + await pageObjects.typeOnSendBox('Hello, World!'); + await pageObjects.runHook('useSubmitSendBox', [], submitSendBox => submitSendBox()); + + await driver.wait(minNumActivitiesShown(2), timeouts.directLine); + + const base64PNG = await driver.takeScreenshot(); + + expect(base64PNG).toMatchImageSnapshot(imageSnapshotOptions); +}); diff --git a/__tests__/hooks/useTextBox.js b/__tests__/hooks/useTextBox.js new file mode 100644 index 0000000000..2873052478 --- /dev/null +++ b/__tests__/hooks/useTextBox.js @@ -0,0 +1,29 @@ +import { imageSnapshotOptions, timeouts } from '../constants.json'; + +import minNumActivitiesShown from '../setup/conditions/minNumActivitiesShown'; +import scrollToBottomCompleted from '../setup/conditions/scrollToBottomCompleted'; +import uiConnected from '../setup/conditions/uiConnected'; + +// selenium-webdriver API doc: +// https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html + +jest.setTimeout(timeouts.test); + +// TODO: [P1] Test is temporarily disable until fully implemented +test('calling submit should scroll to end', async () => { + // const { driver, pageObjects } = await setupWebDriver(); + // await driver.wait(uiConnected(), timeouts.directLine); + // await pageObjects.typeOnSendBox('help'); + // await expect(pageObjects.runHook('useTextBoxValue', [], textBoxValue => textBoxValue[0])).resolves.toBe('help'); + // await pageObjects.clickSendButton(); + // await driver.wait(minNumActivitiesShown(2), timeouts.directLine); + // await driver.wait(scrollToBottomCompleted(), timeouts.scrollToBottom); + // await driver.executeScript(() => { + // document.querySelector('[role="log"] > *').scrollTop = 0; + // }); + // expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions); + // await pageObjects.runHook('useTextBoxValue', [], textBoxValue => textBoxValue[1]('Hello, World!')); + // await pageObjects.runHook('useTextBoxSubmit', [], textBoxSubmit => textBoxSubmit()); + // await driver.wait(scrollToBottomCompleted(), timeouts.scrollToBottom); + // expect(await driver.takeScreenshot()).toMatchImageSnapshot(imageSnapshotOptions); +}); diff --git a/packages/component/src/Activity/ScrollToEndButton.js b/packages/component/src/Activity/ScrollToEndButton.js index c1130eab69..ce85b40d7d 100644 --- a/packages/component/src/Activity/ScrollToEndButton.js +++ b/packages/component/src/Activity/ScrollToEndButton.js @@ -4,12 +4,13 @@ import classNames from 'classnames'; import PropTypes from 'prop-types'; import React from 'react'; -import connectToWebChat from '../connectToWebChat'; import Localize from '../Localization/Localize'; +import useScrollToEnd from '../hooks/useScrollToEnd'; import useStyleSet from '../hooks/useStyleSet'; -const ScrollToEndButton = ({ className, scrollToEnd }) => { +const ScrollToEndButton = ({ className }) => { const [{ scrollToEndButton: scrollToEndButtonStyleSet }] = useStyleSet(); + const scrollToEnd = useScrollToEnd(); return (