whelk-ui 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/package.json +4 -3
- package/playwright.config.ts +79 -0
- package/src/components/add_object/AddObject.vue +40 -0
- package/src/components/card/CardComponent.vue +14 -0
- package/src/components/card/card_footer/CardFooter.vue +19 -0
- package/src/components/card/card_header/CardHeader.vue +16 -0
- package/src/components/check_box/CheckBox.vue +42 -0
- package/src/components/datetime/DatetimeComponent.vue +147 -0
- package/src/components/drop_down/DropDown.vue +104 -0
- package/src/components/drop_down/drop_down_item/DropDownItem.vue +58 -0
- package/src/components/form_group/FormGroup.spec.ts +16 -0
- package/src/components/form_group/FormGroup.vue +19 -0
- package/src/components/number_input/NumberInput.spec.ts +712 -0
- package/src/components/number_input/NumberInput.vue +264 -0
- package/src/components/password_input/PasswordInput.vue +166 -0
- package/src/components/render_error_message/RenderErrorMessage.spec.ts +0 -0
- package/src/components/render_error_message/RenderErrorMessage.vue +32 -0
- package/src/components/switch/SwitchComponent.vue +152 -0
- package/src/components/text_area/TextArea.vue +151 -0
- package/src/components/text_input/TextInput.vue +178 -0
- package/src/components/tool_tip/ToolTip.vue +96 -0
- package/src/utils/enums/ObjectTitleCaseEnums.ts +17 -0
- package/src/utils/enums/ObjectTypeEnums.ts +15 -0
- package/src/utils/interfaces/DocumentItemInterface.ts +5 -0
- package/src/utils/interfaces/DropDownItemsInterface.ts +8 -0
- package/src/utils/interfaces/FolderItemInterface.ts +4 -0
- package/src/utils/interfaces/MenuItemInterface.ts +10 -0
- package/tests/example.spec.ts +18 -0
- package/vite.config.ts +40 -1
|
@@ -0,0 +1,712 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { render } from "vitest-browser-vue";
|
|
3
|
+
import { mount } from "@vue/test-utils";
|
|
4
|
+
import NumberInput from "./NumberInput.vue";
|
|
5
|
+
|
|
6
|
+
// LABEL
|
|
7
|
+
describe("NumberInput - Label testing", async () => {
|
|
8
|
+
test('renders label when input exists - "hello world"', async () => {
|
|
9
|
+
const { getByText } = render(NumberInput, {
|
|
10
|
+
props: {
|
|
11
|
+
label: "hello world",
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Label is being rendered correctly
|
|
16
|
+
await expect.element(getByText("hello world")).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('renders label when input exists - "Number Picker"', async () => {
|
|
20
|
+
const { getByText } = render(NumberInput, {
|
|
21
|
+
props: {
|
|
22
|
+
label: "Number Picker",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Label is being rendered correctly
|
|
27
|
+
await expect.element(getByText("Number Picker")).toBeInTheDocument();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// INCREMENTING ++
|
|
32
|
+
describe("NumberInput - Incrementing", async () => {
|
|
33
|
+
test("counters increase from 0 to 1 when increase is clicked", async () => {
|
|
34
|
+
const wrapper = mount(NumberInput, {
|
|
35
|
+
props: {
|
|
36
|
+
label: "Test Number",
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Assert input value is default 0
|
|
41
|
+
expect(wrapper.find("input").element.value).toBe("0");
|
|
42
|
+
|
|
43
|
+
// Find the + button
|
|
44
|
+
const buttons = wrapper.findAll("button");
|
|
45
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
46
|
+
buttonWrapper.text().includes("+"),
|
|
47
|
+
)[0];
|
|
48
|
+
|
|
49
|
+
// Click on the + button
|
|
50
|
+
await targetButton?.trigger("click");
|
|
51
|
+
|
|
52
|
+
// Check the value has been increased by 1
|
|
53
|
+
expect(wrapper.find("input").element.value).toBe("1");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("increment to the max value and check button gets disabled", async () => {
|
|
57
|
+
const wrapper = mount(NumberInput, {
|
|
58
|
+
props: {
|
|
59
|
+
label: "Test Number",
|
|
60
|
+
maxValue: 10,
|
|
61
|
+
modelValue: 9,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Assert input value is default 10
|
|
66
|
+
expect(wrapper.find("input").element.value).toBe("9");
|
|
67
|
+
|
|
68
|
+
// Find the + button
|
|
69
|
+
const buttons = wrapper.findAll("button");
|
|
70
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
71
|
+
buttonWrapper.text().includes("+"),
|
|
72
|
+
)[0];
|
|
73
|
+
|
|
74
|
+
// Expect to be disabled
|
|
75
|
+
expect(targetButton?.element.disabled).toBe(false);
|
|
76
|
+
|
|
77
|
+
// Click on the + button
|
|
78
|
+
await targetButton?.trigger("click");
|
|
79
|
+
|
|
80
|
+
// Check the value has changed, and button is disabled
|
|
81
|
+
expect(wrapper.find("input").element.value).toBe("10");
|
|
82
|
+
expect(targetButton?.element.disabled).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("increment button is disabled and will not increment the value", async () => {
|
|
86
|
+
const wrapper = mount(NumberInput, {
|
|
87
|
+
props: {
|
|
88
|
+
label: "Test Number",
|
|
89
|
+
maxValue: 10,
|
|
90
|
+
modelValue: 10,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Assert input value is default 9
|
|
95
|
+
expect(wrapper.find("input").element.value).toBe("10");
|
|
96
|
+
|
|
97
|
+
// Find the + button
|
|
98
|
+
const buttons = wrapper.findAll("button");
|
|
99
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
100
|
+
buttonWrapper.text().includes("+"),
|
|
101
|
+
)[0];
|
|
102
|
+
|
|
103
|
+
// Expect to be disabled
|
|
104
|
+
expect(targetButton?.element.disabled).toBe(true);
|
|
105
|
+
|
|
106
|
+
// Click on the + button
|
|
107
|
+
await targetButton?.trigger("click");
|
|
108
|
+
|
|
109
|
+
// Check the value has not changed
|
|
110
|
+
expect(wrapper.find("input").element.value).toBe("10");
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("increment by 5 units", async () => {
|
|
114
|
+
const wrapper = mount(NumberInput, {
|
|
115
|
+
props: {
|
|
116
|
+
label: "Test Number",
|
|
117
|
+
maxValue: 10,
|
|
118
|
+
modelValue: 0,
|
|
119
|
+
stepIncrement: 5,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Assert input value is default 0
|
|
124
|
+
expect(wrapper.find("input").element.value).toBe("0");
|
|
125
|
+
|
|
126
|
+
// Find the + button
|
|
127
|
+
const buttons = wrapper.findAll("button");
|
|
128
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
129
|
+
buttonWrapper.text().includes("+"),
|
|
130
|
+
)[0];
|
|
131
|
+
|
|
132
|
+
// Click on the + button
|
|
133
|
+
await targetButton?.trigger("click");
|
|
134
|
+
|
|
135
|
+
// Check the value added 5 units
|
|
136
|
+
expect(wrapper.find("input").element.value).toBe("5");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("increment past the maxValue, results should return max value", async () => {
|
|
140
|
+
const wrapper = mount(NumberInput, {
|
|
141
|
+
props: {
|
|
142
|
+
label: "Test Number",
|
|
143
|
+
maxValue: 10,
|
|
144
|
+
modelValue: 0,
|
|
145
|
+
stepIncrement: 15,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Assert input value is default 0
|
|
150
|
+
expect(wrapper.find("input").element.value).toBe("0");
|
|
151
|
+
|
|
152
|
+
// Find the + button
|
|
153
|
+
const buttons = wrapper.findAll("button");
|
|
154
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
155
|
+
buttonWrapper.text().includes("+"),
|
|
156
|
+
)[0];
|
|
157
|
+
|
|
158
|
+
// Click on the + button
|
|
159
|
+
await targetButton?.trigger("click");
|
|
160
|
+
|
|
161
|
+
// Check the value has not changed
|
|
162
|
+
expect(wrapper.find("input").element.value).toBe("10");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("increment by 1 to the max javascript integer value", async () => {
|
|
166
|
+
const wrapper = mount(NumberInput, {
|
|
167
|
+
props: {
|
|
168
|
+
label: "Test Number",
|
|
169
|
+
maxValue: Number.MAX_SAFE_INTEGER,
|
|
170
|
+
modelValue: Number.MAX_SAFE_INTEGER - 1,
|
|
171
|
+
stepIncrement: 1,
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Assert input value is default 0
|
|
176
|
+
expect(wrapper.find("input").element.value).toBe(
|
|
177
|
+
`${Number.MAX_SAFE_INTEGER - 1}`,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// Find the + button
|
|
181
|
+
const buttons = wrapper.findAll("button");
|
|
182
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
183
|
+
buttonWrapper.text().includes("+"),
|
|
184
|
+
)[0];
|
|
185
|
+
|
|
186
|
+
// Click on the + button
|
|
187
|
+
await targetButton?.trigger("click");
|
|
188
|
+
|
|
189
|
+
// Check the value has not changed
|
|
190
|
+
expect(wrapper.find("input").element.value).toBe(
|
|
191
|
+
`${Number.MAX_SAFE_INTEGER}`,
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("increment by 10 PAST the max javascript integer value", async () => {
|
|
196
|
+
const wrapper = mount(NumberInput, {
|
|
197
|
+
props: {
|
|
198
|
+
label: "Test Number",
|
|
199
|
+
maxValue: Number.MAX_SAFE_INTEGER,
|
|
200
|
+
modelValue: Number.MAX_SAFE_INTEGER - 1,
|
|
201
|
+
stepIncrement: 10,
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Assert input value is default 0
|
|
206
|
+
expect(wrapper.find("input").element.value).toBe(
|
|
207
|
+
`${Number.MAX_SAFE_INTEGER - 1}`,
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
// Find the + button
|
|
211
|
+
const buttons = wrapper.findAll("button");
|
|
212
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
213
|
+
buttonWrapper.text().includes("+"),
|
|
214
|
+
)[0];
|
|
215
|
+
|
|
216
|
+
// Click on the + button
|
|
217
|
+
await targetButton?.trigger("click");
|
|
218
|
+
|
|
219
|
+
// Check the value has not changed
|
|
220
|
+
expect(wrapper.find("input").element.value).toBe(
|
|
221
|
+
`${Number.MAX_SAFE_INTEGER}`,
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test("counters increase from 0 to 1 when increase is clicked, even with a -1 step increment", async () => {
|
|
226
|
+
const wrapper = mount(NumberInput, {
|
|
227
|
+
props: {
|
|
228
|
+
label: "Test Number",
|
|
229
|
+
modelValue: 0,
|
|
230
|
+
stepIncrement: -1,
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Assert input value is default 0
|
|
235
|
+
expect(wrapper.find("input").element.value).toBe("0");
|
|
236
|
+
|
|
237
|
+
// Find the + button
|
|
238
|
+
const buttons = wrapper.findAll("button");
|
|
239
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
240
|
+
buttonWrapper.text().includes("+"),
|
|
241
|
+
)[0];
|
|
242
|
+
|
|
243
|
+
// Click on the + button
|
|
244
|
+
await targetButton?.trigger("click");
|
|
245
|
+
|
|
246
|
+
// Check the value has not changed
|
|
247
|
+
expect(wrapper.find("input").element.value).toBe("1");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("counters increase from -10 to -9 when increase is clicked", async () => {
|
|
251
|
+
const wrapper = mount(NumberInput, {
|
|
252
|
+
props: {
|
|
253
|
+
label: "Test Number",
|
|
254
|
+
modelValue: -10,
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// Assert input value is default
|
|
259
|
+
expect(wrapper.find("input").element.value).toBe("-10");
|
|
260
|
+
|
|
261
|
+
// Find the + button
|
|
262
|
+
const buttons = wrapper.findAll("button");
|
|
263
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
264
|
+
buttonWrapper.text().includes("+"),
|
|
265
|
+
)[0];
|
|
266
|
+
|
|
267
|
+
// Click on the + button
|
|
268
|
+
await targetButton?.trigger("click");
|
|
269
|
+
|
|
270
|
+
// Check the value has not changed
|
|
271
|
+
expect(wrapper.find("input").element.value).toBe("-9");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("counters increase from -12 to -10 when increase is clicked, even with a -2 step increment", async () => {
|
|
275
|
+
const wrapper = mount(NumberInput, {
|
|
276
|
+
props: {
|
|
277
|
+
label: "Test Number",
|
|
278
|
+
modelValue: -12,
|
|
279
|
+
stepIncrement: -2,
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// Assert input value is default 0
|
|
284
|
+
expect(wrapper.find("input").element.value).toBe("-12");
|
|
285
|
+
|
|
286
|
+
// Find the + button
|
|
287
|
+
const buttons = wrapper.findAll("button");
|
|
288
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
289
|
+
buttonWrapper.text().includes("+"),
|
|
290
|
+
)[0];
|
|
291
|
+
|
|
292
|
+
// Click on the + button
|
|
293
|
+
await targetButton?.trigger("click");
|
|
294
|
+
|
|
295
|
+
// Check the value has not changed
|
|
296
|
+
expect(wrapper.find("input").element.value).toBe("-10");
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test("we can still increment even when the model value is less than the minimum value. Will instantly pop to minimum number", async () => {
|
|
300
|
+
const wrapper = mount(NumberInput, {
|
|
301
|
+
props: {
|
|
302
|
+
label: "Test Number",
|
|
303
|
+
minValue: -10,
|
|
304
|
+
modelValue: -15,
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// Assert input value is default 0
|
|
309
|
+
expect(wrapper.find("input").element.value).toBe("-15");
|
|
310
|
+
|
|
311
|
+
// Find the + button
|
|
312
|
+
const buttons = wrapper.findAll("button");
|
|
313
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
314
|
+
buttonWrapper.text().includes("+"),
|
|
315
|
+
)[0];
|
|
316
|
+
|
|
317
|
+
// Click on the + button
|
|
318
|
+
await targetButton?.trigger("click");
|
|
319
|
+
|
|
320
|
+
// Check the value has not changed
|
|
321
|
+
expect(wrapper.find("input").element.value).toBe("-10");
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// DECREMENTING ++
|
|
326
|
+
describe("NumberInput - Decreasing", async () => {
|
|
327
|
+
test("counters decreases from 0 to -1 when decrease is clicked", async () => {
|
|
328
|
+
const wrapper = mount(NumberInput, {
|
|
329
|
+
props: {
|
|
330
|
+
label: "Test Number",
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// Assert input value is default 0
|
|
335
|
+
expect(wrapper.find("input").element.value).toBe("0");
|
|
336
|
+
|
|
337
|
+
// Find the + button
|
|
338
|
+
const buttons = wrapper.findAll("button");
|
|
339
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
340
|
+
buttonWrapper.text().includes("-"),
|
|
341
|
+
)[0];
|
|
342
|
+
|
|
343
|
+
// Click on the + button
|
|
344
|
+
await targetButton?.trigger("click");
|
|
345
|
+
|
|
346
|
+
// Check the value has been increased by 1
|
|
347
|
+
expect(wrapper.find("input").element.value).toBe("-1");
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
test("decrease to the min value and check button gets disabled", async () => {
|
|
351
|
+
const wrapper = mount(NumberInput, {
|
|
352
|
+
props: {
|
|
353
|
+
label: "Test Number",
|
|
354
|
+
minValue: -10,
|
|
355
|
+
modelValue: -9,
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// Assert input value is default
|
|
360
|
+
expect(wrapper.find("input").element.value).toBe("-9");
|
|
361
|
+
|
|
362
|
+
// Find the + button
|
|
363
|
+
const buttons = wrapper.findAll("button");
|
|
364
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
365
|
+
buttonWrapper.text().includes("-"),
|
|
366
|
+
)[0];
|
|
367
|
+
|
|
368
|
+
// Expect to be disabled
|
|
369
|
+
expect(targetButton?.element.disabled).toBe(false);
|
|
370
|
+
|
|
371
|
+
// Click on the - button
|
|
372
|
+
await targetButton?.trigger("click");
|
|
373
|
+
|
|
374
|
+
// Check the value has changed, and button is disabled
|
|
375
|
+
expect(wrapper.find("input").element.value).toBe("-10");
|
|
376
|
+
expect(targetButton?.element.disabled).toBe(true);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
test("decrement button is disabled and will not decrease the value", async () => {
|
|
380
|
+
const wrapper = mount(NumberInput, {
|
|
381
|
+
props: {
|
|
382
|
+
label: "Test Number",
|
|
383
|
+
minValue: -10,
|
|
384
|
+
modelValue: -10,
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// Assert input value is default
|
|
389
|
+
expect(wrapper.find("input").element.value).toBe("-10");
|
|
390
|
+
|
|
391
|
+
// Find the + button
|
|
392
|
+
const buttons = wrapper.findAll("button");
|
|
393
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
394
|
+
buttonWrapper.text().includes("-"),
|
|
395
|
+
)[0];
|
|
396
|
+
|
|
397
|
+
// Expect to be disabled
|
|
398
|
+
expect(targetButton?.element.disabled).toBe(true);
|
|
399
|
+
|
|
400
|
+
// Click on the - button
|
|
401
|
+
await targetButton?.trigger("click");
|
|
402
|
+
|
|
403
|
+
// Check the value has not changed
|
|
404
|
+
expect(wrapper.find("input").element.value).toBe("-10");
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test("decrement by 5 units", async () => {
|
|
408
|
+
const wrapper = mount(NumberInput, {
|
|
409
|
+
props: {
|
|
410
|
+
label: "Test Number",
|
|
411
|
+
minValue: -10,
|
|
412
|
+
modelValue: 0,
|
|
413
|
+
stepIncrement: 5,
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
// Assert input value is default 0
|
|
418
|
+
expect(wrapper.find("input").element.value).toBe("0");
|
|
419
|
+
|
|
420
|
+
// Find the - button
|
|
421
|
+
const buttons = wrapper.findAll("button");
|
|
422
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
423
|
+
buttonWrapper.text().includes("-"),
|
|
424
|
+
)[0];
|
|
425
|
+
|
|
426
|
+
// Click on the + button
|
|
427
|
+
await targetButton?.trigger("click");
|
|
428
|
+
|
|
429
|
+
// Check the value added 5 units
|
|
430
|
+
expect(wrapper.find("input").element.value).toBe("-5");
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
test("decrement past the minValue, results should return min value", async () => {
|
|
434
|
+
const wrapper = mount(NumberInput, {
|
|
435
|
+
props: {
|
|
436
|
+
label: "Test Number",
|
|
437
|
+
minValue: -10,
|
|
438
|
+
modelValue: 0,
|
|
439
|
+
stepIncrement: 15,
|
|
440
|
+
},
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
// Assert input value is default 0
|
|
444
|
+
expect(wrapper.find("input").element.value).toBe("0");
|
|
445
|
+
|
|
446
|
+
// Find the - button
|
|
447
|
+
const buttons = wrapper.findAll("button");
|
|
448
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
449
|
+
buttonWrapper.text().includes("-"),
|
|
450
|
+
)[0];
|
|
451
|
+
|
|
452
|
+
// Click on the + button
|
|
453
|
+
await targetButton?.trigger("click");
|
|
454
|
+
|
|
455
|
+
// Check the value has not changed
|
|
456
|
+
expect(wrapper.find("input").element.value).toBe("-10");
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
test("decrement by 1 to the min javascript integer value", async () => {
|
|
460
|
+
const wrapper = mount(NumberInput, {
|
|
461
|
+
props: {
|
|
462
|
+
label: "Test Number",
|
|
463
|
+
minValue: -Number.MAX_SAFE_INTEGER,
|
|
464
|
+
modelValue: -Number.MAX_SAFE_INTEGER + 1,
|
|
465
|
+
stepIncrement: 1,
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
// Assert input value is default 0
|
|
470
|
+
expect(wrapper.find("input").element.value).toBe(
|
|
471
|
+
`${-Number.MAX_SAFE_INTEGER + 1}`,
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
// Find the - button
|
|
475
|
+
const buttons = wrapper.findAll("button");
|
|
476
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
477
|
+
buttonWrapper.text().includes("-"),
|
|
478
|
+
)[0];
|
|
479
|
+
|
|
480
|
+
// Click on the + button
|
|
481
|
+
await targetButton?.trigger("click");
|
|
482
|
+
|
|
483
|
+
// Check the value has not changed
|
|
484
|
+
expect(wrapper.find("input").element.value).toBe(
|
|
485
|
+
`${-Number.MAX_SAFE_INTEGER}`,
|
|
486
|
+
);
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
test("decrement by 10 PAST the min javascript integer value", async () => {
|
|
490
|
+
const wrapper = mount(NumberInput, {
|
|
491
|
+
props: {
|
|
492
|
+
label: "Test Number",
|
|
493
|
+
minValue: -Number.MAX_SAFE_INTEGER,
|
|
494
|
+
modelValue: -Number.MAX_SAFE_INTEGER + 1,
|
|
495
|
+
stepIncrement: 10,
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// Assert input value is default 0
|
|
500
|
+
expect(wrapper.find("input").element.value).toBe(
|
|
501
|
+
`${-Number.MAX_SAFE_INTEGER + 1}`,
|
|
502
|
+
);
|
|
503
|
+
|
|
504
|
+
// Find the - button
|
|
505
|
+
const buttons = wrapper.findAll("button");
|
|
506
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
507
|
+
buttonWrapper.text().includes("-"),
|
|
508
|
+
)[0];
|
|
509
|
+
|
|
510
|
+
// Click on the - button
|
|
511
|
+
await targetButton?.trigger("click");
|
|
512
|
+
|
|
513
|
+
// Check the value has not changed
|
|
514
|
+
expect(wrapper.find("input").element.value).toBe(
|
|
515
|
+
`${-Number.MAX_SAFE_INTEGER}`,
|
|
516
|
+
);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
test("counters decreases from 0 to -1 when decrease is clicked, even with a -1 step increment", async () => {
|
|
520
|
+
const wrapper = mount(NumberInput, {
|
|
521
|
+
props: {
|
|
522
|
+
label: "Test Number",
|
|
523
|
+
modelValue: 0,
|
|
524
|
+
stepIncrement: -1,
|
|
525
|
+
},
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
// Assert input value is default 0
|
|
529
|
+
expect(wrapper.find("input").element.value).toBe("0");
|
|
530
|
+
|
|
531
|
+
// Find the - button
|
|
532
|
+
const buttons = wrapper.findAll("button");
|
|
533
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
534
|
+
buttonWrapper.text().includes("-"),
|
|
535
|
+
)[0];
|
|
536
|
+
|
|
537
|
+
// Click on the + button
|
|
538
|
+
await targetButton?.trigger("click");
|
|
539
|
+
|
|
540
|
+
// Check the value has not changed
|
|
541
|
+
expect(wrapper.find("input").element.value).toBe("-1");
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
test("counters decrease from 10 to 9 when decrease is clicked", async () => {
|
|
545
|
+
const wrapper = mount(NumberInput, {
|
|
546
|
+
props: {
|
|
547
|
+
label: "Test Number",
|
|
548
|
+
modelValue: 10,
|
|
549
|
+
},
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
// Assert input value is default
|
|
553
|
+
expect(wrapper.find("input").element.value).toBe("10");
|
|
554
|
+
|
|
555
|
+
// Find the - button
|
|
556
|
+
const buttons = wrapper.findAll("button");
|
|
557
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
558
|
+
buttonWrapper.text().includes("-"),
|
|
559
|
+
)[0];
|
|
560
|
+
|
|
561
|
+
// Click on the - button
|
|
562
|
+
await targetButton?.trigger("click");
|
|
563
|
+
|
|
564
|
+
// Check the value has not changed
|
|
565
|
+
expect(wrapper.find("input").element.value).toBe("9");
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
test("counters decreases from 12 to 10 when decrease is clicked, even with a -2 step increment", async () => {
|
|
569
|
+
const wrapper = mount(NumberInput, {
|
|
570
|
+
props: {
|
|
571
|
+
label: "Test Number",
|
|
572
|
+
modelValue: 12,
|
|
573
|
+
stepIncrement: -2,
|
|
574
|
+
},
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
// Assert input value is default 0
|
|
578
|
+
expect(wrapper.find("input").element.value).toBe("12");
|
|
579
|
+
|
|
580
|
+
// Find the - button
|
|
581
|
+
const buttons = wrapper.findAll("button");
|
|
582
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
583
|
+
buttonWrapper.text().includes("-"),
|
|
584
|
+
)[0];
|
|
585
|
+
|
|
586
|
+
// Click on the - button
|
|
587
|
+
await targetButton?.trigger("click");
|
|
588
|
+
|
|
589
|
+
// Check the value has not changed
|
|
590
|
+
expect(wrapper.find("input").element.value).toBe("10");
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
test("we can still decrement even when the model value is more than the maximum value. Will instantly pop to maximum number", async () => {
|
|
594
|
+
const wrapper = mount(NumberInput, {
|
|
595
|
+
props: {
|
|
596
|
+
label: "Test Number",
|
|
597
|
+
maxValue: 10,
|
|
598
|
+
modelValue: 15,
|
|
599
|
+
},
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
// Assert input value is default 0
|
|
603
|
+
expect(wrapper.find("input").element.value).toBe("15");
|
|
604
|
+
|
|
605
|
+
// Find the - button
|
|
606
|
+
const buttons = wrapper.findAll("button");
|
|
607
|
+
const targetButton = buttons.filter((buttonWrapper) =>
|
|
608
|
+
buttonWrapper.text().includes("-"),
|
|
609
|
+
)[0];
|
|
610
|
+
|
|
611
|
+
// Click on the - button
|
|
612
|
+
await targetButton?.trigger("click");
|
|
613
|
+
|
|
614
|
+
// Check the value has not changed
|
|
615
|
+
expect(wrapper.find("input").element.value).toBe("10");
|
|
616
|
+
});
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
describe("NumberInput - Manually Entering", async () => {
|
|
620
|
+
test("manually enter in the value", async () => {
|
|
621
|
+
const wrapper = mount(NumberInput, {
|
|
622
|
+
props: {
|
|
623
|
+
label: "Test Number",
|
|
624
|
+
},
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
// Check the default value
|
|
628
|
+
const input = wrapper.find("input");
|
|
629
|
+
expect(input.element.value).toBe("0");
|
|
630
|
+
|
|
631
|
+
// Mutate to 15
|
|
632
|
+
await input.setValue("15");
|
|
633
|
+
|
|
634
|
+
// Check the value
|
|
635
|
+
expect(input.element.value).toBe("15");
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
test("manually enter the value past the max value, should update to max value", async () => {
|
|
639
|
+
const wrapper = mount(NumberInput, {
|
|
640
|
+
props: {
|
|
641
|
+
label: "Test Number",
|
|
642
|
+
maxValue: 10,
|
|
643
|
+
},
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
// Check the default value
|
|
647
|
+
const input = wrapper.find("input");
|
|
648
|
+
expect(input.element.value).toBe("0");
|
|
649
|
+
|
|
650
|
+
// Mutate to 15
|
|
651
|
+
await input.setValue("15");
|
|
652
|
+
|
|
653
|
+
// Check the value
|
|
654
|
+
expect(input.element.value).toBe("10");
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
test("manually enter the value under the min value, should update to min value", async () => {
|
|
658
|
+
const wrapper = mount(NumberInput, {
|
|
659
|
+
props: {
|
|
660
|
+
label: "Test Number",
|
|
661
|
+
minValue: -10,
|
|
662
|
+
},
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
// Check the default value
|
|
666
|
+
const input = wrapper.find("input");
|
|
667
|
+
expect(input.element.value).toBe("0");
|
|
668
|
+
|
|
669
|
+
// Mutate to 15
|
|
670
|
+
await input.setValue("-15");
|
|
671
|
+
|
|
672
|
+
// Check the value
|
|
673
|
+
expect(input.element.value).toBe("-10");
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
test("manually remove all values - should default to 0", async () => {
|
|
677
|
+
const wrapper = mount(NumberInput, {
|
|
678
|
+
props: {
|
|
679
|
+
label: "Test Number",
|
|
680
|
+
modelValue: 100,
|
|
681
|
+
},
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
// Check the default value
|
|
685
|
+
const input = wrapper.find("input");
|
|
686
|
+
expect(input.element.value).toBe("100");
|
|
687
|
+
|
|
688
|
+
// Mutate to ""
|
|
689
|
+
await input.setValue("");
|
|
690
|
+
|
|
691
|
+
// Check the value
|
|
692
|
+
expect(input.element.value).toBe("0");
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
test("manual - user tries to type in -1. First they hit -, default will be -1", async () => {
|
|
696
|
+
const wrapper = mount(NumberInput, {
|
|
697
|
+
props: {
|
|
698
|
+
label: "Test Number",
|
|
699
|
+
},
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
// Check the default value
|
|
703
|
+
const input = wrapper.find("input");
|
|
704
|
+
expect(input.element.value).toBe("0");
|
|
705
|
+
|
|
706
|
+
// Mutate to ""
|
|
707
|
+
await input.setValue("-");
|
|
708
|
+
|
|
709
|
+
// Check the value
|
|
710
|
+
expect(input.element.value).toBe("0");
|
|
711
|
+
});
|
|
712
|
+
});
|