2016-05-31 15:32:29 -04:00
|
|
|
#= require jquery-ui/autocomplete
|
2015-12-17 16:45:43 -05:00
|
|
|
#= require new_branch_form
|
|
|
|
|
|
|
|
describe 'Branch', ->
|
|
|
|
describe 'create a new branch', ->
|
|
|
|
fixture.preload('new_branch.html')
|
|
|
|
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith = (value) ->
|
|
|
|
$('.js-branch-name').val(value).trigger('blur')
|
|
|
|
|
|
|
|
expectToHaveError = (error) ->
|
|
|
|
expect($('.js-branch-name-error span').text()).toEqual(error)
|
|
|
|
|
2015-12-17 16:45:43 -05:00
|
|
|
beforeEach ->
|
|
|
|
fixture.load('new_branch.html')
|
|
|
|
$('form').on 'submit', (e) -> e.preventDefault()
|
|
|
|
|
|
|
|
@form = new NewBranchForm($('.js-create-branch-form'), [])
|
|
|
|
|
|
|
|
it "can't start with a dot", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '.foo'
|
|
|
|
expectToHaveError "can't start with '.'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't start with a slash", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '/foo'
|
|
|
|
expectToHaveError "can't start with '/'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't have two consecutive dots", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith 'foo..bar'
|
|
|
|
expectToHaveError "can't contain '..'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't have spaces anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith ' foo'
|
|
|
|
expectToHaveError "can't contain spaces"
|
|
|
|
fillNameWith 'foo bar'
|
|
|
|
expectToHaveError "can't contain spaces"
|
|
|
|
fillNameWith 'foo '
|
|
|
|
expectToHaveError "can't contain spaces"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't have ~ anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '~foo'
|
|
|
|
expectToHaveError "can't contain '~'"
|
|
|
|
fillNameWith 'foo~bar'
|
|
|
|
expectToHaveError "can't contain '~'"
|
|
|
|
fillNameWith 'foo~'
|
|
|
|
expectToHaveError "can't contain '~'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't have tilde anwhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '~foo'
|
|
|
|
expectToHaveError "can't contain '~'"
|
|
|
|
fillNameWith 'foo~bar'
|
|
|
|
expectToHaveError "can't contain '~'"
|
|
|
|
fillNameWith 'foo~'
|
|
|
|
expectToHaveError "can't contain '~'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't have caret anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '^foo'
|
|
|
|
expectToHaveError "can't contain '^'"
|
|
|
|
fillNameWith 'foo^bar'
|
|
|
|
expectToHaveError "can't contain '^'"
|
|
|
|
fillNameWith 'foo^'
|
|
|
|
expectToHaveError "can't contain '^'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't have : anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith ':foo'
|
|
|
|
expectToHaveError "can't contain ':'"
|
|
|
|
fillNameWith 'foo:bar'
|
|
|
|
expectToHaveError "can't contain ':'"
|
|
|
|
fillNameWith ':foo'
|
|
|
|
expectToHaveError "can't contain ':'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't have question mark anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '?foo'
|
|
|
|
expectToHaveError "can't contain '?'"
|
|
|
|
fillNameWith 'foo?bar'
|
|
|
|
expectToHaveError "can't contain '?'"
|
|
|
|
fillNameWith 'foo?'
|
|
|
|
expectToHaveError "can't contain '?'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't have asterisk anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '*foo'
|
|
|
|
expectToHaveError "can't contain '*'"
|
|
|
|
fillNameWith 'foo*bar'
|
|
|
|
expectToHaveError "can't contain '*'"
|
|
|
|
fillNameWith 'foo*'
|
|
|
|
expectToHaveError "can't contain '*'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't have open bracket anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '[foo'
|
|
|
|
expectToHaveError "can't contain '['"
|
|
|
|
fillNameWith 'foo[bar'
|
|
|
|
expectToHaveError "can't contain '['"
|
|
|
|
fillNameWith 'foo['
|
|
|
|
expectToHaveError "can't contain '['"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't have a backslash anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '\\foo'
|
|
|
|
expectToHaveError "can't contain '\\'"
|
|
|
|
fillNameWith 'foo\\bar'
|
|
|
|
expectToHaveError "can't contain '\\'"
|
|
|
|
fillNameWith 'foo\\'
|
|
|
|
expectToHaveError "can't contain '\\'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't contain a sequence @{ anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '@{foo'
|
|
|
|
expectToHaveError "can't contain '@{'"
|
|
|
|
fillNameWith 'foo@{bar'
|
|
|
|
expectToHaveError "can't contain '@{'"
|
|
|
|
fillNameWith 'foo@{'
|
|
|
|
expectToHaveError "can't contain '@{'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't have consecutive slashes", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith 'foo//bar'
|
|
|
|
expectToHaveError "can't contain consecutive slashes"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't end with a slash", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith 'foo/'
|
|
|
|
expectToHaveError "can't end in '/'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't end with a dot", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith 'foo.'
|
|
|
|
expectToHaveError "can't end in '.'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't end with .lock", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith 'foo.lock'
|
|
|
|
expectToHaveError "can't end in '.lock'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "can't be the single character @", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '@'
|
|
|
|
expectToHaveError "can't be '@'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "concatenates all error messages", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '/foo bar?~.'
|
|
|
|
expectToHaveError "can't start with '/', can't contain spaces, '?', '~', can't end in '.'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "doesn't duplicate error messages", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '?foo?bar?zoo?'
|
|
|
|
expectToHaveError "can't contain '?'"
|
2015-12-17 16:45:43 -05:00
|
|
|
|
|
|
|
it "removes the error message when is a valid name", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith 'foo?bar'
|
2015-12-17 16:45:43 -05:00
|
|
|
expect($('.js-branch-name-error span').length).toEqual(1)
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith 'foobar'
|
2015-12-17 16:45:43 -05:00
|
|
|
expect($('.js-branch-name-error span').length).toEqual(0)
|
|
|
|
|
|
|
|
it "can have dashes anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '-foo-bar-zoo-'
|
2015-12-17 16:45:43 -05:00
|
|
|
expect($('.js-branch-name-error span').length).toEqual(0)
|
|
|
|
|
|
|
|
it "can have underscores anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '_foo_bar_zoo_'
|
2015-12-17 16:45:43 -05:00
|
|
|
expect($('.js-branch-name-error span').length).toEqual(0)
|
|
|
|
|
|
|
|
it "can have numbers anywhere", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith '1foo2bar3zoo4'
|
2015-12-17 16:45:43 -05:00
|
|
|
expect($('.js-branch-name-error span').length).toEqual(0)
|
|
|
|
|
|
|
|
it "can be only letters", ->
|
2015-12-22 12:32:57 -05:00
|
|
|
fillNameWith 'foo'
|
2015-12-17 16:45:43 -05:00
|
|
|
expect($('.js-branch-name-error span').length).toEqual(0)
|