Issues (72)

tests/call.form.test.js (19 issues)

Labels
Severity
1
const jq = require('jquery');
2
const {
3
    cmd: { node },
4
    utils: { dom, form, types },
5
    parser: { query },
6
} = require('../dist/jaxon.module');
7
8
// Init the selector library.
9
query.jq = jq;
0 ignored issues
show
The variable query seems to be never declared. If this is a global, consider adding a /** global: query */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
10
11
test('Test empty form', () => {
12
    document.body.innerHTML = `
13
    <div id="wrapper">
14
      <form id="test_form">
15
      </form>
16
    </div>`;
17
18
    const formValues = form.getValues('test_form');
0 ignored issues
show
The variable form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
19
20
    expect(types.of(formValues)).toBe('object');
0 ignored issues
show
The variable types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
21
    expect(Object.keys(formValues).length).toBe(0);
22
});
23
24
test('Test form without id', () => {
25
  document.body.innerHTML = `
26
  <div id="wrapper">
27
    <form>
28
    </form>
29
  </div>`;
30
31
  const formValues = form.getValues('test_form');
0 ignored issues
show
The variable form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
32
33
  expect(types.of(formValues)).toBe('object');
0 ignored issues
show
The variable types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
34
  expect(Object.keys(formValues).length).toBe(0);
35
});
36
37
test('Test form with multiple select', () => {
38
  // Fix: https://github.com/jaxon-php/jaxon-core/issues/128
39
  document.body.innerHTML = `
40
  <div id="wrapper">
41
    <form id="test_form">
42
      <select multiple="multiple" name="multiselect">
43
        <option value="1" selected>Value 1</option>
44
        <option value="2" selected>Value 2</option>
45
        <option value="3">Value 3</option>
46
      </select>
47
    </form>
48
  </div>`;
49
50
  const formValues = form.getValues('test_form');
0 ignored issues
show
The variable form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
51
52
  expect(types.of(formValues)).toBe('object');
0 ignored issues
show
The variable types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
53
  expect(types.of(formValues.multiselect)).toBe('array');
54
  expect(formValues.multiselect.length).toBe(2);
55
  expect(formValues.multiselect[0]).toBe('1');
56
  expect(formValues.multiselect[1]).toBe('2');
57
});
58
59
test('Test assign command on multiple select', () => {
60
    // Fix: https://github.com/jaxon-php/jaxon-js/issues/29
61
    document.body.innerHTML = `
62
    <div id="wrapper">
63
      <form id="test_form">
64
        <select id="multiselect" multiple="multiple" name="multiselect">
65
          <option value="1">Value 1</option>
66
          <option value="2">Value 2</option>
67
          <option value="3">Value 3</option>
68
        </select>
69
      </form>
70
    </div>`;
71
72
    const formValues0 = form.getValues('test_form');
0 ignored issues
show
The variable form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
73
74
    expect(types.of(formValues0)).toBe('object');
0 ignored issues
show
The variable types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
75
    expect(types.of(formValues0.multiselect)).toBe('array');
76
    expect(formValues0.multiselect.length).toBe(0);
77
78
    node.assign({
0 ignored issues
show
The variable node seems to be never declared. If this is a global, consider adding a /** global: node */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
79
        attr: 'options[0].selected',
80
        value: 'true',
81
    }, {
82
        target: dom.$('multiselect'),
0 ignored issues
show
The variable dom seems to be never declared. If this is a global, consider adding a /** global: dom */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
83
    });
84
    const formValues1 = form.getValues('test_form');
85
86
    expect(types.of(formValues1)).toBe('object');
87
    expect(types.of(formValues1.multiselect)).toBe('array');
88
    expect(formValues1.multiselect.length).toBe(1);
89
    expect(formValues1.multiselect[0]).toBe('1');
90
91
    node.assign({
92
        attr: 'options[1].selected',
93
        value: 'true',
94
    }, {
95
        target: dom.$('multiselect'),
96
    });
97
    const formValues2 = form.getValues('test_form');
98
99
    expect(types.of(formValues2)).toBe('object');
100
    expect(types.of(formValues2.multiselect)).toBe('array');
101
    expect(formValues2.multiselect.length).toBe(2);
102
    expect(formValues2.multiselect[0]).toBe('1');
103
    expect(formValues2.multiselect[1]).toBe('2');
104
});
105
106
test('Test form with names into brackets', () => {
107
  document.body.innerHTML = `
108
  <div id="wrapper">
109
    <form id="test_form">
110
      <input name="user[name]" value="John Doe" />
111
      <input name="user[email]" value="[email protected]" />
112
      <input name="user[website]" value="john.doe.website.com" />
113
    </form>
114
  </div>`;
115
116
  const formValues = form.getValues('test_form');
0 ignored issues
show
The variable form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
117
118
  expect(types.of(formValues)).toBe('object');
0 ignored issues
show
The variable types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
119
  expect(types.of(formValues.user)).toBe('object');
120
  expect(Object.keys(formValues.user).length).toBe(3);
121
  expect(formValues.user.name).toBe('John Doe');
122
  expect(formValues.user.email).toBe('[email protected]');
123
  expect(formValues.user.website).toBe('john.doe.website.com');
124
});
125
126
test('Test form with names into multiple brackets', () => {
127
  document.body.innerHTML = `
128
  <div id="wrapper">
129
    <form id="test_form">
130
      <input name="user[name][first]" value="John" />
131
      <input name="user[name][last]" value="Doe" />
132
      <input name="user[email]" value="[email protected]" />
133
      <input name="user[website]" value="john.doe.website.com" />
134
    </form>
135
  </div>`;
136
137
  const formValues = form.getValues('test_form');
0 ignored issues
show
The variable form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
138
139
  expect(types.of(formValues)).toBe('object');
0 ignored issues
show
The variable types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
140
  expect(types.of(formValues.user)).toBe('object');
141
  expect(Object.keys(formValues.user).length).toBe(3);
142
  expect(types.of(formValues.user.name)).toBe('object');
143
  expect(Object.keys(formValues.user.name).length).toBe(2);
144
  expect(formValues.user.name.first).toBe('John');
145
  expect(formValues.user.name.last).toBe('Doe');
146
  expect(formValues.user.email).toBe('[email protected]');
147
  expect(formValues.user.website).toBe('john.doe.website.com');
148
});
149
150
test('Test form with array field', () => {
151
  document.body.innerHTML = `
152
  <div id="wrapper">
153
    <form id="test_form">
154
      <input name="values[]" value="First value" />
155
      <input name="values[]" value="Second value" />
156
      <input name="values[]" value="Third value" />
157
    </form>
158
  </div>`;
159
160
  const formValues = form.getValues('test_form');
0 ignored issues
show
The variable form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
161
162
  expect(types.of(formValues)).toBe('object');
0 ignored issues
show
The variable types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
163
  expect(types.of(formValues.values)).toBe('array');
164
  expect(Object.keys(formValues.values).length).toBe(3);
165
  expect(formValues.values[0]).toBe('First value');
166
  expect(formValues.values[1]).toBe('Second value');
167
  expect(formValues.values[2]).toBe('Third value');
168
});
169
170
test('Test form with object with array field', () => {
171
  document.body.innerHTML = `
172
  <div id="wrapper">
173
    <form id="test_form">
174
      <input name="user[roles][]" value="First role" />
175
      <input name="user[perms][]" value="First perm" />
176
      <input name="user[roles][]" value="Second role" />
177
      <input name="user[perms][]" value="Second perm" />
178
    </form>
179
  </div>`;
180
181
  const formValues = form.getValues('test_form');
0 ignored issues
show
The variable form seems to be never declared. If this is a global, consider adding a /** global: form */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
182
183
  expect(types.of(formValues)).toBe('object');
0 ignored issues
show
The variable types seems to be never declared. If this is a global, consider adding a /** global: types */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
184
  expect(types.of(formValues.user)).toBe('object');
185
  expect(types.of(formValues.user.roles)).toBe('array');
186
  expect(types.of(formValues.user.perms)).toBe('array');
187
  expect(Object.keys(formValues.user.roles).length).toBe(2);
188
  expect(Object.keys(formValues.user.perms).length).toBe(2);
189
  expect(formValues.user.roles[0]).toBe('First role');
190
  expect(formValues.user.roles[1]).toBe('Second role');
191
  expect(formValues.user.perms[0]).toBe('First perm');
192
  expect(formValues.user.perms[1]).toBe('Second perm');
193
});
194