bootbox
Version:
Wrappers for JavaScript alert(), confirm() and other flexible dialogs using the Bootstrap framework
1,225 lines (895 loc) • 41.2 kB
text/coffeescript
describe "bootbox.prompt", ->
beforeEach ->
window.bootbox = bootbox.init()
= (selector) -> .find selector
= (selector) -> .text()
= (selector) -> .length isnt 0
describe "basic usage tests", ->
describe "with one argument", ->
describe "where the argument is not an object", ->
beforeEach ->
= -> bootbox.prompt "What is your name?"
it "throws an error", ->
expect().to.throw /prompt requires a callback/
describe "where the argument is an object", ->
beforeEach ->
= {}
= => = bootbox.prompt
describe "with a title property", ->
beforeEach ->
.title = "What is your name?"
it "throws an error requiring a callback", ->
expect().to.throw /prompt requires a callback/
describe "and a callback property", ->
describe "where the callback is not a function", ->
beforeEach ->
.callback = "Not a function"
it "throws an error requiring a callback", ->
expect().to.throw /prompt requires a callback/
describe "with a callback function", ->
beforeEach ->
.callback = -> true
it "throws an error requiring a title", ->
expect().to.throw /prompt requires a title/
describe "with a title and a callback", ->
beforeEach ->
=
callback: -> true
title: "What is your name?"
it "does not throw an error", ->
expect().not.to.throw Error
it "creates a dialog object", ->
expect().to.be.an "object"
it "applies the bootbox-prompt class to the dialog", ->
expect(.hasClass("bootbox-prompt")).to.be.true
it "adds the correct button labels", ->
expect(.find(".btn:first").text()).to.equal "Cancel"
expect(.find(".btn:last").text()).to.equal "OK"
it "adds the correct button classes", ->
expect(.find(".btn:first").hasClass("btn-default")).to.be.true
expect(.find(".btn:last").hasClass("btn-primary")).to.be.true
describe "with two arguments", ->
describe "where the second argument is not a function", ->
beforeEach ->
= =>
= bootbox.prompt "What is your name?", "callback here"
it "throws an error requiring a callback", ->
expect().to.throw /prompt requires a callback/
describe "where the second argument is a function", ->
beforeEach ->
= =>
= bootbox.prompt "What is your name?", -> true
it "does not throw an error", ->
expect().not.to.throw Error
it "creates a dialog object", ->
expect().to.be.an "object"
it "adds the correct button labels", ->
expect().to.equal "Cancel"
expect().to.equal "OK"
it "adds the correct button classes", ->
expect(.find(".btn:first").hasClass("btn-default")).to.be.true
expect(.find(".btn:last").hasClass("btn-primary")).to.be.true
it "adds the expected dialog title", ->
expect().to.equal "What is your name?"
it "adds a close button", ->
expect(.find(".modal-header .close")).to.be.ok
it "creates a form with a text input", ->
expect(.find("form input[type=text]")).to.be.ok
it "with no default value", ->
expect(.find("form input[type=text]").val()).to.equal ""
it "shows the dialog", ->
expect(.is(":visible")).to.be.true
describe "configuration options tests", ->
beforeEach ->
=
title: "What is your name?"
callback: -> true
= =>
= bootbox.prompt
describe "with a custom cancel button", ->
beforeEach ->
.buttons =
cancel:
label: "Custom cancel"
className: "btn-danger"
= .find(".btn:first")
it "adds the correct cancel button", ->
expect(.text()).to.equal "Custom cancel"
expect(.hasClass("btn-danger")).to.be.true
describe "with a custom confirm button", ->
beforeEach ->
.buttons =
confirm:
label: "Custom confirm"
className: "btn-warning"
= .find(".btn:last")
it "adds the correct confirm button", ->
expect(.text()).to.equal "Custom confirm"
expect(.hasClass("btn-warning")).to.be.true
describe "with an unrecognised button key", ->
beforeEach ->
.buttons =
prompt:
label: "Custom confirm"
className: "btn-warning"
it "throws an error", ->
expect().to.throw /key prompt is not allowed/
describe "setting show to false", ->
beforeEach ->
.show = false
= sinon.spy()
sinon.stub bootbox, "dialog", =>
on: ->
off: ->
modal:
it "does not show the dialog", ->
expect().not.to.have.been.called
describe "invalid prompt type", ->
beforeEach ->
.inputType = 'foobar'
it "throws an error", ->
expect().to.throw /invalid prompt type/
describe "setting inputType text", ->
beforeEach ->
.inputType = "text"
describe "without default value", ->
beforeEach ->
it "shows text input ", ->
expect().to.be.ok
it "has proper class", ->
expect(.hasClass("bootbox-input")).to.be.ok
expect(.hasClass("bootbox-input-text")).to.be.ok
describe "with default value", ->
beforeEach ->
.value = "John Smith"
it "has correct default value", ->
expect(.val()).to.equal "John Smith"
describe "with placeholder", ->
beforeEach ->
.placeholder = "enter your name"
it "has correct placeholder value", ->
expect(.prop("placeholder")).to.equal "enter your name"
describe "with pattern", ->
beforeEach ->
.pattern = "\d{1,2}/\d{1,2}/\d{4}"
it "has correct pattern value", ->
expect(.prop("pattern")).to.equal "\d{1,2}/\d{1,2}/\d{4}"
describe "setting inputType textarea", ->
beforeEach ->
.inputType = "textarea"
describe "without default value", ->
beforeEach ->
it "shows text input ", ->
expect().to.be.ok
it "has proper class", ->
expect(.hasClass("bootbox-input")).to.be.ok
expect(.hasClass("bootbox-input-textarea")).to.be.ok
describe "with default value", ->
beforeEach ->
.value = "Once upon a time..."
it "has correct default value", ->
expect(.val()).to.equal "Once upon a time..."
describe "with placeholder", ->
beforeEach ->
.placeholder = "enter your favorite fairy tale"
it "has correct placeholder value", ->
expect(.prop("placeholder")).to.equal "enter your favorite fairy tale"
describe "setting inputType email", ->
beforeEach ->
.inputType = "email"
describe "without default value", ->
beforeEach ->
it "shows email input ", ->
expect().to.be.ok
it "has proper class", ->
expect(.hasClass("bootbox-input")).to.be.ok
expect(.hasClass("bootbox-input-email")).to.be.ok
describe "with default value", ->
beforeEach ->
.value = "john@smith.com"
it "has correct default value", ->
expect(.val()).to.equal "john@smith.com"
describe "with placeholder", ->
beforeEach ->
.placeholder = "enter your email"
it "has correct placeholder value", ->
expect(.prop("placeholder")).to.equal "enter your email"
describe "with pattern", ->
beforeEach ->
.pattern = "\d{1,2}/\d{1,2}/\d{4}"
it "has correct pattern value", ->
expect(.prop("pattern")).to.equal "\d{1,2}/\d{1,2}/\d{4}"
describe "setting inputType password", ->
beforeEach ->
.inputType = "password"
describe "without default value", ->
beforeEach ->
it "shows password input ", ->
expect().to.be.ok
it "has proper class", ->
expect(.hasClass("bootbox-input")).to.be.ok
expect(.hasClass("bootbox-input-password")).to.be.ok
describe "with default value", ->
beforeEach ->
.value = "qwerty"
it "has correct default value", ->
expect(.val()).to.equal "qwerty"
describe "with placeholder", ->
beforeEach ->
.placeholder = "enter your password"
it "has correct placeholder value", ->
expect(.prop("placeholder")).to.equal "enter your password"
describe "setting inputType select", ->
describe "without options", ->
beforeEach ->
.inputType = 'select'
it "throws an error", ->
expect().to.throw /prompt with select requires options/
describe "with invalid options", ->
beforeEach ->
.inputType = 'select'
.inputOptions = 'foo'
it "throws an error", ->
expect().to.throw /given options in wrong format/
describe "with empty options", ->
beforeEach ->
.inputType = 'select'
.inputOptions = []
it "throws an error", ->
expect().to.throw /prompt with select requires options/
describe "with options in wrong format", ->
beforeEach ->
.inputType = 'select'
.inputOptions = [{foo: 'bar'}]
it "throws an error", ->
expect().to.throw /given options in wrong format/
describe "with a value but no text", ->
beforeEach ->
.inputType = 'select'
.inputOptions = [{value: 'bar'}]
it "throws an error", ->
expect().to.throw /given options in wrong format/
describe "with an invalid second options", ->
beforeEach ->
.inputType = 'select'
.inputOptions = [
{value: "bar", text: "bar"}
{text: "foo"}
]
it "throws an error", ->
expect().to.throw /given options in wrong format/
describe "with valid options", ->
beforeEach ->
.inputType = "select"
.inputOptions = [{value: 1, text: 'foo'},{value: 2, text: 'bar'},{value: 3, text: 'foobar'}]
it "shows select input", ->
expect().to.be.ok
it "has proper class", ->
expect(.hasClass("bootbox-input")).to.be.ok
expect(.hasClass("bootbox-input-select")).to.be.ok
it "with three options", ->
expect(.length).to.equal 3
describe "with zero as the first option", ->
beforeEach ->
.inputType = "select"
.inputOptions = [{value: 0, text: "foo"}]
it "shows the select input", ->
expect().to.be.ok
describe "with false as the first option", ->
beforeEach ->
.inputType = "select"
.inputOptions = [{value: false, text: "foo"}]
it "shows the select input", ->
expect().to.be.ok
describe "with option groups", ->
beforeEach ->
.inputType = 'select'
.inputOptions = [
{value: 1, group: 'foo', text: 'foo'}
{value: 2, group: 'bar', text: 'bar'}
{value: 3, group: 'foo', text: 'foobar'}
{value: 4, group: 'bar', text: 'barfoo'}
]
it "shows select input", ->
expect().to.be.ok
it "has proper class", ->
expect(.hasClass("bootbox-input")).to.be.ok
expect(.hasClass("bootbox-input-select")).to.be.ok
it "with two option group", ->
expect(.length).to.equal 2
it "with four options", ->
expect(.length).to.equal 4
describe "setting inputType checkbox", ->
describe "without options", ->
beforeEach ->
.inputType = 'checkbox'
it "throws an error", ->
expect().to.throw /prompt with checkbox requires options/
describe "with options", ->
beforeEach ->
.inputType = 'checkbox'
.inputOptions = [
{value: 1, text: 'foo'}
{value: 2, text: 'bar'}
{value: 3, text: 'foobar'}
]
it "shows checkbox input", ->
expect().to.be.ok
it "has proper class", ->
expect(.hasClass("bootbox-input")).to.be.ok
expect(.hasClass("bootbox-input-checkbox")).to.be.ok
it "with three checkboxes", ->
expect(.length).to.equal 3
describe "setting inputType date", ->
beforeEach ->
.inputType = "date"
describe "without default value", ->
beforeEach ->
it "shows date input ", ->
expect().to.be.ok
it "has proper class", ->
expect(.hasClass("bootbox-input")).to.be.ok
expect(.hasClass("bootbox-input-date")).to.be.ok
describe "with default value", ->
beforeEach ->
.value = "17/08/2005"
it "has correct default value", ->
expect(.val()).to.equal "17/08/2005"
describe "with placeholder", ->
beforeEach ->
.placeholder = "enter the date"
it "has correct placeholder value", ->
expect(.prop("placeholder")).to.equal "enter the date"
describe "with pattern", ->
beforeEach ->
.pattern = "\d{1,2}/\d{1,2}/\d{4}"
it "has correct pattern value", ->
expect(.prop("pattern")).to.equal "\d{1,2}/\d{1,2}/\d{4}"
describe "setting inputType time", ->
beforeEach ->
.inputType = "time"
describe "without default value", ->
beforeEach ->
it "shows time input ", ->
expect().to.be.ok
it "has proper class", ->
expect(.hasClass("bootbox-input")).to.be.ok
expect(.hasClass("bootbox-input-time")).to.be.ok
describe "with default value", ->
beforeEach ->
.value = "19:02"
it "has correct default value", ->
expect(.val()).to.equal "19:02"
describe "with placeholder", ->
beforeEach ->
.placeholder = "enter the time"
it "has correct placeholder value", ->
expect(.prop("placeholder")).to.equal "enter the time"
describe "with pattern", ->
beforeEach ->
.pattern = "\d{1,2}/\d{1,2}/\d{4}"
it "has correct pattern value", ->
expect(.prop("pattern")).to.equal "\d{1,2}/\d{1,2}/\d{4}"
describe "setting inputType number", ->
beforeEach ->
.inputType = "number"
describe "without default value", ->
beforeEach ->
it "shows number input ", ->
expect().to.be.ok
it "has proper class", ->
expect(.hasClass("bootbox-input")).to.be.ok
expect(.hasClass("bootbox-input-number")).to.be.ok
describe "with default value", ->
beforeEach ->
.value = "300"
it "has correct default value", ->
expect(.val()).to.equal "300"
describe "with placeholder", ->
beforeEach ->
.placeholder = "enter the number"
it "has correct placeholder value", ->
expect(.prop("placeholder")).to.equal "enter the number"
describe "callback tests", ->
describe "with a simple callback", ->
beforeEach ->
= sinon.spy()
= bootbox.prompt
title: "What is your name?"
callback:
= sinon.spy , "modal"
describe "when entering no value in the text input", ->
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly ""
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "when submitting the form", ->
beforeEach ->
.find(".bootbox-form").trigger "submit"
it "invokes the callback with the correct value", ->
expect().to.have.been.calledWithExactly ""
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "when entering a value in the text input", ->
beforeEach ->
.find(".bootbox-input").val "Test input"
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly "Test input"
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "when submitting the form", ->
beforeEach ->
.find(".bootbox-form").trigger "submit"
it "invokes the callback with the correct value", ->
expect().to.have.been.calledWithExactly "Test input"
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "when dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "when triggering the escape event", ->
beforeEach ->
.trigger "escape.close.bb"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "when dismissing the dialog by clicking the close button", ->
beforeEach ->
.find(".close").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "with a callback which returns false", ->
beforeEach ->
= sinon.stub()
.returns false
= bootbox.prompt
title: "What is your name?"
callback:
= sinon.spy , "modal"
describe "when entering no value in the text input", ->
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly ""
it "should not hide the modal", ->
expect().not.to.have.been.called
describe "when entering a value in the text input", ->
beforeEach ->
.find(".bootbox-input").val "Test input"
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly "Test input"
it "should not hide the modal", ->
expect().not.to.have.been.called
describe "when dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
it "should not hide the modal", ->
expect().not.to.have.been.called
describe "when triggering the escape event", ->
beforeEach ->
.trigger "escape.close.bb"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
it "should not hide the modal", ->
expect().not.to.have.been.called
describe "when dismissing the dialog by clicking the close button", ->
beforeEach ->
.find(".close").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
it "should not hide the modal", ->
expect().not.to.have.been.called
describe "with a default value", ->
beforeEach ->
= sinon.spy()
= bootbox.prompt
title: "What is your name?"
value: "Bob"
callback:
= sinon.spy , "modal"
it "populates the input with the default value", ->
expect(.find(".bootbox-input").val()).to.equal "Bob"
describe "when entering no value in the text input", ->
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly "Bob"
describe "when dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
describe "when entering a value in the text input", ->
beforeEach ->
.find(".bootbox-input").val "Alice"
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly "Alice"
describe "when dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
describe "with a placeholder", ->
beforeEach ->
= sinon.spy()
= bootbox.prompt
title: "What is your name?"
placeholder: "e.g. Bob Smith"
callback: -> true
it "populates the input with the placeholder attribute", ->
expect(.find(".bootbox-input").attr("placeholder")).to.equal "e.g. Bob Smith"
describe "with inputType select", ->
describe "without a default value", ->
beforeEach ->
= sinon.spy()
= bootbox.prompt
title: "What is your IDE?"
callback:
inputType: "select"
inputOptions: [
{value: '#', text: 'Choose one'},
{value: 1, text: 'Vim'},
{value: 2, text: 'Sublime Text'},
{value: 3, text: 'WebStorm/PhpStorm'},
{value: 4, text: 'Komodo IDE'},
]
= sinon.spy , "modal"
it "has correct number values in list", ->
expect(.length).to.equal 5
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly "#"
describe "when dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
describe "with a default value", ->
beforeEach ->
= sinon.spy()
= bootbox.prompt
title: "What is your IDE?"
callback:
value: 1
inputType: "select"
inputOptions: [
{value: '#', text: 'Choose one'},
{value: 1, text: 'Vim'},
{value: 2, text: 'Sublime Text'},
{value: 3, text: 'WebStorm/PhpStorm'},
{value: 4, text: 'Komodo IDE'},
]
= sinon.spy , "modal"
it "specified option is selected", ->
expect(.find(".bootbox-input-select").val()).to.equal "1"
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly "1"
describe "when dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
describe "when changing the selected option and dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".bootbox-input-select").val(3)
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly "3"
describe "with inputType email", ->
describe "without a default value", ->
beforeEach ->
= sinon.spy()
= bootbox.prompt
title: "What is your email?"
inputType: "email"
callback:
= sinon.spy , "modal"
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly ""
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "when submitting the form", ->
beforeEach ->
.find(".bootbox-form").trigger "submit"
it "invokes the callback with the correct value", ->
expect().to.have.been.calledWithExactly ""
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "when entering a value in the email input", ->
beforeEach ->
.find(".bootbox-input-email").val "john@smith.com"
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly "john@smith.com"
describe "when dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
describe "with a default value", ->
beforeEach ->
= sinon.spy()
= bootbox.prompt
title: "What is your email?"
inputType: "email"
value: "john@smith.com"
callback:
= sinon.spy , "modal"
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly "john@smith.com"
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "when submitting the form", ->
beforeEach ->
.find(".bootbox-form").trigger "submit"
it "invokes the callback with the correct value", ->
expect().to.have.been.calledWithExactly "john@smith.com"
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "when changing a value in the email input", ->
beforeEach ->
.find(".bootbox-input-email").val "smith@john.com"
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly "smith@john.com"
describe "when dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
describe "with input type checkbox", ->
describe "without a default value", ->
beforeEach ->
= sinon.spy()
= bootbox.prompt
title: "What is your IDE?"
inputType: 'checkbox'
inputOptions: [
{value: 1, text: 'Vim'},
{value: 2, text: 'Sublime Text'},
{value: 3, text: 'WebStorm/PhpStorm'},
{value: 4, text: 'Komodo IDE'},
]
callback:
= sinon.spy , "modal"
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with an undefined value", ->
expect().to.have.been.calledWithExactly []
it "should hide the modal", ->
expect().to.have.been.calledWithExactly "hide"
describe "when dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
describe "with default value", ->
describe "one value checked", ->
beforeEach ->
= sinon.spy()
= bootbox.prompt
title: "What is your IDE?"
callback:
value: 2
inputType: "checkbox"
inputOptions: [
{value: 1, text: 'Vim'},
{value: 2, text: 'Sublime Text'},
{value: 3, text: 'WebStorm/PhpStorm'},
{value: 4, text: 'Komodo IDE'},
]
= sinon.spy , "modal"
it "specified checkbox is checked", ->
expect(.find("input:checkbox:checked").val()).to.equal "2"
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly ["2"]
describe "when dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
describe "when changing the checked option and dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find("input:checkbox:checked").prop('checked', false)
.find("input:checkbox[value=3]").prop('checked', true)
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
describe "when changing the selected option and dismissing the dialog by clicking OK", ->
beforeEach ->
.find("input:checkbox:checked").prop('checked', false)
.find("input:checkbox[value=3]").prop('checked', true)
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly ["3"]
describe "multiple value checked", ->
beforeEach ->
= sinon.spy()
= bootbox.prompt
title: "What is your IDE?"
callback:
value: [2, 3]
inputType: "checkbox"
inputOptions: [
{value: 1, text: 'Vim'}
{value: 2, text: 'Sublime Text'}
{value: 3, text: 'WebStorm/PhpStorm'}
{value: 4, text: 'Komodo IDE'}
]
= sinon.spy , "modal"
it "specified checkboxes are checked", ->
checked = []
.find("input:checkbox:checked").each (foo, bar) =>
checked.push $(bar).val()
expect(checked).to.deep.equal ["2", "3"]
describe "when dismissing the dialog by clicking OK", ->
beforeEach ->
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly ["2", "3"]
describe "when dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
describe "when changing the checked options and dismissing the dialog by clicking Cancel", ->
beforeEach ->
.find("input:checkbox:checked").prop('checked', false)
.find("input:checkbox[value=1]").prop('checked', true)
.find("input:checkbox[value=4]").prop('checked', true)
.find(".btn-default").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly null
describe "when changing the checked options and dismissing the dialog by clicking OK", ->
beforeEach ->
.find("input:checkbox:checked").prop('checked', false)
.find("input:checkbox[value=1]").prop('checked', true)
.find("input:checkbox[value=4]").prop('checked', true)
.find(".btn-primary").trigger "click"
it "should invoke the callback", ->
expect().to.have.been.called
it "with the correct value", ->
expect().to.have.been.calledWithExactly ["1", "4"]