|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-US"> |
| 3 | + <head> |
| 4 | + <link href="/assets/index.css" rel="stylesheet" type="text/css" /> |
| 5 | + <script crossorigin="anonymous" src="/test-harness.js"></script> |
| 6 | + <script crossorigin="anonymous" src="/test-page-object.js"></script> |
| 7 | + <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> |
| 8 | + <script type="importmap"> |
| 9 | + { |
| 10 | + "imports": { |
| 11 | + "jest-mock": "https://esm.sh/jest-mock" |
| 12 | + } |
| 13 | + } |
| 14 | + </script> |
| 15 | + </head> |
| 16 | + <body> |
| 17 | + <main id="webchat"></main> |
| 18 | + <script type="module"> |
| 19 | + import { fn, spyOn } from 'jest-mock'; |
| 20 | + |
| 21 | + run(async function () { |
| 22 | + const { |
| 23 | + testHelpers: { createDirectLineEmulator } |
| 24 | + } = window; |
| 25 | + |
| 26 | + const { directLine, store } = createDirectLineEmulator(); |
| 27 | + |
| 28 | + const timeline = []; |
| 29 | + |
| 30 | + const originalRequestIdleCallback = window.requestIdleCallback; |
| 31 | + |
| 32 | + const requestIdleCallback = spyOn(window, 'requestIdleCallback').mockImplementation(callback => { |
| 33 | + timeline.push('requestIdleCallback()'); |
| 34 | + originalRequestIdleCallback.call(window, callback); |
| 35 | + }); |
| 36 | + |
| 37 | + WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat')); |
| 38 | + |
| 39 | + await pageConditions.uiConnected(); |
| 40 | + |
| 41 | + await directLine.actPostActivity(async () => { |
| 42 | + const sendBoxTextBox = pageElements.sendBoxTextBox(); |
| 43 | + |
| 44 | + const originalFocus = sendBoxTextBox.focus; |
| 45 | + const originalSetAttribute = sendBoxTextBox.setAttribute; |
| 46 | + |
| 47 | + const focus = spyOn(sendBoxTextBox, 'focus').mockImplementation(() => { |
| 48 | + timeline.push('focus()'); |
| 49 | + originalFocus.call(sendBoxTextBox); |
| 50 | + }); |
| 51 | + |
| 52 | + const setAttribute = spyOn(sendBoxTextBox, 'setAttribute').mockImplementation((name, value) => { |
| 53 | + timeline.push(`setAttribute(${JSON.stringify(name)}, ${JSON.stringify(value)})`); |
| 54 | + originalSetAttribute.call(sendBoxTextBox, name, value); |
| 55 | + }); |
| 56 | + |
| 57 | + await host.click(pageElements.sendBoxTextBox()); |
| 58 | + await host.sendKeys('Hello, World!'); |
| 59 | + |
| 60 | + // WHEN: Click on the send button. |
| 61 | + await host.click(pageElements.sendButton()); |
| 62 | + |
| 63 | + expect(timeline).toEqual([ |
| 64 | + 'setAttribute(\"inputmode\", \"text\")', // THEN: `setAttribute()` is called when click on the text box. |
| 65 | + 'setAttribute(\"inputmode\", \"none\")', // THEN: Tap on the send button should hide the virtual keyboard. |
| 66 | + 'requestIdleCallback()', // THEN: Make sure there is a pause between `setAttribute()` and `focus()` |
| 67 | + 'focus()' // THEN: Should focus on the send box. |
| 68 | + ]); |
| 69 | + |
| 70 | + expect(document.activeElement).toBe(sendBoxTextBox); |
| 71 | + }); |
| 72 | + }); |
| 73 | + </script> |
| 74 | + </body> |
| 75 | +</html> |
0 commit comments