@dile/utils 3.0.17 → 3.0.19
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/components/country-select/country-select.spec.js +35 -0
- package/components/country-select/fct-country-select.js +3 -1
- package/components/country-select/src/DileCountrySelect.js +3 -1
- package/components/datepicker/calendar.js +3 -1
- package/components/datepicker/calendar.spec.js +22 -0
- package/components/datepicker/datepicker.js +3 -1
- package/components/datepicker/datepicker.spec.js +33 -0
- package/components/datepicker/datetimepicker.js +3 -1
- package/components/datepicker/datetimepicker.spec.js +30 -0
- package/components/graph/graph.js +3 -1
- package/components/graph/graph.spec.js +38 -0
- package/components/html-transform/html-transform.js +3 -1
- package/components/html-transform/html-transform.spec.js +25 -0
- package/components/local-time/local-time.js +3 -1
- package/components/local-time/local-time.spec.js +25 -0
- package/components/media-query/media-query.js +3 -1
- package/components/media-query/media-query.spec.js +34 -0
- package/components/network/network.js +3 -1
- package/components/network/network.spec.js +33 -0
- package/components/smooth-scroll/smooth-scroll.js +3 -1
- package/components/smooth-scroll/smooth-scroll.spec.js +26 -0
- package/package.json +3 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './country-select.js';
|
|
3
|
+
|
|
4
|
+
describe('dile-country-select', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
document.body.innerHTML = '';
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function renderCountrySelect(html) {
|
|
10
|
+
document.body.innerHTML = html;
|
|
11
|
+
const el = document.body.querySelector('dile-country-select');
|
|
12
|
+
await el.updateComplete;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('renders a dile-select with country options', async () => {
|
|
17
|
+
const el = await renderCountrySelect('<dile-country-select name="country"></dile-country-select>');
|
|
18
|
+
const select = el.shadowRoot.querySelector('dile-select');
|
|
19
|
+
expect(select).toBeTruthy();
|
|
20
|
+
expect(el.shadowRoot.querySelectorAll('option').length).toBeGreaterThan(1);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('updates value and dispatches country-changed on selection change', async () => {
|
|
24
|
+
const el = await renderCountrySelect('<dile-country-select name="country"></dile-country-select>');
|
|
25
|
+
let detail = null;
|
|
26
|
+
el.addEventListener('country-changed', (e) => { detail = e.detail; });
|
|
27
|
+
|
|
28
|
+
el.shadowRoot.querySelector('dile-select').dispatchEvent(
|
|
29
|
+
new CustomEvent('element-changed', { detail: { value: 'ES' } })
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
expect(el.value).toBe('ES');
|
|
33
|
+
expect(detail).toEqual({ value: 'ES' });
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -48,4 +48,6 @@ export class FctCountrySelect extends LitElement {
|
|
|
48
48
|
this.value = e.detail.value;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
customElements.
|
|
51
|
+
if (!customElements.get('fct-country-select')) {
|
|
52
|
+
customElements.define('fct-country-select', FctCountrySelect);
|
|
53
|
+
}
|
|
@@ -138,4 +138,6 @@ export class DileCountrySelect extends LitElement {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
customElements.
|
|
141
|
+
if (!customElements.get('dile-country-select')) {
|
|
142
|
+
customElements.define('dile-country-select', DileCountrySelect);
|
|
143
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './calendar.js';
|
|
3
|
+
|
|
4
|
+
describe('dile-calendar', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
document.body.innerHTML = '';
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function renderCalendar(html) {
|
|
10
|
+
document.body.innerHTML = html;
|
|
11
|
+
const el = document.body.querySelector('dile-calendar');
|
|
12
|
+
await el.updateComplete;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('renders the month navigation and day grid', async () => {
|
|
17
|
+
const el = await renderCalendar('<dile-calendar></dile-calendar>');
|
|
18
|
+
await el.updateComplete;
|
|
19
|
+
expect(el.shadowRoot.querySelector('.calendar__navigation')).toBeTruthy();
|
|
20
|
+
expect(el.shadowRoot.querySelectorAll('.calendar__day-button').length).toBeGreaterThan(0);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import './calendar.js';
|
|
2
2
|
import { DileDatepicker } from "./src/DileDatepicker.js";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
if (!customElements.get("dile-datepicker")) {
|
|
5
|
+
window.customElements.define("dile-datepicker", DileDatepicker);
|
|
6
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './datepicker.js';
|
|
3
|
+
|
|
4
|
+
describe('dile-datepicker', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
document.body.innerHTML = '';
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function renderDatepicker(html) {
|
|
10
|
+
document.body.innerHTML = html;
|
|
11
|
+
const el = document.body.querySelector('dile-datepicker');
|
|
12
|
+
await el.updateComplete;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('renders the text input and a calendar trigger icon', async () => {
|
|
17
|
+
const el = await renderDatepicker('<dile-datepicker name="birthdate" label="Birthdate"></dile-datepicker>');
|
|
18
|
+
expect(el.shadowRoot.querySelector('input')).toBeTruthy();
|
|
19
|
+
expect(el.shadowRoot.querySelector('dile-menu-overlay')).toBeTruthy();
|
|
20
|
+
expect(el.shadowRoot.querySelector('dile-icon')).toBeTruthy();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('updates value when a date is selected from the calendar', async () => {
|
|
24
|
+
const el = await renderDatepicker('<dile-datepicker name="birthdate"></dile-datepicker>');
|
|
25
|
+
const calendar = el.shadowRoot.querySelector('dile-calendar');
|
|
26
|
+
calendar.dispatchEvent(new CustomEvent('user-selected-date-changed', {
|
|
27
|
+
detail: { selectedDate: new Date(2024, 0, 15) },
|
|
28
|
+
}));
|
|
29
|
+
await el.updateComplete;
|
|
30
|
+
|
|
31
|
+
expect(el.value).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import './calendar.js';
|
|
2
2
|
import { DileDatetimepicker } from "./src/DileDatetimepicker.js";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
if (!customElements.get("dile-datetimepicker")) {
|
|
5
|
+
window.customElements.define("dile-datetimepicker", DileDatetimepicker);
|
|
6
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './datetimepicker.js';
|
|
3
|
+
|
|
4
|
+
describe('dile-datetimepicker', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
document.body.innerHTML = '';
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function renderDatetimepicker(html) {
|
|
10
|
+
document.body.innerHTML = html;
|
|
11
|
+
const el = document.body.querySelector('dile-datetimepicker');
|
|
12
|
+
await el.updateComplete;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('renders the text input, calendar and time picker inside the overlay', async () => {
|
|
17
|
+
const el = await renderDatetimepicker('<dile-datetimepicker name="appointment"></dile-datetimepicker>');
|
|
18
|
+
expect(el.shadowRoot.querySelector('input')).toBeTruthy();
|
|
19
|
+
expect(el.shadowRoot.querySelector('dile-calendar')).toBeTruthy();
|
|
20
|
+
expect(el.shadowRoot.querySelector('dile-time-picker')).toBeTruthy();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('updates value combining date and time when accepted', async () => {
|
|
24
|
+
const el = await renderDatetimepicker('<dile-datetimepicker name="appointment"></dile-datetimepicker>');
|
|
25
|
+
el.acceptTime();
|
|
26
|
+
await el.updateComplete;
|
|
27
|
+
|
|
28
|
+
expect(el.value).toMatch(/^\d{4}-\d{2}-\d{2} /);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach, beforeEach } from 'vitest';
|
|
2
|
+
import './graph.js';
|
|
3
|
+
|
|
4
|
+
// DileGraph relies on a global `Chart` (Chart.js), normally loaded via <script> tag
|
|
5
|
+
// in consuming pages, not a module import. Stub it so firstUpdated() doesn't throw.
|
|
6
|
+
describe('dile-graph', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
window.Chart = class {
|
|
9
|
+
constructor(ctx, config) {
|
|
10
|
+
this.ctx = ctx;
|
|
11
|
+
this.config = config;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
document.body.innerHTML = '';
|
|
18
|
+
delete window.Chart;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
async function renderGraph(html) {
|
|
22
|
+
document.body.innerHTML = html;
|
|
23
|
+
const el = document.body.querySelector('dile-graph');
|
|
24
|
+
await el.updateComplete;
|
|
25
|
+
return el;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
it('renders a canvas and initializes a Chart instance', async () => {
|
|
29
|
+
const el = await renderGraph('<dile-graph></dile-graph>');
|
|
30
|
+
expect(el.shadowRoot.querySelector('canvas')).toBeTruthy();
|
|
31
|
+
expect(el.myChart).toBeInstanceOf(window.Chart);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('defaults chartType to line', async () => {
|
|
35
|
+
const el = await renderGraph('<dile-graph></dile-graph>');
|
|
36
|
+
expect(el.chartType).toBe('line');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './html-transform.js';
|
|
3
|
+
|
|
4
|
+
describe('dile-html-transform', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
document.body.innerHTML = '';
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function renderHtmlTransform(html) {
|
|
10
|
+
document.body.innerHTML = html;
|
|
11
|
+
const el = document.body.querySelector('dile-html-transform');
|
|
12
|
+
await el.updateComplete;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('renders the plain text when no conversion flags are set', async () => {
|
|
17
|
+
const el = await renderHtmlTransform('<dile-html-transform text="hello world"></dile-html-transform>');
|
|
18
|
+
expect(el.shadowRoot.textContent.trim()).toBe('hello world');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('converts a link when convertLinks is set', async () => {
|
|
22
|
+
const el = await renderHtmlTransform('<dile-html-transform text="visit example.com" convertLinks></dile-html-transform>');
|
|
23
|
+
expect(el.shadowRoot.querySelector('a')).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './local-time.js';
|
|
3
|
+
|
|
4
|
+
describe('dile-local-time', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
document.body.innerHTML = '';
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function renderLocalTime(html) {
|
|
10
|
+
document.body.innerHTML = html;
|
|
11
|
+
const el = document.body.querySelector('dile-local-time');
|
|
12
|
+
await el.updateComplete;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('renders the formatted local time from isoDatetime', async () => {
|
|
17
|
+
const el = await renderLocalTime('<dile-local-time isoDatetime="2024-01-15T10:30:00Z"></dile-local-time>');
|
|
18
|
+
expect(el.shadowRoot.textContent.trim().length).toBeGreaterThan(0);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('renders empty when isoDatetime is not set', async () => {
|
|
22
|
+
const el = await renderLocalTime('<dile-local-time></dile-local-time>');
|
|
23
|
+
expect(el.shadowRoot.textContent.trim()).toBe('');
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './media-query.js';
|
|
3
|
+
|
|
4
|
+
describe('dile-media-query', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
document.body.innerHTML = '';
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function renderMediaQuery(html) {
|
|
10
|
+
document.body.innerHTML = html;
|
|
11
|
+
const el = document.body.querySelector('dile-media-query');
|
|
12
|
+
await el.updateComplete;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('renders without throwing and creates a matcher for the query', async () => {
|
|
17
|
+
const el = await renderMediaQuery('<dile-media-query query="(min-width: 10px)"></dile-media-query>');
|
|
18
|
+
await el.updateComplete;
|
|
19
|
+
expect(el.matcher).toBeInstanceOf(MediaQueryList);
|
|
20
|
+
expect(el._match).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('dispatches dile-media-query-changed when the match state is set', async () => {
|
|
24
|
+
const el = await renderMediaQuery('<dile-media-query query="(min-width: 10px)"></dile-media-query>');
|
|
25
|
+
let detail = null;
|
|
26
|
+
el.addEventListener('dile-media-query-changed', (e) => { detail = e.detail; });
|
|
27
|
+
|
|
28
|
+
el.query = '(max-width: 5px)';
|
|
29
|
+
await el.updateComplete;
|
|
30
|
+
await el.updateComplete;
|
|
31
|
+
|
|
32
|
+
expect(detail).toEqual({ value: false });
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './network.js';
|
|
3
|
+
|
|
4
|
+
describe('dile-network', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
document.body.innerHTML = '';
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function renderNetwork(html) {
|
|
10
|
+
document.body.innerHTML = html;
|
|
11
|
+
const el = document.body.querySelector('dile-network');
|
|
12
|
+
await el.updateComplete;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('reflects the current navigator.onLine status', async () => {
|
|
17
|
+
const el = await renderNetwork('<dile-network></dile-network>');
|
|
18
|
+
expect(el.onLine).toBe(window.navigator.onLine);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('does not render the offline toast when online and showOffLineStatus is unset', async () => {
|
|
22
|
+
const el = await renderNetwork('<dile-network></dile-network>');
|
|
23
|
+
expect(el.shadowRoot.querySelector('#eltoast')).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('renders the offline toast when forced offline with showOffLineStatus', async () => {
|
|
27
|
+
const el = await renderNetwork('<dile-network showOffLineStatus></dile-network>');
|
|
28
|
+
el.onLine = false;
|
|
29
|
+
await el.updateComplete;
|
|
30
|
+
|
|
31
|
+
expect(el.shadowRoot.querySelector('#eltoast')).toBeTruthy();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import './smooth-scroll.js';
|
|
3
|
+
|
|
4
|
+
describe('dile-smooth-scroll', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
document.body.innerHTML = '';
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
async function renderSmoothScroll(html) {
|
|
10
|
+
document.body.innerHTML = html;
|
|
11
|
+
const el = document.body.querySelector('dile-smooth-scroll');
|
|
12
|
+
await el.updateComplete;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it('renders without throwing', async () => {
|
|
17
|
+
const el = await renderSmoothScroll('<dile-smooth-scroll></dile-smooth-scroll>');
|
|
18
|
+
expect(el).toBeTruthy();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('exposes smooth scroll methods without throwing when invoked', async () => {
|
|
22
|
+
const el = await renderSmoothScroll('<dile-smooth-scroll></dile-smooth-scroll>');
|
|
23
|
+
expect(typeof el.smoothScrollToTop).toBe('function');
|
|
24
|
+
expect(() => el.smoothScrollToTop()).not.toThrow();
|
|
25
|
+
});
|
|
26
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/utils",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.19",
|
|
4
4
|
"description": "Utility Components of Diverse Uses Based on the Lit Library and Web Components Standard.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://dile-components.com/",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@dile/ui": "^3.4.
|
|
23
|
+
"@dile/ui": "^3.4.6",
|
|
24
24
|
"@lion/ui": "^0.11.2",
|
|
25
25
|
"linkify-string": "^4.1.3",
|
|
26
26
|
"linkifyjs": "^4.1.3",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "57a54e50de1a24d64dcf478fa6d39624e1f775eb"
|
|
33
33
|
}
|