debian-mirror-gitlab/spec/javascripts/new_branch_spec.js

200 lines
5.8 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import NewBranchForm from '~/new_branch_form';
2016-09-13 17:45:13 +05:30
2018-12-13 13:39:08 +05:30
describe('Branch', function() {
describe('create a new branch', function() {
2019-05-18 00:54:41 +05:30
preloadFixtures('branches/new_branch.html');
2018-12-13 13:39:08 +05:30
function fillNameWith(value) {
$('.js-branch-name')
.val(value)
.trigger('blur');
}
function expectToHaveError(error) {
expect($('.js-branch-name-error span').text()).toEqual(error);
}
beforeEach(function() {
2019-05-18 00:54:41 +05:30
loadFixtures('branches/new_branch.html');
2018-12-13 13:39:08 +05:30
$('form').on('submit', function(e) {
return e.preventDefault();
2016-09-13 17:45:13 +05:30
});
2018-12-13 13:39:08 +05:30
this.form = new NewBranchForm($('.js-create-branch-form'), []);
});
it("can't start with a dot", function() {
fillNameWith('.foo');
expectToHaveError("can't start with '.'");
});
it("can't start with a slash", function() {
fillNameWith('/foo');
expectToHaveError("can't start with '/'");
});
it("can't have two consecutive dots", function() {
fillNameWith('foo..bar');
expectToHaveError("can't contain '..'");
});
it("can't have spaces anywhere", function() {
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", function() {
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", function() {
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", function() {
fillNameWith('^foo');
expectToHaveError("can't contain '^'");
fillNameWith('foo^bar');
expectToHaveError("can't contain '^'");
fillNameWith('foo^');
expectToHaveError("can't contain '^'");
});
it("can't have : anywhere", function() {
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", function() {
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", function() {
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", function() {
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", function() {
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", function() {
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", function() {
fillNameWith('foo//bar');
expectToHaveError("can't contain consecutive slashes");
});
it("can't end with a slash", function() {
fillNameWith('foo/');
expectToHaveError("can't end in '/'");
});
it("can't end with a dot", function() {
fillNameWith('foo.');
expectToHaveError("can't end in '.'");
});
it("can't end with .lock", function() {
fillNameWith('foo.lock');
expectToHaveError("can't end in '.lock'");
});
it("can't be the single character @", function() {
fillNameWith('@');
expectToHaveError("can't be '@'");
});
it('concatenates all error messages', function() {
fillNameWith('/foo bar?~.');
expectToHaveError("can't start with '/', can't contain spaces, '?', '~', can't end in '.'");
});
it("doesn't duplicate error messages", function() {
fillNameWith('?foo?bar?zoo?');
expectToHaveError("can't contain '?'");
});
it('removes the error message when is a valid name', function() {
fillNameWith('foo?bar');
expect($('.js-branch-name-error span').length).toEqual(1);
fillNameWith('foobar');
expect($('.js-branch-name-error span').length).toEqual(0);
});
it('can have dashes anywhere', function() {
fillNameWith('-foo-bar-zoo-');
expect($('.js-branch-name-error span').length).toEqual(0);
});
it('can have underscores anywhere', function() {
fillNameWith('_foo_bar_zoo_');
expect($('.js-branch-name-error span').length).toEqual(0);
});
it('can have numbers anywhere', function() {
fillNameWith('1foo2bar3zoo4');
expect($('.js-branch-name-error span').length).toEqual(0);
});
it('can be only letters', function() {
fillNameWith('foo');
expect($('.js-branch-name-error span').length).toEqual(0);
2016-09-13 17:45:13 +05:30
});
});
2018-12-13 13:39:08 +05:30
});