Skip to content

Commit 982d145

Browse files
committed
Upgrade tests
1 parent 3b66bdc commit 982d145

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

__tests__/html/hooks.useActiveTyping.variable.html renamed to __tests__/html2/hooks/useActiveTyping.variable.html

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
<main id="webchat"></main>
1414
<script type="text/babel" data-presets="env,stage-3,react">
1515
const {
16+
testHelpers: { createDirectLineEmulator },
1617
WebChat: {
1718
Components: { BasicWebChat, Composer },
1819
hooks: { useActiveTyping }
1920
}
2021
} = window;
2122

2223
run(async function () {
23-
const clock = lolex.createClock();
24-
25-
const directLine = WebChat.createDirectLine({ token: await testHelpers.token.fetchDirectLineToken() });
26-
const store = testHelpers.createStoreWithOptions({ ponyfill: clock });
24+
const ponyfill = lolex.createClock();
25+
const { directLine, store } = createDirectLineEmulator({ ponyfill });
2726

2827
const RunFunction = ({ fn }) => {
2928
fn();
@@ -34,7 +33,7 @@
3433
const renderWithFunction = fn =>
3534
new Promise(resolve =>
3635
ReactDOM.render(
37-
<Composer directLine={directLine} ponyfill={clock} sendTypingIndicator={true} store={store}>
36+
<Composer directLine={directLine} ponyfill={ponyfill} sendTypingIndicator={true} store={store}>
3837
<BasicWebChat />
3938
<RunFunction fn={() => resolve(fn && fn())} key={Date.now() + ''} />
4039
</Composer>,
@@ -46,7 +45,7 @@
4645

4746
await pageConditions.webChatRendered();
4847

49-
clock.tick(600);
48+
ponyfill.tick(600);
5049

5150
// WHEN: At initial.
5251
await pageConditions.uiConnected();
@@ -55,7 +54,7 @@
5554
await expect(renderWithFunction(() => useActiveTyping())).resolves.toEqual([{}]);
5655

5756
// WHEN: Type "a" without send.
58-
await pageObjects.typeInSendBox('a');
57+
await directLine.actPostActivity(() => pageObjects.typeInSendBox('a'));
5958

6059
// THEN: `useActiveTyping` should return current user.
6160
await expect(renderWithFunction(() => Object.values(useActiveTyping()[0]))).resolves.toEqual([
@@ -69,7 +68,7 @@
6968
]);
7069

7170
// WHEN: Type "b" at t=10.
72-
clock.tick(10);
71+
ponyfill.tick(10);
7372
await pageObjects.typeInSendBox('b');
7473

7574
// We need to wait for 6000 ms because:
@@ -78,10 +77,7 @@
7877
// 3. t=10: Typed letter "b"
7978
// 4. t=10: Scheduled another typing indicator at t=3000
8079
// 5. t=3000: Send typing activity
81-
clock.tick(3000);
82-
83-
// TODO: Understand why we need to yield after clock.tick and see if we could eliminate it.
84-
await 0;
80+
await directLine.actPostActivity(() => ponyfill.tick(3000));
8581

8682
// THEN: `useActiveTyping` should return current user.
8783
await expect(renderWithFunction(() => Object.values(useActiveTyping()[0]))).resolves.toEqual([
@@ -95,7 +91,7 @@
9591
]);
9692

9793
// WHEN: After 8 seconds.
98-
clock.tick(8000);
94+
ponyfill.tick(8000);
9995

10096
// THEN: `useActiveTyping` should return nothing.
10197
await expect(renderWithFunction(() => useActiveTyping())).resolves.toEqual([{}]);

0 commit comments

Comments
 (0)