new_branch_spec.js 5.8 KB
Newer Older
1
import $ from 'jquery';
F
Filipa Lacerda 已提交
2
import NewBranchForm from '~/new_branch_form';
F
Fatih Acet 已提交
3

M
Mike Greiling 已提交
4 5
describe('Branch', function() {
  describe('create a new branch', function() {
6
    preloadFixtures('branches/new_branch.html.raw');
M
Mike Greiling 已提交
7 8 9

    function fillNameWith(value) {
      $('.js-branch-name')
M
Mike Greiling 已提交
10 11
        .val(value)
        .trigger('blur');
M
Mike Greiling 已提交
12 13 14
    }

    function expectToHaveError(error) {
M
Mike Greiling 已提交
15
      expect($('.js-branch-name-error span').text()).toEqual(error);
M
Mike Greiling 已提交
16 17
    }

M
Mike Greiling 已提交
18
    beforeEach(function() {
19
      loadFixtures('branches/new_branch.html.raw');
M
Mike Greiling 已提交
20 21 22
      $('form').on('submit', function(e) {
        return e.preventDefault();
      });
M
Mike Greiling 已提交
23
      this.form = new NewBranchForm($('.js-create-branch-form'), []);
M
Mike Greiling 已提交
24
    });
25

M
Mike Greiling 已提交
26 27
    it("can't start with a dot", function() {
      fillNameWith('.foo');
M
Mike Greiling 已提交
28
      expectToHaveError("can't start with '.'");
M
Mike Greiling 已提交
29
    });
30

M
Mike Greiling 已提交
31 32
    it("can't start with a slash", function() {
      fillNameWith('/foo');
M
Mike Greiling 已提交
33
      expectToHaveError("can't start with '/'");
M
Mike Greiling 已提交
34
    });
35

M
Mike Greiling 已提交
36 37
    it("can't have two consecutive dots", function() {
      fillNameWith('foo..bar');
M
Mike Greiling 已提交
38
      expectToHaveError("can't contain '..'");
M
Mike Greiling 已提交
39
    });
40

M
Mike Greiling 已提交
41 42 43 44 45 46
    it("can't have spaces anywhere", function() {
      fillNameWith(' foo');
      expectToHaveError("can't contain spaces");
      fillNameWith('foo bar');
      expectToHaveError("can't contain spaces");
      fillNameWith('foo ');
M
Mike Greiling 已提交
47
      expectToHaveError("can't contain spaces");
M
Mike Greiling 已提交
48
    });
49

M
Mike Greiling 已提交
50 51 52 53 54 55
    it("can't have ~ anywhere", function() {
      fillNameWith('~foo');
      expectToHaveError("can't contain '~'");
      fillNameWith('foo~bar');
      expectToHaveError("can't contain '~'");
      fillNameWith('foo~');
M
Mike Greiling 已提交
56
      expectToHaveError("can't contain '~'");
M
Mike Greiling 已提交
57
    });
58

M
Mike Greiling 已提交
59 60 61 62 63 64
    it("can't have tilde anwhere", function() {
      fillNameWith('~foo');
      expectToHaveError("can't contain '~'");
      fillNameWith('foo~bar');
      expectToHaveError("can't contain '~'");
      fillNameWith('foo~');
M
Mike Greiling 已提交
65
      expectToHaveError("can't contain '~'");
M
Mike Greiling 已提交
66
    });
67

M
Mike Greiling 已提交
68 69 70 71 72 73
    it("can't have caret anywhere", function() {
      fillNameWith('^foo');
      expectToHaveError("can't contain '^'");
      fillNameWith('foo^bar');
      expectToHaveError("can't contain '^'");
      fillNameWith('foo^');
M
Mike Greiling 已提交
74
      expectToHaveError("can't contain '^'");
M
Mike Greiling 已提交
75
    });
76

M
Mike Greiling 已提交
77 78 79 80 81 82
    it("can't have : anywhere", function() {
      fillNameWith(':foo');
      expectToHaveError("can't contain ':'");
      fillNameWith('foo:bar');
      expectToHaveError("can't contain ':'");
      fillNameWith(':foo');
M
Mike Greiling 已提交
83
      expectToHaveError("can't contain ':'");
M
Mike Greiling 已提交
84
    });
85

M
Mike Greiling 已提交
86 87 88 89 90 91
    it("can't have question mark anywhere", function() {
      fillNameWith('?foo');
      expectToHaveError("can't contain '?'");
      fillNameWith('foo?bar');
      expectToHaveError("can't contain '?'");
      fillNameWith('foo?');
M
Mike Greiling 已提交
92
      expectToHaveError("can't contain '?'");
M
Mike Greiling 已提交
93
    });
94

M
Mike Greiling 已提交
95 96 97 98 99 100
    it("can't have asterisk anywhere", function() {
      fillNameWith('*foo');
      expectToHaveError("can't contain '*'");
      fillNameWith('foo*bar');
      expectToHaveError("can't contain '*'");
      fillNameWith('foo*');
M
Mike Greiling 已提交
101
      expectToHaveError("can't contain '*'");
M
Mike Greiling 已提交
102
    });
103

M
Mike Greiling 已提交
104 105 106 107 108 109
    it("can't have open bracket anywhere", function() {
      fillNameWith('[foo');
      expectToHaveError("can't contain '['");
      fillNameWith('foo[bar');
      expectToHaveError("can't contain '['");
      fillNameWith('foo[');
M
Mike Greiling 已提交
110
      expectToHaveError("can't contain '['");
M
Mike Greiling 已提交
111
    });
112

M
Mike Greiling 已提交
113 114 115 116 117 118
    it("can't have a backslash anywhere", function() {
      fillNameWith('\\foo');
      expectToHaveError("can't contain '\\'");
      fillNameWith('foo\\bar');
      expectToHaveError("can't contain '\\'");
      fillNameWith('foo\\');
M
Mike Greiling 已提交
119
      expectToHaveError("can't contain '\\'");
M
Mike Greiling 已提交
120
    });
121

M
Mike Greiling 已提交
122 123 124 125 126 127
    it("can't contain a sequence @{ anywhere", function() {
      fillNameWith('@{foo');
      expectToHaveError("can't contain '@{'");
      fillNameWith('foo@{bar');
      expectToHaveError("can't contain '@{'");
      fillNameWith('foo@{');
M
Mike Greiling 已提交
128
      expectToHaveError("can't contain '@{'");
M
Mike Greiling 已提交
129
    });
130

M
Mike Greiling 已提交
131 132
    it("can't have consecutive slashes", function() {
      fillNameWith('foo//bar');
M
Mike Greiling 已提交
133
      expectToHaveError("can't contain consecutive slashes");
M
Mike Greiling 已提交
134
    });
135

M
Mike Greiling 已提交
136 137
    it("can't end with a slash", function() {
      fillNameWith('foo/');
M
Mike Greiling 已提交
138
      expectToHaveError("can't end in '/'");
M
Mike Greiling 已提交
139
    });
140

M
Mike Greiling 已提交
141 142
    it("can't end with a dot", function() {
      fillNameWith('foo.');
M
Mike Greiling 已提交
143
      expectToHaveError("can't end in '.'");
M
Mike Greiling 已提交
144
    });
145

M
Mike Greiling 已提交
146 147
    it("can't end with .lock", function() {
      fillNameWith('foo.lock');
M
Mike Greiling 已提交
148
      expectToHaveError("can't end in '.lock'");
M
Mike Greiling 已提交
149
    });
150

M
Mike Greiling 已提交
151 152
    it("can't be the single character @", function() {
      fillNameWith('@');
M
Mike Greiling 已提交
153
      expectToHaveError("can't be '@'");
M
Mike Greiling 已提交
154
    });
155

M
Mike Greiling 已提交
156 157
    it('concatenates all error messages', function() {
      fillNameWith('/foo bar?~.');
M
Mike Greiling 已提交
158
      expectToHaveError("can't start with '/', can't contain spaces, '?', '~', can't end in '.'");
M
Mike Greiling 已提交
159
    });
160

M
Mike Greiling 已提交
161 162
    it("doesn't duplicate error messages", function() {
      fillNameWith('?foo?bar?zoo?');
M
Mike Greiling 已提交
163
      expectToHaveError("can't contain '?'");
M
Mike Greiling 已提交
164
    });
165

M
Mike Greiling 已提交
166 167
    it('removes the error message when is a valid name', function() {
      fillNameWith('foo?bar');
168

M
Mike Greiling 已提交
169 170
      expect($('.js-branch-name-error span').length).toEqual(1);
      fillNameWith('foobar');
171

M
Mike Greiling 已提交
172 173
      expect($('.js-branch-name-error span').length).toEqual(0);
    });
174

M
Mike Greiling 已提交
175 176
    it('can have dashes anywhere', function() {
      fillNameWith('-foo-bar-zoo-');
177

M
Mike Greiling 已提交
178 179
      expect($('.js-branch-name-error span').length).toEqual(0);
    });
180

M
Mike Greiling 已提交
181 182
    it('can have underscores anywhere', function() {
      fillNameWith('_foo_bar_zoo_');
183

M
Mike Greiling 已提交
184 185
      expect($('.js-branch-name-error span').length).toEqual(0);
    });
186

M
Mike Greiling 已提交
187 188
    it('can have numbers anywhere', function() {
      fillNameWith('1foo2bar3zoo4');
189

M
Mike Greiling 已提交
190 191
      expect($('.js-branch-name-error span').length).toEqual(0);
    });
192

M
Mike Greiling 已提交
193 194
    it('can be only letters', function() {
      fillNameWith('foo');
195

M
Mike Greiling 已提交
196
      expect($('.js-branch-name-error span').length).toEqual(0);
F
Fatih Acet 已提交
197 198
    });
  });
M
Mike Greiling 已提交
199
});