Skip to content

Commit d9c382d

Browse files
committed
Adding delay intercom test
Fix spelling
1 parent ef59f9d commit d9c382d

File tree

5 files changed

+83
-1
lines changed

5 files changed

+83
-1
lines changed

playground/app.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
ProviderEventsPage,
99
ProviderApiPage,
1010
UseIntercomTourPage,
11+
UseIntercomWithDelay
1112
} from './modules';
1213

1314
import { Page, Style } from './modules/common';
@@ -47,6 +48,7 @@ const App = () => {
4748
<Route path="/providerApi" component={ProviderApiPage} />
4849
<Route path="/useIntercom" component={UseIntercomPage} />
4950
<Route path="/useIntercomTour" component={UseIntercomTourPage} />
51+
<Route path="/useIntercomWithTimeout" component={UseIntercomWithDelay} />
5052
<Route path="/" exact>
5153
<Navigation>
5254
<Link to="/provider">
@@ -61,6 +63,9 @@ const App = () => {
6163
<Link to="/useIntercomTour">
6264
<code>useIntercom with tour</code>
6365
</Link>
66+
<Link to="/useIntercomWithTimeout">
67+
<code>useIntercom with delayed boot</code>
68+
</Link>
6469
</Navigation>
6570
</Route>
6671
</Router>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { default as UseIntercomPage } from './useIntercom';
22
export { default as UseIntercomTourPage } from './useIntercomTour';
3+
export { default as UseIntercomWithDelay } from './useIntercomWithDelay'
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as React from 'react';
2+
import styled from 'styled-components';
3+
4+
import { IntercomProvider, useIntercom } from '../../../.';
5+
6+
import { Button } from '../common';
7+
8+
const Grid = styled.div`
9+
display: grid;
10+
grid-template-columns: repeat(1, 1fr);
11+
width: 100%;
12+
`;
13+
14+
const Item = styled.div`
15+
display: grid;
16+
grid-template-rows: min-content;
17+
18+
&::after {
19+
content: '';
20+
margin: 2rem 0 1.5rem;
21+
border-bottom: 2px solid var(--grey);
22+
width: 100%;
23+
}
24+
`;
25+
26+
const RawUseIntercomPage = () => {
27+
const {
28+
boot,
29+
} = useIntercom();
30+
const handleBoot = React.useCallback(() => boot(), [boot]);
31+
32+
return (
33+
<Grid>
34+
<Item>
35+
<p>
36+
Intercom will be autobooted after 5000ms
37+
</p>
38+
</Item>
39+
</Grid>
40+
);
41+
};
42+
43+
const UseIntercomWithDelayPage = () => {
44+
return (
45+
<IntercomProvider appId="jcabc7e3" initializeDelay={5000} autoBoot>
46+
<RawUseIntercomPage />
47+
</IntercomProvider>
48+
);
49+
};
50+
51+
export default UseIntercomWithDelayPage;

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ export type IntercomProviderProps = {
420420
*/
421421
apiBase?: string;
422422
/**
423-
* Indicates if the intercom initialization should be delayed, dealy is in ms
423+
* Indicates if the intercom initialization should be delayed, delay is in ms
424424
*
425425
* @remarks If not set delay is set to 0ms
426426
* */

test/useIntercom.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,29 @@ describe('useIntercom', () => {
4444

4545
expect(window.intercomSettings).toEqual({ app_id: INTERCOM_APP_ID });
4646
});
47+
48+
test('should set wait for a certain amount of ms until booting, booting before that will do nothing', async () => {
49+
const { result, waitFor } = renderHook(() => useIntercom(), {
50+
wrapper: ({ children }) => (
51+
<IntercomProvider appId={INTERCOM_APP_ID} initializeDelay={5000}>{children}</IntercomProvider>
52+
),
53+
});
54+
55+
const { boot } = result.current;
56+
57+
act(() => {
58+
boot();
59+
});
60+
61+
expect(window.intercomSettings).toEqual({app_id: undefined});
62+
63+
await waitFor(() => {}, {timeout: 5000});
64+
65+
act(() => {
66+
boot();
67+
});
68+
69+
expect(window.intercomSettings).toEqual({ app_id: INTERCOM_APP_ID });
70+
71+
});
4772
});

0 commit comments

Comments
 (0)