Skip to content

Instantly share code, notes, and snippets.

@austenito
Created August 10, 2012 18:47
Show Gist options
  • Save austenito/3316680 to your computer and use it in GitHub Desktop.
Save austenito/3316680 to your computer and use it in GitHub Desktop.
describe "MC", ->
describe "#update_overage_total", ->
beforeEach ->
$('#bill_total').remove()
$('#voucher_value').remove()
$('#overage_value').remove()
$('body').append "<div id='overage_value'></div>"
it "calculates positive overage value", ->
$('body').append "<input id='bill_total' type='text' value=100 />"
$('body').append "<div id='voucher_value'>50</div>"
MC.update_overage_total()
expect($('#overage_value').html()).toEqual("50.00")
it "calculates negative overage value", ->
$('body').append "<input id='bill_total' type='text' value=100 />"
$('body').append "<div id='voucher_value'>150</div>"
MC.update_overage_total()
expect($('#overage_value').html()).toEqual("0.00")
describe "#validate_bill_total", ->
beforeEach ->
$('#bill_total').remove()
$('#bill_total_block').remove()
$('body').append sandbox {
id: 'bill_total_block'
}
describe "bill total value is not a number", ->
beforeEach ->
$('body').append "<input id='bill_total' type='text' value='foo' />"
$('#bill_total_block').append("<div class='validation' style='display: none'></div>")
it "displays an error if bill total is not a number", ->
MC.validate_bill_total()
expect($('#bill_total_block')).toHaveClass('error')
it "shows the validation error", ->
MC.validate_bill_total()
expect($('#bill_total_block .validation')).toBeVisible()
describe "bill total is a valid number", ->
beforeEach ->
$('#bill_total_block').addClass('error')
$('#bill_total_block').append("<div class='validation'></div>")
it "removes the error class", ->
MC.validate_bill_total()
expect($('#bill_total_block')).not.toHaveClass('error')
it "hides validation error", ->
MC.validate_bill_total()
expect($('#bill_total_block .validation')).not.toBeVisible()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment