|
| 1 | +<!doctype html> |
| 2 | +<html lang="en-US"> |
| 3 | + |
| 4 | +<head> |
| 5 | + <link href="/assets/index.css" rel="stylesheet" type="text/css" /> |
| 6 | + <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script> |
| 7 | + <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.development.js"></script> |
| 8 | + <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.development.js"></script> |
| 9 | + <script crossorigin="anonymous" src="/test-harness.js"></script> |
| 10 | + <script crossorigin="anonymous" src="/test-page-object.js"></script> |
| 11 | + <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> |
| 12 | +</head> |
| 13 | + |
| 14 | +<body> |
| 15 | + <main id="webchat"></main> |
| 16 | + <script> |
| 17 | + const { |
| 18 | + React: { useMemo }, |
| 19 | + WebChat: { |
| 20 | + hooks: { useDirection } |
| 21 | + } |
| 22 | + } = window; |
| 23 | + |
| 24 | + run(async function () { |
| 25 | + const { directLine, store } = testHelpers.createDirectLineEmulator(); |
| 26 | + |
| 27 | + renderWebChat( |
| 28 | + { |
| 29 | + directLine, |
| 30 | + store, |
| 31 | + }, |
| 32 | + document.getElementById('webchat') |
| 33 | + ); |
| 34 | + |
| 35 | + await pageConditions.uiConnected(); |
| 36 | + |
| 37 | + await directLine.emulateIncomingActivity({ |
| 38 | + from: { |
| 39 | + role: "bot" |
| 40 | + }, |
| 41 | + id: "a-00002", |
| 42 | + timestamp: 0, |
| 43 | + type: "message", |
| 44 | + attachments: [ |
| 45 | + { |
| 46 | + contentType: 'application/vnd.microsoft.card.adaptive', |
| 47 | + content: { |
| 48 | + type: 'AdaptiveCard', |
| 49 | + body: [ |
| 50 | + { |
| 51 | + type: 'TextBlock', |
| 52 | + text: 'This is the initial message', |
| 53 | + wrap: true |
| 54 | + } |
| 55 | + ], |
| 56 | + actions: [ |
| 57 | + { |
| 58 | + type: 'Action.Submit', |
| 59 | + title: 'Submit card' |
| 60 | + } |
| 61 | + ], |
| 62 | + $schema: 'http://adaptivecards.io/schemas/adaptive-card.json', |
| 63 | + version: '1.0' |
| 64 | + } |
| 65 | + } |
| 66 | + ] |
| 67 | + }); |
| 68 | + |
| 69 | + const adaptiveCardEl = document.querySelector('.webchat__adaptive-card-renderer'); |
| 70 | + const [currentRenderedChild] = adaptiveCardEl.children; |
| 71 | + |
| 72 | + await new Promise(resolve => setTimeout(resolve, 200)); |
| 73 | + |
| 74 | + let observedMutations |
| 75 | + new MutationObserver((mutations) => { |
| 76 | + observedMutations = mutations; |
| 77 | + }).observe(adaptiveCardEl, { childList: true }); |
| 78 | + |
| 79 | + // WHEN: we receive a new activity with the same ID |
| 80 | + await directLine.emulateIncomingActivity({ |
| 81 | + from: { |
| 82 | + role: "bot" |
| 83 | + }, |
| 84 | + id: "a-00002", |
| 85 | + timestamp: 0, |
| 86 | + type: "message", |
| 87 | + attachments: [ |
| 88 | + { |
| 89 | + contentType: 'application/vnd.microsoft.card.adaptive', |
| 90 | + content: { |
| 91 | + type: 'AdaptiveCard', |
| 92 | + body: [ |
| 93 | + { |
| 94 | + type: 'TextBlock', |
| 95 | + text: 'This is the message', |
| 96 | + wrap: true |
| 97 | + } |
| 98 | + ], |
| 99 | + actions: [ |
| 100 | + { |
| 101 | + type: 'Action.Submit', |
| 102 | + title: 'Submit card' |
| 103 | + } |
| 104 | + ], |
| 105 | + $schema: 'http://adaptivecards.io/schemas/adaptive-card.json', |
| 106 | + version: '1.0' |
| 107 | + } |
| 108 | + } |
| 109 | + ] |
| 110 | + }); |
| 111 | + |
| 112 | + // THEN: the Adaptive Card is re-rendered resulting in a single DOM mutation |
| 113 | + expect(observedMutations.length).toBe(1); |
| 114 | + expect(observedMutations.[0].type).toBe('childList'); |
| 115 | + expect(observedMutations.[0].addedNodes[0]).toBe(adaptiveCardEl.children[0]); |
| 116 | + expect(observedMutations.[0].removedNodes[0]).toBe(currentRenderedChild); |
| 117 | + |
| 118 | + await host.snapshot('local'); |
| 119 | + }); |
| 120 | + </script> |
| 121 | +</body> |
| 122 | + |
| 123 | +</html> |
0 commit comments