|
| 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=" https://unpkg.com/@babel/[email protected]/babel.min.js" ></script> |
| 6 | + <script src=" https://unpkg.com/[email protected]/dist/preact.umd.js" ></script> |
| 7 | + <script src=" https://unpkg.com/[email protected]/hooks/dist/hooks.umd.js" ></script> |
| 8 | + <script src=" https://unpkg.com/[email protected]/compat/dist/compat.umd.js" ></script> |
| 9 | + <script> |
| 10 | + // Expose Preact's compat as React for WebChat |
| 11 | + window.React = preactCompat; |
| 12 | + window.ReactDOM = preactCompat; |
| 13 | + </script> |
| 14 | + <script crossorigin="anonymous" src="/test-harness.js"></script> |
| 15 | + <script crossorigin="anonymous" src="/test-page-object.js"></script> |
| 16 | + <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> |
| 17 | + </head> |
| 18 | + <body> |
| 19 | + <main id="webchat"></main> |
| 20 | + <script type="text/babel"> |
| 21 | + run(async function () { |
| 22 | + const { |
| 23 | + React, |
| 24 | + ReactDOM: { render }, |
| 25 | + WebChat: { ReactWebChat } |
| 26 | + } = window; // Imports in UMD fashion. |
| 27 | + |
| 28 | + const aiMessageEntity = { |
| 29 | + '@context': 'https://schema.org', |
| 30 | + '@id': '', |
| 31 | + '@type': 'Message', |
| 32 | + keywords: ['AIGeneratedContent', 'AllowCopy'], |
| 33 | + type: 'https://schema.org/Message' |
| 34 | + }; |
| 35 | + |
| 36 | + const waveSvg = `data:image/svg+xml;utf8,${encodeURIComponent(` |
| 37 | +<svg width="400" height="200" viewBox="0 0 400 200" xmlns="http://www.w3.org/2000/svg"> |
| 38 | + <!-- Primary Wave --> |
| 39 | + <path d="M0,100 C50,50 100,150 150,100 C200,50 250,150 300,100 C350,50 400,150 400,100" |
| 40 | + stroke="#3B82F6" fill="none" stroke-width="2" opacity="0.5"/> |
| 41 | +
|
| 42 | + <!-- Second Harmonic --> |
| 43 | + <path d="M0,100 C25,75 50,125 75,100 C100,75 125,125 150,100 C175,75 200,125 225,100 C250,75 275,125 300,100 C325,75 350,125 375,100 C400,75 400,125 400,100" |
| 44 | + stroke="#10B981" fill="none" stroke-width="2" opacity="0.5"/> |
| 45 | +
|
| 46 | + <!-- Combined Wave --> |
| 47 | + <path d="M0,100 C40,30 80,170 120,100 C160,30 200,170 240,100 C280,30 320,170 360,100 C380,65 400,135 400,100" |
| 48 | + stroke="#EF4444" fill="none" stroke-width="3"/> |
| 49 | +
|
| 50 | + <!-- Grid Lines --> |
| 51 | + <line x1="0" y1="100" x2="400" y2="100" stroke="#CBD5E1" stroke-width="0.5" stroke-dasharray="4"/> |
| 52 | + <line x1="100" y1="0" x2="100" y2="200" stroke="#CBD5E1" stroke-width="0.5" stroke-dasharray="4"/> |
| 53 | + <line x1="200" y1="0" x2="200" y2="200" stroke="#CBD5E1" stroke-width="0.5" stroke-dasharray="4"/> |
| 54 | + <line x1="300" y1="0" x2="300" y2="200" stroke="#CBD5E1" stroke-width="0.5" stroke-dasharray="4"/> |
| 55 | +</svg>`)}`; |
| 56 | + |
| 57 | + const { directLine, store } = testHelpers.createDirectLineEmulator(); |
| 58 | + |
| 59 | + render( |
| 60 | + <ReactWebChat directLine={directLine} store={store} />, |
| 61 | + document.getElementById('webchat') |
| 62 | + ); |
| 63 | + |
| 64 | + await pageConditions.uiConnected(); |
| 65 | + |
| 66 | + directLine.emulateIncomingActivity({ |
| 67 | + from: { role: 'bot' }, |
| 68 | + entities: [{ |
| 69 | + ...aiMessageEntity, |
| 70 | + isBasedOn: { |
| 71 | + '@type': 'SoftwareSourceCode', |
| 72 | + 'programmingLanguage': 'python', |
| 73 | + "text": `import numpy as np |
| 74 | +import matplotlib.pyplot as plt |
| 75 | +
|
| 76 | +def plot_sine_waves(): |
| 77 | + """Create a beautiful visualization of sine waves with different frequencies.""" |
| 78 | + # Generate time points |
| 79 | + t = np.linspace(0, 10, 1000) |
| 80 | +
|
| 81 | + # Create waves with different frequencies and phases |
| 82 | + wave1 = np.sin(t) |
| 83 | + wave2 = 0.5 * np.sin(2 * t + np.pi/4) |
| 84 | + wave3 = 0.3 * np.sin(3 * t + np.pi/3) |
| 85 | +
|
| 86 | + # Combine waves |
| 87 | + combined = wave1 + wave2 + wave3 |
| 88 | +
|
| 89 | + # Create a stylish plot |
| 90 | + plt.style.use('seaborn-darkgrid') |
| 91 | + plt.figure(figsize=(12, 8)) |
| 92 | +
|
| 93 | + # Plot individual waves |
| 94 | + plt.plot(t, wave1, label='Primary Wave', alpha=0.5) |
| 95 | + plt.plot(t, wave2, label='Second Harmonic', alpha=0.5) |
| 96 | + plt.plot(t, wave3, label='Third Harmonic', alpha=0.5) |
| 97 | +
|
| 98 | + # Plot combined wave with a thicker line |
| 99 | + plt.plot(t, combined, 'r-', |
| 100 | + label='Combined Wave', |
| 101 | + linewidth=2) |
| 102 | +
|
| 103 | + plt.title('Harmonic Wave Composition', fontsize=14) |
| 104 | + plt.xlabel('Time', fontsize=12) |
| 105 | + plt.ylabel('Amplitude', fontsize=12) |
| 106 | + plt.legend() |
| 107 | + plt.grid(True, alpha=0.3) |
| 108 | +
|
| 109 | + # Show the plot |
| 110 | + plt.tight_layout() |
| 111 | + plt.show() |
| 112 | +
|
| 113 | +# Generate the visualization |
| 114 | +plot_sine_waves()` |
| 115 | + } |
| 116 | + }], |
| 117 | + type: "message", |
| 118 | + text: `This example demonstrates creating a beautiful visualization of harmonic waves using Python's Matplotlib library. The code generates three sine waves with different frequencies and phases, then combines them to show wave interference patterns.\n<img alt="wave plot" src="${waveSvg}">`, |
| 119 | + }); |
| 120 | + |
| 121 | + await pageConditions.numActivitiesShown(1); |
| 122 | + |
| 123 | + // When: Focus the "Code" button |
| 124 | + const codeButton = document.querySelector(`[data-testid="${WebChat.testIds.viewCodeButton}"]`); |
| 125 | + codeButton.focus(); |
| 126 | + |
| 127 | + // Then: Shows a focus ring around the "Code" button |
| 128 | + expect(document.activeElement).toBe(codeButton); |
| 129 | + await host.snapshot('local'); |
| 130 | + |
| 131 | + // WHEN: Press ENTER on the "Code" button. |
| 132 | + await host.sendKeys('ENTER'); |
| 133 | + |
| 134 | + // THEN: The code dialog should open. |
| 135 | + await host.snapshot('local'); |
| 136 | + |
| 137 | + // WHEN: Press ENTER to close the View Code dialog. |
| 138 | + await host.sendKeys('ENTER'); |
| 139 | + |
| 140 | + // // THEN: The code dialog should close. |
| 141 | + await host.snapshot('local'); |
| 142 | + }); |
| 143 | + </script> |
| 144 | + </body> |
| 145 | +</html> |
0 commit comments