@@ -11,6 +11,18 @@ let mockPreferences: PreferencesAccess;
1111describe ( 'AIOptInModal Component' , function ( ) {
1212 beforeEach ( async function ( ) {
1313 mockPreferences = await createSandboxFromDefaultPreferences ( ) ;
14+
15+ // Mock showModal for MarketingModal v8.0.0 which uses HTML dialog element
16+ if ( ! HTMLDialogElement . prototype . showModal ) {
17+ HTMLDialogElement . prototype . showModal = function ( ) {
18+ this . open = true ;
19+ } ;
20+ }
21+ if ( ! HTMLDialogElement . prototype . close ) {
22+ HTMLDialogElement . prototype . close = function ( ) {
23+ this . open = false ;
24+ } ;
25+ }
1426 } ) ;
1527
1628 afterEach ( function ( ) {
@@ -52,8 +64,7 @@ describe('AIOptInModal Component', function () {
5264 expect ( screen . getByText ( 'Not now' ) ) . to . exist ;
5365 } ) ;
5466
55- // TODO: Re-enable this test once the LG-5416 is released
56- it . skip ( 'should show the opt in button enabled when project AI setting is enabled' , async function ( ) {
67+ it ( 'should show the opt in button enabled when project AI setting is enabled' , async function ( ) {
5768 await mockPreferences . savePreferences ( {
5869 enableGenAIFeaturesAtlasProject : true ,
5970 } ) ;
@@ -70,12 +81,11 @@ describe('AIOptInModal Component', function () {
7081 </ AIOptInModal >
7182 </ PreferencesProvider >
7283 ) ;
73- const button = screen . getByText ( 'Use Natural Language ' ) . closest ( 'button' ) ;
84+ const button = screen . getByText ( 'Use AI Features ' ) . closest ( 'button' ) ;
7485 expect ( button ?. getAttribute ( 'aria-disabled' ) ) . to . equal ( 'false' ) ;
7586 } ) ;
7687
77- // TODO: Re-enable this test once the LG-5416 is released
78- it . skip ( 'should disable the opt in button if project AI setting is disabled ' , async function ( ) {
88+ it ( 'should disable the opt in button if project AI setting is disabled' , async function ( ) {
7989 await mockPreferences . savePreferences ( {
8090 enableGenAIFeaturesAtlasProject : false ,
8191 } ) ;
@@ -92,7 +102,137 @@ describe('AIOptInModal Component', function () {
92102 </ AIOptInModal >
93103 </ PreferencesProvider >
94104 ) ;
95- const button = screen . getByText ( 'Use Natural Language ' ) . closest ( 'button' ) ;
105+ const button = screen . getByText ( 'Use AI Features ' ) . closest ( 'button' ) ;
96106 expect ( button ?. getAttribute ( 'aria-disabled' ) ) . to . equal ( 'true' ) ;
97107 } ) ;
108+
109+ describe ( 'conditional banner messages' , function ( ) {
110+ it ( 'should show warning banner when AI features are disabled' , async function ( ) {
111+ await mockPreferences . savePreferences ( {
112+ enableGenAIFeaturesAtlasProject : false ,
113+ enableGenAISampleDocumentPassingOnAtlasProject : false ,
114+ } ) ;
115+ render (
116+ < PreferencesProvider value = { mockPreferences } >
117+ < AIOptInModal
118+ projectId = "ab123"
119+ isOptInModalVisible = { true }
120+ isOptInInProgress = { false }
121+ onOptInModalClose = { ( ) => { } }
122+ onOptInClick = { ( ) => { } }
123+ />
124+ </ PreferencesProvider >
125+ ) ;
126+ expect (
127+ screen . getByText (
128+ / A I f e a t u r e s a r e d i s a b l e d f o r p r o j e c t u s e r s w i t h d a t a a c c e s s /
129+ )
130+ ) . to . exist ;
131+ expect (
132+ screen . getByText ( / P r o j e c t O w n e r s c a n e n a b l e D a t a E x p l o r e r A I f e a t u r e s / )
133+ ) . to . exist ;
134+ } ) ;
135+
136+ it ( 'should show info banner with correct copy when only the "Sending Sample Field Values in DE Gen AI Features" setting is disabled' , async function ( ) {
137+ await mockPreferences . savePreferences ( {
138+ enableGenAIFeaturesAtlasProject : true ,
139+ enableGenAISampleDocumentPassingOnAtlasProject : false ,
140+ } ) ;
141+ render (
142+ < PreferencesProvider value = { mockPreferences } >
143+ < AIOptInModal
144+ projectId = "ab123"
145+ isOptInModalVisible = { true }
146+ isOptInInProgress = { false }
147+ onOptInModalClose = { ( ) => { } }
148+ onOptInClick = { ( ) => { } }
149+ />
150+ </ PreferencesProvider >
151+ ) ;
152+ expect (
153+ screen . getByText (
154+ / A I f e a t u r e s a r e e n a b l e d f o r p r o j e c t u s e r s w i t h d a t a a c c e s s /
155+ )
156+ ) . to . exist ;
157+ expect (
158+ screen . getByText (
159+ / e n a b l e s e n d i n g s a m p l e f i e l d v a l u e s i n D a t a E x p l o r e r A I f e a t u r e s /
160+ )
161+ ) . to . exist ;
162+ } ) ;
163+
164+ it ( 'should show info banner with correct copy when both project settings are enabled' , async function ( ) {
165+ await mockPreferences . savePreferences ( {
166+ enableGenAIFeaturesAtlasProject : true ,
167+ enableGenAISampleDocumentPassingOnAtlasProject : true ,
168+ } ) ;
169+ render (
170+ < PreferencesProvider value = { mockPreferences } >
171+ < AIOptInModal
172+ projectId = "ab123"
173+ isOptInModalVisible = { true }
174+ isOptInInProgress = { false }
175+ onOptInModalClose = { ( ) => { } }
176+ onOptInClick = { ( ) => { } }
177+ />
178+ </ PreferencesProvider >
179+ ) ;
180+ expect (
181+ screen . getByText (
182+ / A I f e a t u r e s a r e e n a b l e d f o r p r o j e c t u s e r s w i t h d a t a a c c e s s /
183+ )
184+ ) . to . exist ;
185+ expect (
186+ screen . getByText ( / P r o j e c t O w n e r s c a n d i s a b l e D a t a E x p l o r e r A I f e a t u r e s / )
187+ ) . to . exist ;
188+ } ) ;
189+ } ) ;
190+
191+ describe ( 'button click behavior' , function ( ) {
192+ it ( 'should not call onOptInClick when main AI features are disabled' , async function ( ) {
193+ let onOptInClickCalled = false ;
194+ await mockPreferences . savePreferences ( {
195+ enableGenAIFeaturesAtlasProject : false ,
196+ } ) ;
197+ render (
198+ < PreferencesProvider value = { mockPreferences } >
199+ < AIOptInModal
200+ projectId = "ab123"
201+ isOptInModalVisible = { true }
202+ isOptInInProgress = { false }
203+ onOptInModalClose = { ( ) => { } }
204+ onOptInClick = { ( ) => {
205+ onOptInClickCalled = true ;
206+ } }
207+ />
208+ </ PreferencesProvider >
209+ ) ;
210+ const button = screen . getByText ( 'Use AI Features' ) ;
211+ button . click ( ) ;
212+ expect ( onOptInClickCalled ) . to . be . false ;
213+ } ) ;
214+
215+ it ( 'should call onOptInClick when main AI features are enabled' , async function ( ) {
216+ let onOptInClickCalled = false ;
217+ await mockPreferences . savePreferences ( {
218+ enableGenAIFeaturesAtlasProject : true ,
219+ } ) ;
220+ render (
221+ < PreferencesProvider value = { mockPreferences } >
222+ < AIOptInModal
223+ projectId = "ab123"
224+ isOptInModalVisible = { true }
225+ isOptInInProgress = { false }
226+ onOptInModalClose = { ( ) => { } }
227+ onOptInClick = { ( ) => {
228+ onOptInClickCalled = true ;
229+ } }
230+ />
231+ </ PreferencesProvider >
232+ ) ;
233+ const button = screen . getByText ( 'Use AI Features' ) ;
234+ button . click ( ) ;
235+ expect ( onOptInClickCalled ) . to . be . true ;
236+ } ) ;
237+ } ) ;
98238} ) ;
0 commit comments