-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathsaga.clearSuggestedActionsOnPostActivity.html
More file actions
100 lines (88 loc) · 3.33 KB
/
saga.clearSuggestedActionsOnPostActivity.html
File metadata and controls
100 lines (88 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.development.js"></script>
<script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.development.js"></script>
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
</head>
<body>
<main id="webchat"></main>
<script type="importmap">
{
"imports": {
"@testduet/wait-for": "https://unpkg.com/@testduet/wait-for@main/dist/wait-for.mjs"
}
}
</script>
<script type="module">
import { waitFor } from '@testduet/wait-for';
import renderHook from '../../hooks/private/renderHook.js';
const {
React: { createElement },
testHelpers: { createDirectLineEmulator },
WebChat: {
Components: { BasicWebChat, Composer },
hooks: { useSuggestedActions },
testIds
}
} = window;
run(async function () {
const { directLine, store } = createDirectLineEmulator();
const WebChatWrapper = ({ children }) =>
createElement(Composer, { directLine, store }, createElement(BasicWebChat), children);
// WHEN: Render initially.
const renderResult = renderHook(
props => {
const state = useSuggestedActions();
if (props) {
state[1](props.suggestedActions);
} else {
return state;
}
},
{
legacyRoot: true,
wrapper: WebChatWrapper
}
);
await pageConditions.uiConnected();
// THEN: useSuggestedActions() getter should return empty array.
await waitFor(() =>
expect(renderResult).toHaveProperty('result.current', [[], expect.anything(), { activity: undefined }])
);
// WHEN: An activity with 2 suggested actions is received.
await directLine.emulateIncomingActivity({
from: { role: 'bot' },
suggestedActions: {
actions: [
{ title: 'Hello, World!', type: 'imBack' },
{ title: 'Aloha!', type: 'imBack' }
],
to: ''
},
text: 'Hello, World!',
type: 'message'
});
// WHEN: A message is being sent.
pageElements.byTestId(testIds.sendBoxTextBox).focus();
await (
await directLine.actPostActivity(async () => {
await host.sendKeys('Good morning!', 'ENTER');
})
).resolveAll();
// THEN: UI should hide suggested actions.
await waitFor(() => expect(pageElements.allByTestId(testIds.suggestedActionButton)).toHaveLength(0));
// THEN: useSuggestedActions() should return no suggested actions.
renderResult.rerender();
await waitFor(() =>
expect(renderResult).toHaveProperty('result.current', [[], expect.any(Function), { activity: undefined }])
);
// THEN: getState() should have no suggested actions.
expect(store.getState().suggestedActions).toHaveLength(0);
});
</script>
</body>
</html>