diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2015-12-22 15:32:57 -0200 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2015-12-22 15:32:57 -0200 |
commit | 3657eb76c265f4cf6c35c13c2e32bd2536df89ed (patch) | |
tree | a7b72dd1efb1aa3862447804554951b841af9ee9 /spec/javascripts | |
parent | 23b436dc9346275e9fbd6201317e09da63befc46 (diff) | |
download | gitlab-ce-3657eb76c265f4cf6c35c13c2e32bd2536df89ed.tar.gz |
Add helper methods to JS validation spec for invalid branch namesbranch-invalid-name
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/new_branch_spec.js.coffee | 179 |
1 files changed, 92 insertions, 87 deletions
diff --git a/spec/javascripts/new_branch_spec.js.coffee b/spec/javascripts/new_branch_spec.js.coffee index ea479239957..8889ce2e9b3 100644 --- a/spec/javascripts/new_branch_spec.js.coffee +++ b/spec/javascripts/new_branch_spec.js.coffee @@ -5,151 +5,156 @@ describe 'Branch', -> describe 'create a new branch', -> fixture.preload('new_branch.html') + fillNameWith = (value) -> + $('.js-branch-name').val(value).trigger('blur') + + expectToHaveError = (error) -> + expect($('.js-branch-name-error span').text()).toEqual(error) + beforeEach -> fixture.load('new_branch.html') $('form').on 'submit', (e) -> e.preventDefault() @form = new NewBranchForm($('.js-create-branch-form'), []) - @name = $('.js-branch-name') it "can't start with a dot", -> - @name.val('.foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't start with '.'") + fillNameWith '.foo' + expectToHaveError "can't start with '.'" it "can't start with a slash", -> - @name.val('/foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't start with '/'") + fillNameWith '/foo' + expectToHaveError "can't start with '/'" it "can't have two consecutive dots", -> - @name.val('foo..bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '..'") + fillNameWith 'foo..bar' + expectToHaveError "can't contain '..'" it "can't have spaces anywhere", -> - @name.val(' foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain spaces") - @name.val('foo bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain spaces") - @name.val('foo ').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain spaces") + fillNameWith ' foo' + expectToHaveError "can't contain spaces" + fillNameWith 'foo bar' + expectToHaveError "can't contain spaces" + fillNameWith 'foo ' + expectToHaveError "can't contain spaces" it "can't have ~ anywhere", -> - @name.val('~foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '~'") - @name.val('foo~bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '~'") - @name.val('foo~').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '~'") + fillNameWith '~foo' + expectToHaveError "can't contain '~'" + fillNameWith 'foo~bar' + expectToHaveError "can't contain '~'" + fillNameWith 'foo~' + expectToHaveError "can't contain '~'" it "can't have tilde anwhere", -> - @name.val('~foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '~'") - @name.val('foo~bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '~'") - @name.val('foo~').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '~'") + fillNameWith '~foo' + expectToHaveError "can't contain '~'" + fillNameWith 'foo~bar' + expectToHaveError "can't contain '~'" + fillNameWith 'foo~' + expectToHaveError "can't contain '~'" it "can't have caret anywhere", -> - @name.val('^foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '^'") - @name.val('foo^bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '^'") - @name.val('foo^').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '^'") + fillNameWith '^foo' + expectToHaveError "can't contain '^'" + fillNameWith 'foo^bar' + expectToHaveError "can't contain '^'" + fillNameWith 'foo^' + expectToHaveError "can't contain '^'" it "can't have : anywhere", -> - @name.val(':foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain ':'") - @name.val('foo:bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain ':'") - @name.val(':foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain ':'") + fillNameWith ':foo' + expectToHaveError "can't contain ':'" + fillNameWith 'foo:bar' + expectToHaveError "can't contain ':'" + fillNameWith ':foo' + expectToHaveError "can't contain ':'" it "can't have question mark anywhere", -> - @name.val('?foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '?'") - @name.val('foo?bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '?'") - @name.val('foo?').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '?'") + fillNameWith '?foo' + expectToHaveError "can't contain '?'" + fillNameWith 'foo?bar' + expectToHaveError "can't contain '?'" + fillNameWith 'foo?' + expectToHaveError "can't contain '?'" it "can't have asterisk anywhere", -> - @name.val('*foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '*'") - @name.val('foo*bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '*'") - @name.val('foo*').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '*'") + fillNameWith '*foo' + expectToHaveError "can't contain '*'" + fillNameWith 'foo*bar' + expectToHaveError "can't contain '*'" + fillNameWith 'foo*' + expectToHaveError "can't contain '*'" it "can't have open bracket anywhere", -> - @name.val('[foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '['") - @name.val('foo[bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '['") - @name.val('foo[').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '['") + fillNameWith '[foo' + expectToHaveError "can't contain '['" + fillNameWith 'foo[bar' + expectToHaveError "can't contain '['" + fillNameWith 'foo[' + expectToHaveError "can't contain '['" it "can't have a backslash anywhere", -> - @name.val('\\foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '\\'") - @name.val('foo\\bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '\\'") - @name.val('foo\\').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '\\'") + fillNameWith '\\foo' + expectToHaveError "can't contain '\\'" + fillNameWith 'foo\\bar' + expectToHaveError "can't contain '\\'" + fillNameWith 'foo\\' + expectToHaveError "can't contain '\\'" it "can't contain a sequence @{ anywhere", -> - @name.val('@{foo').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '@{'") - @name.val('foo@{bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '@{'") - @name.val('foo@{').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '@{'") + fillNameWith '@{foo' + expectToHaveError "can't contain '@{'" + fillNameWith 'foo@{bar' + expectToHaveError "can't contain '@{'" + fillNameWith 'foo@{' + expectToHaveError "can't contain '@{'" it "can't have consecutive slashes", -> - @name.val('foo//bar').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain consecutive slashes") + fillNameWith 'foo//bar' + expectToHaveError "can't contain consecutive slashes" it "can't end with a slash", -> - @name.val('foo/').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't end in '/'") + fillNameWith 'foo/' + expectToHaveError "can't end in '/'" it "can't end with a dot", -> - @name.val('foo.').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't end in '.'") + fillNameWith 'foo.' + expectToHaveError "can't end in '.'" it "can't end with .lock", -> - @name.val('foo.lock').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't end in '.lock'") + fillNameWith 'foo.lock' + expectToHaveError "can't end in '.lock'" it "can't be the single character @", -> - @name.val('@').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't be '@'") + fillNameWith '@' + expectToHaveError "can't be '@'" it "concatenates all error messages", -> - @name.val('/foo bar?~.').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't start with '/', can't contain spaces, '?', '~', can't end in '.'") + fillNameWith '/foo bar?~.' + expectToHaveError "can't start with '/', can't contain spaces, '?', '~', can't end in '.'" it "doesn't duplicate error messages", -> - @name.val('?foo?bar?zoo?').trigger('blur') - expect($('.js-branch-name-error span').text()).toEqual("can't contain '?'") + fillNameWith '?foo?bar?zoo?' + expectToHaveError "can't contain '?'" it "removes the error message when is a valid name", -> - @name.val('foo?bar').trigger('blur') + fillNameWith 'foo?bar' expect($('.js-branch-name-error span').length).toEqual(1) - @name.val('foobar').trigger('blur') + fillNameWith 'foobar' expect($('.js-branch-name-error span').length).toEqual(0) it "can have dashes anywhere", -> - @name.val('-foo-bar-zoo-').trigger('blur') + fillNameWith '-foo-bar-zoo-' expect($('.js-branch-name-error span').length).toEqual(0) it "can have underscores anywhere", -> - @name.val('_foo_bar_zoo_').trigger('blur') + fillNameWith '_foo_bar_zoo_' expect($('.js-branch-name-error span').length).toEqual(0) it "can have numbers anywhere", -> - @name.val('1foo2bar3zoo4').trigger('blur') + fillNameWith '1foo2bar3zoo4' expect($('.js-branch-name-error span').length).toEqual(0) it "can be only letters", -> - @name.val('foo').trigger('blur') + fillNameWith 'foo' expect($('.js-branch-name-error span').length).toEqual(0) |