@@ -41,6 +41,25 @@ let appState = Immutable.fromJS({
41
41
}
42
42
} )
43
43
44
+ const createAppState = detail => Immutable . fromJS ( {
45
+ windows : [ {
46
+ windowId : 1 ,
47
+ windowUUID : 'uuid'
48
+ } ] ,
49
+ tabs : [ {
50
+ tabId : tabId ,
51
+ windowId : 1 ,
52
+ windowUUID : 'uuid' ,
53
+ url : 'https://brave.com' ,
54
+ messageBoxDetail : detail
55
+ } ] ,
56
+ tabsInternal : {
57
+ index : {
58
+ 1 : 0
59
+ }
60
+ }
61
+ } )
62
+
44
63
describe ( 'MessageBox component unit tests' , function ( ) {
45
64
before ( function ( ) {
46
65
mockery . enable ( {
@@ -60,7 +79,7 @@ describe('MessageBox component unit tests', function () {
60
79
61
80
describe ( 'Rendering' , function ( ) {
62
81
before ( function ( ) {
63
- appStoreRenderer . state = Immutable . fromJS ( appState )
82
+ appStoreRenderer . state = createAppState ( detail1 )
64
83
} )
65
84
it ( 'renders itself inside a dialog component' , function ( ) {
66
85
const wrapper = mount (
@@ -98,6 +117,19 @@ describe('MessageBox component unit tests', function () {
98
117
assert . equal ( wrapper . find ( 'button[data-l10n-id="Cancel"][data-test-id="secondaryColor"]' ) . length , 1 )
99
118
} )
100
119
120
+ it ( 'renders the PromptTextBox when input is allowed' , function ( ) {
121
+ appStoreRenderer . state = createAppState ( Object . assign ( { } , detail1 , {
122
+ allowInput : true
123
+ } ) )
124
+ const wrapper = mount (
125
+ < MessageBox
126
+ tabId = { tabId }
127
+ allowInput
128
+ />
129
+ )
130
+ assert . equal ( wrapper . find ( 'PromptTextBox' ) . length , 1 )
131
+ } )
132
+
101
133
it ( 'hides the suppress checkbox if showSuppress is false' , function ( ) {
102
134
const appState2 = appState . setIn ( [ 'tabs' , 0 , 'messageBoxDetail' , 'showSuppress' ] , false )
103
135
appStoreRenderer . state = Immutable . fromJS ( appState2 )
@@ -158,5 +190,27 @@ describe('MessageBox component unit tests', function () {
158
190
assert . equal ( spy . withArgs ( tabId , response ) . calledOnce , true )
159
191
appActions . tabMessageBoxDismissed . restore ( )
160
192
} )
193
+
194
+ it ( 'calls appActions.tabMessageBoxDismissed with input input is allowed' , function ( ) {
195
+ const expectedInput = 'some input'
196
+ appStoreRenderer . state = createAppState ( Object . assign ( { } , detail1 , {
197
+ allowInput : true ,
198
+ defaultPromptText : expectedInput
199
+ } ) )
200
+ const spy = sinon . spy ( appActions , 'tabMessageBoxDismissed' )
201
+ const wrapper = mount (
202
+ < MessageBox
203
+ tabId = { tabId }
204
+ />
205
+ )
206
+ const response = {
207
+ suppress : detail1 . suppress ,
208
+ result : false ,
209
+ input : expectedInput
210
+ }
211
+ wrapper . find ( 'button[data-l10n-id="Cancel"][data-test-id="secondaryColor"]' ) . simulate ( 'click' )
212
+ assert . equal ( spy . withArgs ( tabId , response ) . calledOnce , true )
213
+ appActions . tabMessageBoxDismissed . restore ( )
214
+ } )
161
215
} )
162
216
} )
0 commit comments