Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 81c4262

Browse files
author
Alex Robinson
committed
Add unit tests for rendering PromptTextBox in MessageBox when input is allowed
1 parent ea94cba commit 81c4262

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

test/unit/app/renderer/components/common/messageBoxTest.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ let appState = Immutable.fromJS({
4141
}
4242
})
4343

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+
4463
describe('MessageBox component unit tests', function () {
4564
before(function () {
4665
mockery.enable({
@@ -60,7 +79,7 @@ describe('MessageBox component unit tests', function () {
6079

6180
describe('Rendering', function () {
6281
before(function () {
63-
appStoreRenderer.state = Immutable.fromJS(appState)
82+
appStoreRenderer.state = createAppState(detail1)
6483
})
6584
it('renders itself inside a dialog component', function () {
6685
const wrapper = mount(
@@ -98,6 +117,19 @@ describe('MessageBox component unit tests', function () {
98117
assert.equal(wrapper.find('button[data-l10n-id="Cancel"][data-test-id="secondaryColor"]').length, 1)
99118
})
100119

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+
101133
it('hides the suppress checkbox if showSuppress is false', function () {
102134
const appState2 = appState.setIn(['tabs', 0, 'messageBoxDetail', 'showSuppress'], false)
103135
appStoreRenderer.state = Immutable.fromJS(appState2)
@@ -158,5 +190,27 @@ describe('MessageBox component unit tests', function () {
158190
assert.equal(spy.withArgs(tabId, response).calledOnce, true)
159191
appActions.tabMessageBoxDismissed.restore()
160192
})
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+
})
161215
})
162216
})

0 commit comments

Comments
 (0)