@sveltia/ui 0.36.1 → 0.37.1

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.
@@ -1,69 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getSelectedItemDetail } from './select.svelte.js';
3
-
4
- /**
5
- * Helper to create a minimal element-like object with the given dataset values.
6
- * @param {Record<string, string>} dataset Dataset key-value pairs.
7
- * @returns {HTMLElement} A fake element with the given dataset.
8
- */
9
- const makeElement = (dataset) => /** @type {HTMLElement} */ (/** @type {unknown} */ ({ dataset }));
10
-
11
- describe('getSelectedItemDetail', () => {
12
- it('should return a string value by default', () => {
13
- const el = makeElement({ value: 'hello', name: 'field', label: 'Hello' });
14
- const detail = getSelectedItemDetail(el);
15
-
16
- expect(detail.type).toBe('string');
17
- expect(detail.value).toBe('hello');
18
- expect(detail.name).toBe('field');
19
- expect(detail.label).toBe('Hello');
20
- expect(detail.target).toBe(el);
21
- });
22
-
23
- it('should coerce value to empty string when value is absent and type is string', () => {
24
- const el = makeElement({ name: 'field' });
25
- const detail = getSelectedItemDetail(el);
26
-
27
- expect(detail.type).toBe('string');
28
- expect(detail.value).toBe('');
29
- });
30
-
31
- it('should return a number value when type is number', () => {
32
- const el = makeElement({ type: 'number', value: '42' });
33
- const detail = getSelectedItemDetail(el);
34
-
35
- expect(detail.type).toBe('number');
36
- expect(detail.value).toBe(42);
37
- });
38
-
39
- it('should return null for a non-numeric value when type is number', () => {
40
- const el = makeElement({ type: 'number', value: 'abc' });
41
- const detail = getSelectedItemDetail(el);
42
-
43
- expect(detail.value).toBeNull();
44
- });
45
-
46
- it('should return true for "true" when type is boolean', () => {
47
- const el = makeElement({ type: 'boolean', value: 'true' });
48
- const detail = getSelectedItemDetail(el);
49
-
50
- expect(detail.type).toBe('boolean');
51
- expect(detail.value).toBe(true);
52
- });
53
-
54
- it('should return false for any non-"true" string when type is boolean', () => {
55
- const el = makeElement({ type: 'boolean', value: 'false' });
56
- const detail = getSelectedItemDetail(el);
57
-
58
- expect(detail.value).toBe(false);
59
- });
60
-
61
- it('should leave value unchanged for an unknown/custom type (else-if string branch false)', () => {
62
- const el = makeElement({ type: 'date', value: '2024-01-01' });
63
- const detail = getSelectedItemDetail(el);
64
-
65
- expect(detail.type).toBe('date');
66
- // value is the raw dataset string when type is not string/number/boolean
67
- expect(detail.value).toBe('2024-01-01');
68
- });
69
- });