gitlab-org--gitlab-foss/spec/frontend/new_branch_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

206 lines
6 KiB
JavaScript
Raw Normal View History

import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
2017-11-20 15:28:29 -05:00
import NewBranchForm from '~/new_branch_form';
2016-07-24 16:45:11 -04:00
describe('Branch', () => {
let testContext;
beforeEach(() => {
testContext = {};
});
describe('create a new branch', () => {
2018-10-17 03:21:28 -04:00
function fillNameWith(value) {
document.querySelector('.js-branch-name').value = value;
const event = new CustomEvent('blur');
document.querySelector('.js-branch-name').dispatchEvent(event);
2018-10-17 03:21:28 -04:00
}
function expectToHaveError(error) {
expect(document.querySelector('.js-branch-name-error').textContent).toEqual(error);
2018-10-17 03:21:28 -04:00
}
beforeEach(() => {
loadHTMLFixture('branches/new_branch.html');
document.querySelector('form').addEventListener('submit', (e) => e.preventDefault());
testContext.form = new NewBranchForm(document.querySelector('.js-create-branch-form'), []);
2018-10-17 03:13:26 -04:00
});
afterEach(() => {
resetHTMLFixture();
});
it("can't start with a dot", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('.foo');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't start with '.'");
2018-10-17 03:13:26 -04:00
});
it("can't start with a slash", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('/foo');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't start with '/'");
2018-10-17 03:13:26 -04:00
});
it("can't have two consecutive dots", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('foo..bar');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain '..'");
2018-10-17 03:13:26 -04:00
});
it("can't have spaces anywhere", () => {
2018-10-17 03:13:26 -04:00
fillNameWith(' foo');
expectToHaveError("can't contain spaces");
fillNameWith('foo bar');
expectToHaveError("can't contain spaces");
fillNameWith('foo ');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain spaces");
2018-10-17 03:13:26 -04:00
});
it("can't have ~ anywhere", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('~foo');
expectToHaveError("can't contain '~'");
fillNameWith('foo~bar');
expectToHaveError("can't contain '~'");
fillNameWith('foo~');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain '~'");
2018-10-17 03:13:26 -04:00
});
it("can't have tilde anwhere", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('~foo');
expectToHaveError("can't contain '~'");
fillNameWith('foo~bar');
expectToHaveError("can't contain '~'");
fillNameWith('foo~');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain '~'");
2018-10-17 03:13:26 -04:00
});
it("can't have caret anywhere", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('^foo');
expectToHaveError("can't contain '^'");
fillNameWith('foo^bar');
expectToHaveError("can't contain '^'");
fillNameWith('foo^');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain '^'");
2018-10-17 03:13:26 -04:00
});
it("can't have : anywhere", () => {
2018-10-17 03:13:26 -04:00
fillNameWith(':foo');
expectToHaveError("can't contain ':'");
fillNameWith('foo:bar');
expectToHaveError("can't contain ':'");
fillNameWith(':foo');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain ':'");
2018-10-17 03:13:26 -04:00
});
it("can't have question mark anywhere", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('?foo');
expectToHaveError("can't contain '?'");
fillNameWith('foo?bar');
expectToHaveError("can't contain '?'");
fillNameWith('foo?');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain '?'");
2018-10-17 03:13:26 -04:00
});
it("can't have asterisk anywhere", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('*foo');
expectToHaveError("can't contain '*'");
fillNameWith('foo*bar');
expectToHaveError("can't contain '*'");
fillNameWith('foo*');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain '*'");
2018-10-17 03:13:26 -04:00
});
it("can't have open bracket anywhere", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('[foo');
expectToHaveError("can't contain '['");
fillNameWith('foo[bar');
expectToHaveError("can't contain '['");
fillNameWith('foo[');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain '['");
2018-10-17 03:13:26 -04:00
});
it("can't have a backslash anywhere", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('\\foo');
expectToHaveError("can't contain '\\'");
fillNameWith('foo\\bar');
expectToHaveError("can't contain '\\'");
fillNameWith('foo\\');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain '\\'");
2018-10-17 03:13:26 -04:00
});
it("can't contain a sequence @{ anywhere", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('@{foo');
expectToHaveError("can't contain '@{'");
fillNameWith('foo@{bar');
expectToHaveError("can't contain '@{'");
fillNameWith('foo@{');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain '@{'");
2018-10-17 03:13:26 -04:00
});
it("can't have consecutive slashes", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('foo//bar');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain consecutive slashes");
2018-10-17 03:13:26 -04:00
});
it("can't end with a slash", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('foo/');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't end in '/'");
2018-10-17 03:13:26 -04:00
});
it("can't end with a dot", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('foo.');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't end in '.'");
2018-10-17 03:13:26 -04:00
});
it("can't end with .lock", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('foo.lock');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't end in '.lock'");
2018-10-17 03:13:26 -04:00
});
it("can't be the single character @", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('@');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't be '@'");
2018-10-17 03:13:26 -04:00
});
it('concatenates all error messages', () => {
2018-10-17 03:13:26 -04:00
fillNameWith('/foo bar?~.');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't start with '/', can't contain spaces, '?', '~', can't end in '.'");
2018-10-17 03:13:26 -04:00
});
it("doesn't duplicate error messages", () => {
2018-10-17 03:13:26 -04:00
fillNameWith('?foo?bar?zoo?');
2018-10-17 03:21:28 -04:00
expectToHaveError("can't contain '?'");
2018-10-17 03:13:26 -04:00
});
it('removes the error message when is a valid name', () => {
2018-10-17 03:13:26 -04:00
fillNameWith('foo?bar');
2018-10-09 14:03:09 -04:00
expect(document.querySelector('.js-branch-name-error').textContent).not.toEqual('');
2018-10-17 03:13:26 -04:00
fillNameWith('foobar');
2018-10-09 14:03:09 -04:00
expect(document.querySelector('.js-branch-name-error').textContent).toEqual('');
2018-10-17 03:13:26 -04:00
});
it('can have dashes anywhere', () => {
2018-10-17 03:13:26 -04:00
fillNameWith('-foo-bar-zoo-');
2018-10-09 14:03:09 -04:00
expect(document.querySelector('.js-branch-name-error').textContent).toEqual('');
2018-10-17 03:13:26 -04:00
});
it('can have underscores anywhere', () => {
2018-10-17 03:13:26 -04:00
fillNameWith('_foo_bar_zoo_');
2018-10-09 14:03:09 -04:00
expect(document.querySelector('.js-branch-name-error').textContent).toEqual('');
2018-10-17 03:13:26 -04:00
});
it('can have numbers anywhere', () => {
2018-10-17 03:13:26 -04:00
fillNameWith('1foo2bar3zoo4');
2018-10-09 14:03:09 -04:00
expect(document.querySelector('.js-branch-name-error').textContent).toEqual('');
2018-10-17 03:13:26 -04:00
});
2018-10-09 14:03:09 -04:00
it('can be only letters', () => {
2018-10-17 03:13:26 -04:00
fillNameWith('foo');
2018-10-09 14:03:09 -04:00
expect(document.querySelector('.js-branch-name-error').textContent).toEqual('');
2016-07-24 16:45:11 -04:00
});
});
2018-10-17 03:13:26 -04:00
});