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
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
describe('Branch', () => {
|
|
|
|
let testContext;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
testContext = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('create a new branch', () => {
|
2019-07-07 11:18:12 +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);
|
|
|
|
}
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
beforeEach(() => {
|
2019-07-07 11:18:12 +05:30
|
|
|
loadFixtures('branches/new_branch.html');
|
2020-03-09 13:42:32 +05:30
|
|
|
$('form').on('submit', e => e.preventDefault());
|
|
|
|
testContext.form = new NewBranchForm($('.js-create-branch-form'), []);
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't start with a dot", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('.foo');
|
|
|
|
expectToHaveError("can't start with '.'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't start with a slash", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('/foo');
|
|
|
|
expectToHaveError("can't start with '/'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't have two consecutive dots", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('foo..bar');
|
|
|
|
expectToHaveError("can't contain '..'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't have spaces anywhere", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith(' foo');
|
|
|
|
expectToHaveError("can't contain spaces");
|
|
|
|
fillNameWith('foo bar');
|
|
|
|
expectToHaveError("can't contain spaces");
|
|
|
|
fillNameWith('foo ');
|
|
|
|
expectToHaveError("can't contain spaces");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't have ~ anywhere", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('~foo');
|
|
|
|
expectToHaveError("can't contain '~'");
|
|
|
|
fillNameWith('foo~bar');
|
|
|
|
expectToHaveError("can't contain '~'");
|
|
|
|
fillNameWith('foo~');
|
|
|
|
expectToHaveError("can't contain '~'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't have tilde anwhere", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('~foo');
|
|
|
|
expectToHaveError("can't contain '~'");
|
|
|
|
fillNameWith('foo~bar');
|
|
|
|
expectToHaveError("can't contain '~'");
|
|
|
|
fillNameWith('foo~');
|
|
|
|
expectToHaveError("can't contain '~'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't have caret anywhere", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('^foo');
|
|
|
|
expectToHaveError("can't contain '^'");
|
|
|
|
fillNameWith('foo^bar');
|
|
|
|
expectToHaveError("can't contain '^'");
|
|
|
|
fillNameWith('foo^');
|
|
|
|
expectToHaveError("can't contain '^'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't have : anywhere", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith(':foo');
|
|
|
|
expectToHaveError("can't contain ':'");
|
|
|
|
fillNameWith('foo:bar');
|
|
|
|
expectToHaveError("can't contain ':'");
|
|
|
|
fillNameWith(':foo');
|
|
|
|
expectToHaveError("can't contain ':'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't have question mark anywhere", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('?foo');
|
|
|
|
expectToHaveError("can't contain '?'");
|
|
|
|
fillNameWith('foo?bar');
|
|
|
|
expectToHaveError("can't contain '?'");
|
|
|
|
fillNameWith('foo?');
|
|
|
|
expectToHaveError("can't contain '?'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't have asterisk anywhere", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('*foo');
|
|
|
|
expectToHaveError("can't contain '*'");
|
|
|
|
fillNameWith('foo*bar');
|
|
|
|
expectToHaveError("can't contain '*'");
|
|
|
|
fillNameWith('foo*');
|
|
|
|
expectToHaveError("can't contain '*'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't have open bracket anywhere", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('[foo');
|
|
|
|
expectToHaveError("can't contain '['");
|
|
|
|
fillNameWith('foo[bar');
|
|
|
|
expectToHaveError("can't contain '['");
|
|
|
|
fillNameWith('foo[');
|
|
|
|
expectToHaveError("can't contain '['");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't have a backslash anywhere", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('\\foo');
|
|
|
|
expectToHaveError("can't contain '\\'");
|
|
|
|
fillNameWith('foo\\bar');
|
|
|
|
expectToHaveError("can't contain '\\'");
|
|
|
|
fillNameWith('foo\\');
|
|
|
|
expectToHaveError("can't contain '\\'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't contain a sequence @{ anywhere", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('@{foo');
|
|
|
|
expectToHaveError("can't contain '@{'");
|
|
|
|
fillNameWith('foo@{bar');
|
|
|
|
expectToHaveError("can't contain '@{'");
|
|
|
|
fillNameWith('foo@{');
|
|
|
|
expectToHaveError("can't contain '@{'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't have consecutive slashes", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('foo//bar');
|
|
|
|
expectToHaveError("can't contain consecutive slashes");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't end with a slash", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('foo/');
|
|
|
|
expectToHaveError("can't end in '/'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't end with a dot", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('foo.');
|
|
|
|
expectToHaveError("can't end in '.'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't end with .lock", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('foo.lock');
|
|
|
|
expectToHaveError("can't end in '.lock'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("can't be the single character @", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('@');
|
|
|
|
expectToHaveError("can't be '@'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it('concatenates all error messages', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('/foo bar?~.');
|
|
|
|
expectToHaveError("can't start with '/', can't contain spaces, '?', '~', can't end in '.'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it("doesn't duplicate error messages", () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('?foo?bar?zoo?');
|
|
|
|
expectToHaveError("can't contain '?'");
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it('removes the error message when is a valid name', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('foo?bar');
|
|
|
|
|
|
|
|
expect($('.js-branch-name-error span').length).toEqual(1);
|
|
|
|
fillNameWith('foobar');
|
|
|
|
|
|
|
|
expect($('.js-branch-name-error span').length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it('can have dashes anywhere', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('-foo-bar-zoo-');
|
|
|
|
|
|
|
|
expect($('.js-branch-name-error span').length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it('can have underscores anywhere', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('_foo_bar_zoo_');
|
|
|
|
|
|
|
|
expect($('.js-branch-name-error span').length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it('can have numbers anywhere', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
fillNameWith('1foo2bar3zoo4');
|
|
|
|
|
|
|
|
expect($('.js-branch-name-error span').length).toEqual(0);
|
|
|
|
});
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
it('can be only letters', () => {
|
2018-12-13 13:39:08 +05:30
|
|
|
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
|
|
|
});
|