File tree Expand file tree Collapse file tree 5 files changed +83
-1
lines changed Expand file tree Collapse file tree 5 files changed +83
-1
lines changed Original file line number Diff line number Diff line change 8
8
ProviderEventsPage ,
9
9
ProviderApiPage ,
10
10
UseIntercomTourPage ,
11
+ UseIntercomWithDelay
11
12
} from './modules' ;
12
13
13
14
import { Page , Style } from './modules/common' ;
@@ -47,6 +48,7 @@ const App = () => {
47
48
< Route path = "/providerApi" component = { ProviderApiPage } />
48
49
< Route path = "/useIntercom" component = { UseIntercomPage } />
49
50
< Route path = "/useIntercomTour" component = { UseIntercomTourPage } />
51
+ < Route path = "/useIntercomWithTimeout" component = { UseIntercomWithDelay } />
50
52
< Route path = "/" exact >
51
53
< Navigation >
52
54
< Link to = "/provider" >
@@ -61,6 +63,9 @@ const App = () => {
61
63
< Link to = "/useIntercomTour" >
62
64
< code > useIntercom with tour</ code >
63
65
</ Link >
66
+ < Link to = "/useIntercomWithTimeout" >
67
+ < code > useIntercom with delayed boot</ code >
68
+ </ Link >
64
69
</ Navigation >
65
70
</ Route >
66
71
</ Router >
Original file line number Diff line number Diff line change 1
1
export { default as UseIntercomPage } from './useIntercom' ;
2
2
export { default as UseIntercomTourPage } from './useIntercomTour' ;
3
+ export { default as UseIntercomWithDelay } from './useIntercomWithDelay'
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change @@ -420,7 +420,7 @@ export type IntercomProviderProps = {
420
420
*/
421
421
apiBase ?: string ;
422
422
/**
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
424
424
*
425
425
* @remarks If not set delay is set to 0ms
426
426
* */
Original file line number Diff line number Diff line change @@ -44,4 +44,29 @@ describe('useIntercom', () => {
44
44
45
45
expect ( window . intercomSettings ) . toEqual ( { app_id : INTERCOM_APP_ID } ) ;
46
46
} ) ;
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
+ } ) ;
47
72
} ) ;
You can’t perform that action at this time.
0 commit comments