Commit ce6a6481 authored by Rafael Reggiani Manzo's avatar Rafael Reggiani Manzo

Merge branch 'refactor_state_select_js' into 'master'

Extract params of state select to a function

Cover the whole file with unit tests
Signed-off-by: marcheing's avatarHeitor Reis <marcheing@gmail.com>

See merge request !16
parents bdfa43bd 1e0f83f7
Pipeline #3629424 passed with stage
in 9 minutes and 36 seconds
@state_select = (event) ->
$.get(
'/states',
{
country: $('select#profile_country :selected').text(),
locale: $('#locale').val()
},
(data) ->
$('div#state_select').html(data)
)
@success_response = (data) ->
$('div#state_select').html(data)
@request_params = ->
country: $('select#profile_country :selected').text(),
locale: $('#locale').val()
$.get('/states', @request_params(), @success_response)
$(document).ready(@state_select)
$('select#profile_country').on('change', @state_select)
......@@ -3,17 +3,23 @@
describe 'state_select', ->
before ->
@state_select_div = html: (new_html) -> @content = new_html
@state_select_div.html('old_data')
sinon.stub(window, '$')
@get_stub = sinon.stub(window.$, 'get')
$.withArgs('select#profile_country :selected').returns(text: -> 'Brazil')
$.withArgs('#locale').returns(val: -> 'en')
$.withArgs('div#state_select').returns(html: (data) ->)
$.withArgs('div#state_select').returns(@state_select_div)
after ->
$.restore()
it 'is expected to access the state route', ->
@get_stub.withArgs('/states', { country: 'Brazil', locale: 'en' }, (data) -> )
response_data = 'data'
$.get = (url, params, callback) ->
callback(response_data)
expect(@state_select_div.content).to.equal('old_data')
state_select()
sinon.assert.calledOnce(@get_stub)
expect(@state_select_div.content).to.equal(response_data)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment