1
- // eslint-disable-next-line import/order -- This is a test file and we need to import the mocks first
2
- import { mockStore } from '../../../utils/test-mocks' ;
1
+ jest . mock ( '@automattic/jetpack-connection' , ( ) => ( {
2
+ useConnection : jest . fn ( ) ,
3
+ useConnectionErrorNotice : jest . fn ( ( ) => ( { hasConnectionError : false } ) ) ,
4
+ } ) ) ;
5
+
3
6
import { useConnection } from '@automattic/jetpack-connection' ;
4
- import { isJetpackSelfHostedSite , siteHasFeature } from '@automattic/jetpack-script-data' ;
5
7
import { render , screen } from '@testing-library/react' ;
6
8
import { SocialAdminPage } from '../' ;
7
- import { getSocialScriptData } from '../../../utils' ;
8
-
9
- // Mock child components to simplify testing - We only test the SocialAdminPage component here
10
- jest . mock ( '../connection-screen' , ( ) => ( ) => < div data-testid = "connection-screen" /> ) ;
11
- jest . mock ( '../header' , ( ) => ( ) => < div data-testid = "header" /> ) ;
12
- jest . mock ( '../info-section' , ( ) => ( ) => < div data-testid = "info-section" /> ) ;
13
- jest . mock ( '../page-header' , ( ) => ( ) => < div data-testid = "page-header" /> ) ;
14
- jest . mock ( '../pricing-page' , ( ) => ( { onDismiss } ) => (
15
- < button data-testid = "pricing-page" onClick = { onDismiss } onKeyDown = { onDismiss } />
16
- ) ) ;
17
- jest . mock ( '../support-section' , ( ) => ( ) => < div data-testid = "support-section" /> ) ;
18
- jest . mock ( '../toggles/social-image-generator-toggle' , ( ) => ( ) => (
19
- < div data-testid = "social-image-generator-toggle" />
20
- ) ) ;
21
- jest . mock ( '../toggles/social-module-toggle' , ( ) => ( ) => (
22
- < div data-testid = "social-module-toggle" />
23
- ) ) ;
24
- jest . mock ( '../toggles/social-notes-toggle' , ( ) => ( ) => (
25
- < div data-testid = "social-notes-toggle" />
26
- ) ) ;
27
- jest . mock ( '../toggles/utm-toggle' , ( ) => ( ) => < div data-testid = "utm-toggle" /> ) ;
9
+ import { clearMockedScriptData , mockScriptData } from '../../../utils/test-utils' ;
28
10
29
11
describe ( 'SocialAdminPage' , ( ) => {
30
12
beforeEach ( ( ) => {
31
13
jest . clearAllMocks ( ) ;
32
- mockStore ( ) ;
33
14
useConnection . mockReturnValue ( {
34
15
isUserConnected : true ,
35
16
isRegistered : true ,
36
17
} ) ;
37
- isJetpackSelfHostedSite . mockReturnValue ( true ) ;
38
- siteHasFeature . mockReturnValue ( true ) ;
39
- getSocialScriptData . mockReturnValue ( {
40
- plugin_info : {
41
- social : { version : '1.0.0' } ,
42
- jetpack : { version : '1.0.0' } ,
43
- } ,
44
- } ) ;
18
+ mockScriptData ( ) ;
19
+ } ) ;
20
+
21
+ afterEach ( ( ) => {
22
+ clearMockedScriptData ( ) ;
45
23
} ) ;
46
24
47
25
describe ( 'Page rendering' , ( ) => {
@@ -52,88 +30,122 @@ describe( 'SocialAdminPage', () => {
52
30
} ) ;
53
31
54
32
render ( < SocialAdminPage /> ) ;
55
- expect ( screen . getByTestId ( 'connection-screen' ) ) . toBeInTheDocument ( ) ;
33
+ expect ( screen . getByRole ( 'button' , { name : 'Get Started' } ) ) . toBeInTheDocument ( ) ;
56
34
} ) ;
57
35
58
36
it ( 'should render main admin page when connected' , ( ) => {
59
37
render ( < SocialAdminPage /> ) ;
60
38
61
- expect ( screen . getByTestId ( 'page-header' ) ) . toBeInTheDocument ( ) ;
62
- expect ( screen . getByTestId ( 'header' ) ) . toBeInTheDocument ( ) ;
63
- expect ( screen . getByTestId ( 'info-section' ) ) . toBeInTheDocument ( ) ;
64
- expect ( screen . getByTestId ( 'support-section' ) ) . toBeInTheDocument ( ) ;
39
+ expect ( screen . getByText ( 'Write once, post everywhere' ) ) . toBeInTheDocument ( ) ;
40
+ expect ( screen . getByText ( 'Did you know?' ) ) . toBeInTheDocument ( ) ;
65
41
} ) ;
66
42
67
43
it ( 'should render pricing page when showPricingPage is true and no paid features' , ( ) => {
68
- mockStore ( {
69
- getSocialSettings : ( ) => ( { showPricingPage : true } ) ,
44
+ mockScriptData ( {
45
+ social : {
46
+ settings : {
47
+ showPricingPage : true ,
48
+ } ,
49
+ } ,
70
50
} ) ;
71
51
72
52
render ( < SocialAdminPage /> ) ;
73
- expect ( screen . getByTestId ( 'pricing-page' ) ) . toBeInTheDocument ( ) ;
53
+
54
+ expect ( screen . getByText ( 'Start for free' ) ) . toBeInTheDocument ( ) ;
55
+
56
+ clearMockedScriptData ( ) ;
74
57
} ) ;
75
58
} ) ;
76
59
77
60
describe ( 'Toggle visibility' , ( ) => {
78
61
describe ( 'UTM toggle' , ( ) => {
79
62
it ( 'should show when module is enabled' , ( ) => {
80
63
render ( < SocialAdminPage /> ) ;
81
- expect ( screen . getByTestId ( 'utm-toggle ' ) ) . toBeInTheDocument ( ) ;
64
+ expect ( screen . getByText ( 'Append UTM parameters to shared URLs ' ) ) . toBeInTheDocument ( ) ;
82
65
} ) ;
83
66
84
67
it ( 'should not show when module is disabled' , ( ) => {
85
- mockStore ( {
86
- getSocialModuleSettings : ( ) => ( { publicize : false } ) ,
68
+ mockScriptData ( {
69
+ social : {
70
+ is_publicize_enabled : false ,
71
+ } ,
87
72
} ) ;
88
73
render ( < SocialAdminPage /> ) ;
89
- expect ( screen . queryByTestId ( 'utm-toggle' ) ) . not . toBeInTheDocument ( ) ;
74
+ expect (
75
+ screen . queryByText ( 'Append UTM parameters to shared URLs' )
76
+ ) . not . toBeInTheDocument ( ) ;
77
+
78
+ clearMockedScriptData ( ) ;
90
79
} ) ;
91
80
} ) ;
92
81
93
82
describe ( 'Social Notes toggle' , ( ) => {
94
83
it ( 'should show when plugin is active and module is enabled' , ( ) => {
95
84
render ( < SocialAdminPage /> ) ;
96
- expect ( screen . getByTestId ( 'social-notes-toggle ' ) ) . toBeInTheDocument ( ) ;
85
+ expect ( screen . getByText ( 'Enable Social Notes ' ) ) . toBeInTheDocument ( ) ;
97
86
} ) ;
98
87
99
88
it ( 'should not show when plugin is not active' , ( ) => {
100
- getSocialScriptData . mockReturnValue ( {
101
- plugin_info : {
102
- social : { version : null } ,
103
- jetpack : { version : '1.0.0' } ,
89
+ mockScriptData ( {
90
+ social : {
91
+ plugin_info : {
92
+ social : { version : null } ,
93
+ jetpack : { version : '1.0.0' } ,
94
+ } ,
104
95
} ,
105
96
} ) ;
106
97
render ( < SocialAdminPage /> ) ;
107
- expect ( screen . queryByTestId ( 'social-notes-toggle' ) ) . not . toBeInTheDocument ( ) ;
98
+ expect ( screen . queryByText ( 'Enable Social Notes' ) ) . not . toBeInTheDocument ( ) ;
99
+
100
+ clearMockedScriptData ( ) ;
108
101
} ) ;
109
102
110
103
it ( 'should not show when module is disabled' , ( ) => {
111
- mockStore ( {
112
- getSocialModuleSettings : ( ) => ( { publicize : false } ) ,
104
+ mockScriptData ( {
105
+ social : {
106
+ is_publicize_enabled : false ,
107
+ } ,
113
108
} ) ;
114
109
render ( < SocialAdminPage /> ) ;
115
110
expect ( screen . queryByTestId ( 'social-notes-toggle' ) ) . not . toBeInTheDocument ( ) ;
111
+ clearMockedScriptData ( ) ;
116
112
} ) ;
117
113
} ) ;
118
114
119
115
describe ( 'Social Image Generator toggle' , ( ) => {
120
116
it ( 'should show when feature is available and module is enabled' , ( ) => {
117
+ mockScriptData ( {
118
+ site : {
119
+ plan : {
120
+ features : {
121
+ active : [ 'social-image-generator' ] ,
122
+ } ,
123
+ } ,
124
+ } ,
125
+ } ) ;
121
126
render ( < SocialAdminPage /> ) ;
122
- expect ( screen . getByTestId ( 'social-image-generator-toggle' ) ) . toBeInTheDocument ( ) ;
127
+
128
+ expect ( screen . getByText ( 'Enable Social Image Generator' ) ) . toBeInTheDocument ( ) ;
129
+
130
+ clearMockedScriptData ( ) ;
123
131
} ) ;
124
132
125
133
it ( 'should not show when feature is not available' , ( ) => {
126
- siteHasFeature . mockReturnValue ( false ) ;
134
+ mockScriptData ( ) ;
127
135
render ( < SocialAdminPage /> ) ;
128
- expect ( screen . queryByTestId ( 'social-image-generator-toggle' ) ) . not . toBeInTheDocument ( ) ;
136
+ expect ( screen . queryByText ( 'Enable Social Image Generator' ) ) . not . toBeInTheDocument ( ) ;
137
+ clearMockedScriptData ( ) ;
129
138
} ) ;
130
139
131
140
it ( 'should not show when module is disabled' , ( ) => {
132
- mockStore ( {
133
- getSocialModuleSettings : ( ) => ( { publicize : false } ) ,
141
+ mockScriptData ( {
142
+ social : {
143
+ is_publicize_enabled : false ,
144
+ } ,
134
145
} ) ;
135
146
render ( < SocialAdminPage /> ) ;
136
- expect ( screen . queryByTestId ( 'social-image-generator-toggle' ) ) . not . toBeInTheDocument ( ) ;
147
+ expect ( screen . queryByText ( 'Enable Social Image Generator' ) ) . not . toBeInTheDocument ( ) ;
148
+ clearMockedScriptData ( ) ;
137
149
} ) ;
138
150
} ) ;
139
151
} ) ;
0 commit comments