|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-US"> |
| 3 | + <head> |
| 4 | + <link href="/assets/index.css" rel="stylesheet" type="text/css" /> |
| 5 | + </head> |
| 6 | + <body> |
| 7 | + <main id="webchat"></main> |
| 8 | + <script type="importmap"> |
| 9 | + { |
| 10 | + "imports": { |
| 11 | + "botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js", |
| 12 | + "react": "/__dist__/packages/bundle/static/react.js", |
| 13 | + "react-dom": "/__dist__/packages/bundle/static/react-dom.js" |
| 14 | + } |
| 15 | + } |
| 16 | + </script> |
| 17 | + <script type="module"> |
| 18 | + import '/test-harness.mjs'; |
| 19 | + import '/test-page-object.mjs'; |
| 20 | + |
| 21 | + import { createDirectLine, createStoreWithOptions, renderWebChat } from 'botframework-webchat'; |
| 22 | + import { version } from 'react'; |
| 23 | + |
| 24 | + run(async function () { |
| 25 | + const { |
| 26 | + testHelpers: { createDirectLineEmulator } |
| 27 | + } = window; |
| 28 | + |
| 29 | + // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. |
| 30 | + window.WebChat = { createStoreWithOptions }; |
| 31 | + |
| 32 | + const { directLine, store } = createDirectLineEmulator(); |
| 33 | + |
| 34 | + renderWebChat({ directLine, store }, document.getElementById('webchat')); |
| 35 | + |
| 36 | + await pageConditions.uiConnected(); |
| 37 | + |
| 38 | + await directLine.emulateIncomingActivity({ |
| 39 | + entities: [ |
| 40 | + { |
| 41 | + '@context': 'https://schema.org', |
| 42 | + '@id': '', |
| 43 | + '@type': 'Message', |
| 44 | + type: 'https://schema.org/Message', |
| 45 | + isPartOf: { '@id': 'c-00001', '@type': 'HowTo' }, |
| 46 | + position: 1 |
| 47 | + } |
| 48 | + ], |
| 49 | + from: { role: 'bot' }, |
| 50 | + id: 'a-00001', |
| 51 | + text: 'a-00001: Chain 1 thought 1 at t = 0', |
| 52 | + timestamp: new Date(0).toISOString(), |
| 53 | + type: 'message' |
| 54 | + }); |
| 55 | + |
| 56 | + expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([ |
| 57 | + 'a-00001: Chain 1 thought 1 at t = 0' |
| 58 | + ]); |
| 59 | + |
| 60 | + await host.snapshot('local'); |
| 61 | + |
| 62 | + // A "Hello, World!" inserted between two thoughts. |
| 63 | + await directLine.emulateIncomingActivity({ |
| 64 | + from: { role: 'bot' }, |
| 65 | + id: 'a-00002', |
| 66 | + text: 'a-00002: Hello, World at t = 1', |
| 67 | + timestamp: new Date(86_400_000).toISOString(), |
| 68 | + type: 'message' |
| 69 | + }); |
| 70 | + |
| 71 | + expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([ |
| 72 | + 'a-00001: Chain 1 thought 1 at t = 0', |
| 73 | + 'a-00002: Hello, World at t = 1' |
| 74 | + ]); |
| 75 | + |
| 76 | + await host.snapshot('local'); |
| 77 | + |
| 78 | + // The second thought should be grouped with the first one. |
| 79 | + await directLine.emulateIncomingActivity({ |
| 80 | + entities: [ |
| 81 | + { |
| 82 | + '@context': 'https://schema.org', |
| 83 | + '@id': '', |
| 84 | + '@type': 'Message', |
| 85 | + type: 'https://schema.org/Message', |
| 86 | + isPartOf: { '@id': 'c-00001', '@type': 'HowTo' }, |
| 87 | + position: 2 |
| 88 | + } |
| 89 | + ], |
| 90 | + from: { role: 'bot' }, |
| 91 | + id: 'a-00003', |
| 92 | + text: 'a-00003: Chain 1 thought 2 at t = 2', |
| 93 | + timestamp: new Date(2 * 86_400_000).toISOString(), |
| 94 | + type: 'message' |
| 95 | + }); |
| 96 | + |
| 97 | + expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([ |
| 98 | + 'a-00001: Chain 1 thought 1 at t = 0', |
| 99 | + 'a-00003: Chain 1 thought 2 at t = 2', |
| 100 | + 'a-00002: Hello, World at t = 1' |
| 101 | + ]); |
| 102 | + |
| 103 | + await host.snapshot('local'); |
| 104 | + |
| 105 | + await directLine.emulateIncomingActivity({ |
| 106 | + entities: [ |
| 107 | + { |
| 108 | + '@context': 'https://schema.org', |
| 109 | + '@id': '', |
| 110 | + '@type': 'Message', |
| 111 | + type: 'https://schema.org/Message', |
| 112 | + isPartOf: { '@id': 'c-00002', '@type': 'HowTo' }, |
| 113 | + position: 1 |
| 114 | + } |
| 115 | + ], |
| 116 | + from: { role: 'bot' }, |
| 117 | + id: 'a-00004', |
| 118 | + text: 'a-00004: Chain 2 thought 1 at t = 3', |
| 119 | + timestamp: new Date(3 * 86_400_000).toISOString(), |
| 120 | + type: 'message' |
| 121 | + }); |
| 122 | + |
| 123 | + expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([ |
| 124 | + 'a-00001: Chain 1 thought 1 at t = 0', |
| 125 | + 'a-00003: Chain 1 thought 2 at t = 2', |
| 126 | + 'a-00002: Hello, World at t = 1', |
| 127 | + 'a-00004: Chain 2 thought 1 at t = 3' |
| 128 | + ]); |
| 129 | + |
| 130 | + await host.snapshot('local'); |
| 131 | + |
| 132 | + await directLine.emulateIncomingActivity({ |
| 133 | + entities: [ |
| 134 | + { |
| 135 | + '@context': 'https://schema.org', |
| 136 | + '@id': '', |
| 137 | + '@type': 'Message', |
| 138 | + type: 'https://schema.org/Message', |
| 139 | + isPartOf: { '@id': 'c-00002', '@type': 'HowTo' }, |
| 140 | + position: 2 |
| 141 | + } |
| 142 | + ], |
| 143 | + from: { role: 'bot' }, |
| 144 | + id: 'a-00005', |
| 145 | + text: 'a-00005: Chain 2 thought 2 at t = 0', |
| 146 | + // Intentionally roll back the date. |
| 147 | + // It should be grouped and not appear before "Hello, World!' |
| 148 | + timestamp: new Date(0).toISOString(), |
| 149 | + type: 'message' |
| 150 | + }); |
| 151 | + |
| 152 | + expect(pageElements.activityContents().map(({ textContent }) => textContent)).toEqual([ |
| 153 | + 'a-00001: Chain 1 thought 1 at t = 0', |
| 154 | + 'a-00003: Chain 1 thought 2 at t = 2', |
| 155 | + 'a-00002: Hello, World at t = 1', |
| 156 | + 'a-00004: Chain 2 thought 1 at t = 3', |
| 157 | + 'a-00005: Chain 2 thought 2 at t = 0' |
| 158 | + ]); |
| 159 | + |
| 160 | + await host.snapshot('local'); |
| 161 | + }); |
| 162 | + </script> |
| 163 | + </body> |
| 164 | +</html> |
0 commit comments