microui-wc 0.1.1 → 0.1.2
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/AGENTS.md +71 -71
- package/CHANGELOG.md +1 -1
- package/README.md +14 -9
- package/dist/AGENTS.md +71 -71
- package/dist/README.md +14 -9
- package/dist/microui.css +1 -1
- package/dist/microui.esm.js.map +1 -1
- package/dist/microui.min.js.map +1 -1
- package/docs/getting-started.md +3 -3
- package/package.json +39 -11
- package/src/components/mu-schema-form.js +1 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -33
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -28
- package/.github/workflows/ci.yml +0 -42
- package/.github/workflows/deploy-pages.yml +0 -112
- package/CODE_OF_CONDUCT.md +0 -59
- package/CONTRIBUTING.md +0 -156
- package/SECURITY.md +0 -58
- package/app/.generated/routes/alerts.js +0 -8
- package/app/.generated/routes/avatars.js +0 -8
- package/app/.generated/routes/badges.js +0 -8
- package/app/.generated/routes/buttons.js +0 -10
- package/app/.generated/routes/cards.js +0 -10
- package/app/.generated/routes/checkboxes.js +0 -9
- package/app/.generated/routes/chips.js +0 -8
- package/app/.generated/routes/dropdowns.js +0 -9
- package/app/.generated/routes/home.js +0 -7
- package/app/.generated/routes/icons.js +0 -9
- package/app/.generated/routes/inputs.js +0 -10
- package/app/.generated/routes/installation.js +0 -7
- package/app/.generated/routes/layout.js +0 -9
- package/app/.generated/routes/modals.js +0 -9
- package/app/.generated/routes/navbar.js +0 -7
- package/app/.generated/routes/progress.js +0 -9
- package/app/.generated/routes/radios.js +0 -9
- package/app/.generated/routes/switches.js +0 -9
- package/app/.generated/routes/tabs.js +0 -8
- package/app/.generated/routes/toasts.js +0 -9
- package/app/index.html +0 -67
- package/app/pages/alerts.html +0 -23
- package/app/pages/avatars.html +0 -22
- package/app/pages/badges.html +0 -22
- package/app/pages/buttons.html +0 -71
- package/app/pages/cards.html +0 -54
- package/app/pages/checkboxes.html +0 -39
- package/app/pages/chips.html +0 -23
- package/app/pages/dropdowns.html +0 -41
- package/app/pages/home.html +0 -59
- package/app/pages/icons.html +0 -29
- package/app/pages/inputs.html +0 -66
- package/app/pages/installation.html +0 -34
- package/app/pages/layout.html +0 -30
- package/app/pages/modals.html +0 -21
- package/app/pages/navbar.html +0 -22
- package/app/pages/progress.html +0 -35
- package/app/pages/radios.html +0 -40
- package/app/pages/switches.html +0 -39
- package/app/pages/tabs.html +0 -30
- package/app/pages/toasts.html +0 -22
- package/app-dist/index.html +0 -67
- package/app-dist/pages/alerts.html +0 -23
- package/app-dist/pages/avatars.html +0 -22
- package/app-dist/pages/badges.html +0 -22
- package/app-dist/pages/buttons.html +0 -71
- package/app-dist/pages/cards.html +0 -54
- package/app-dist/pages/checkboxes.html +0 -39
- package/app-dist/pages/chips.html +0 -23
- package/app-dist/pages/dropdowns.html +0 -41
- package/app-dist/pages/home.html +0 -59
- package/app-dist/pages/icons.html +0 -29
- package/app-dist/pages/inputs.html +0 -66
- package/app-dist/pages/installation.html +0 -34
- package/app-dist/pages/layout.html +0 -30
- package/app-dist/pages/modals.html +0 -21
- package/app-dist/pages/navbar.html +0 -22
- package/app-dist/pages/progress.html +0 -35
- package/app-dist/pages/radios.html +0 -40
- package/app-dist/pages/switches.html +0 -39
- package/app-dist/pages/tabs.html +0 -30
- package/app-dist/pages/toasts.html +0 -22
- package/app-dist/pages.json +0 -217
- package/app-dist/routes/alerts.js +0 -5
- package/app-dist/routes/avatars.js +0 -1
- package/app-dist/routes/badges.js +0 -1
- package/app-dist/routes/buttons.js +0 -1
- package/app-dist/routes/cards.js +0 -1
- package/app-dist/routes/checkboxes.js +0 -9
- package/app-dist/routes/chips.js +0 -4
- package/app-dist/routes/chunk-019e5e2f.js +0 -5
- package/app-dist/routes/chunk-0m4j19yd.js +0 -2
- package/app-dist/routes/chunk-0tmmp5q0.js +0 -1
- package/app-dist/routes/chunk-10xn709r.js +0 -1
- package/app-dist/routes/chunk-15m2qcda.js +0 -2
- package/app-dist/routes/chunk-1bh8g23n.js +0 -1
- package/app-dist/routes/chunk-1vg0v937.js +0 -1
- package/app-dist/routes/chunk-1zvcgy3j.js +0 -1
- package/app-dist/routes/chunk-2afb0861.js +0 -1
- package/app-dist/routes/chunk-2c6ttpzt.js +0 -5
- package/app-dist/routes/chunk-3dy30fhs.js +0 -1
- package/app-dist/routes/chunk-426dnces.js +0 -13
- package/app-dist/routes/chunk-44kgxery.js +0 -1
- package/app-dist/routes/chunk-47fdnejd.js +0 -33
- package/app-dist/routes/chunk-49a6t2vq.js +0 -1
- package/app-dist/routes/chunk-4fe1rm5b.js +0 -1
- package/app-dist/routes/chunk-4ggmvkta.js +0 -33
- package/app-dist/routes/chunk-4vkz81q7.js +0 -33
- package/app-dist/routes/chunk-4w4tmj8f.js +0 -31
- package/app-dist/routes/chunk-532s62kr.js +0 -31
- package/app-dist/routes/chunk-5hm3bssy.js +0 -33
- package/app-dist/routes/chunk-5vrh24hc.js +0 -1
- package/app-dist/routes/chunk-61pcg25a.js +0 -1
- package/app-dist/routes/chunk-6nfhygvf.js +0 -1
- package/app-dist/routes/chunk-700e7je6.js +0 -33
- package/app-dist/routes/chunk-7fsn17kg.js +0 -1
- package/app-dist/routes/chunk-7k789b32.js +0 -1
- package/app-dist/routes/chunk-7r46q0ys.js +0 -36
- package/app-dist/routes/chunk-86fmc1fr.js +0 -5
- package/app-dist/routes/chunk-8qth37vw.js +0 -1
- package/app-dist/routes/chunk-924wv8n0.js +0 -1
- package/app-dist/routes/chunk-9mbhgxk9.js +0 -1
- package/app-dist/routes/chunk-a216hyd9.js +0 -1
- package/app-dist/routes/chunk-akzxykh9.js +0 -33
- package/app-dist/routes/chunk-b3dcvy8c.js +0 -1
- package/app-dist/routes/chunk-b74zahz5.js +0 -31
- package/app-dist/routes/chunk-bftj53p2.js +0 -5
- package/app-dist/routes/chunk-c01hnz3e.js +0 -1
- package/app-dist/routes/chunk-d8pvv5km.js +0 -1
- package/app-dist/routes/chunk-dev0aezr.js +0 -2
- package/app-dist/routes/chunk-dh6vnv0e.js +0 -1
- package/app-dist/routes/chunk-dn2cbpva.js +0 -36
- package/app-dist/routes/chunk-dvn0my90.js +0 -1
- package/app-dist/routes/chunk-dvq8mnve.js +0 -36
- package/app-dist/routes/chunk-e8c2gc4d.js +0 -5
- package/app-dist/routes/chunk-ejf9ak2x.js +0 -1
- package/app-dist/routes/chunk-f083m55s.js +0 -1
- package/app-dist/routes/chunk-fnrj28s1.js +0 -31
- package/app-dist/routes/chunk-fvg3yjdp.js +0 -31
- package/app-dist/routes/chunk-g7k381n1.js +0 -1
- package/app-dist/routes/chunk-h01kq2ae.js +0 -13
- package/app-dist/routes/chunk-h4dk761v.js +0 -5
- package/app-dist/routes/chunk-hmx91z2x.js +0 -5
- package/app-dist/routes/chunk-hxbg4m42.js +0 -36
- package/app-dist/routes/chunk-jbjnfp2b.js +0 -2
- package/app-dist/routes/chunk-jxtz5vv6.js +0 -36
- package/app-dist/routes/chunk-jxzcs0ey.js +0 -36
- package/app-dist/routes/chunk-kt7wwhcx.js +0 -1
- package/app-dist/routes/chunk-kzptszyc.js +0 -33
- package/app-dist/routes/chunk-mhgca4w4.js +0 -2
- package/app-dist/routes/chunk-mhswxa20.js +0 -1
- package/app-dist/routes/chunk-n8zfeex6.js +0 -1
- package/app-dist/routes/chunk-pee47b2r.js +0 -1
- package/app-dist/routes/chunk-pesmw829.js +0 -1
- package/app-dist/routes/chunk-pgc4c6f3.js +0 -36
- package/app-dist/routes/chunk-q8egegm1.js +0 -1
- package/app-dist/routes/chunk-q9mn2qyq.js +0 -36
- package/app-dist/routes/chunk-qh0rtaf3.js +0 -5
- package/app-dist/routes/chunk-qqhmk6ye.js +0 -2
- package/app-dist/routes/chunk-qrxygmf7.js +0 -33
- package/app-dist/routes/chunk-r46yzksx.js +0 -36
- package/app-dist/routes/chunk-rgpbw2w0.js +0 -5
- package/app-dist/routes/chunk-rnpzv3d8.js +0 -2
- package/app-dist/routes/chunk-s5v8cv05.js +0 -2
- package/app-dist/routes/chunk-sbwn5bpc.js +0 -1
- package/app-dist/routes/chunk-sqbg8jbt.js +0 -33
- package/app-dist/routes/chunk-sv8dqnf7.js +0 -1
- package/app-dist/routes/chunk-t67sw3za.js +0 -1
- package/app-dist/routes/chunk-tjdpqwdf.js +0 -31
- package/app-dist/routes/chunk-tq2mfghg.js +0 -1
- package/app-dist/routes/chunk-ttn10vt6.js +0 -1
- package/app-dist/routes/chunk-v2hzpjxr.js +0 -1
- package/app-dist/routes/chunk-wfjjkw9y.js +0 -1
- package/app-dist/routes/chunk-wt8cxzmf.js +0 -31
- package/app-dist/routes/chunk-x45d372k.js +0 -5
- package/app-dist/routes/chunk-y3wsazkt.js +0 -1
- package/app-dist/routes/chunk-y7pmgc7t.js +0 -33
- package/app-dist/routes/chunk-zefdt2q3.js +0 -31
- package/app-dist/routes/dropdowns.js +0 -6
- package/app-dist/routes/home.js +0 -1
- package/app-dist/routes/icons.js +0 -1
- package/app-dist/routes/inputs.js +0 -12
- package/app-dist/routes/installation.js +0 -1
- package/app-dist/routes/layout.js +0 -1
- package/app-dist/routes/modals.js +0 -7
- package/app-dist/routes/navbar.js +0 -1
- package/app-dist/routes/progress.js +0 -1
- package/app-dist/routes/radios.js +0 -6
- package/app-dist/routes/switches.js +0 -6
- package/app-dist/routes/tabs.js +0 -1
- package/app-dist/routes/toasts.js +0 -16
- package/assets/fonts/material-symbols-mini.woff2 +0 -0
- package/assets/fonts/material-symbols.woff2 +0 -0
- package/assets/fonts/roboto-400.woff2 +0 -0
- package/assets/fonts/roboto-500.woff2 +0 -0
- package/assets/fonts/roboto-700.woff2 +0 -0
- package/assets/logo-banner-400.jpg +0 -0
- package/assets/logo-banner-400.webp +0 -0
- package/assets/logo-banner-800.webp +0 -0
- package/assets/logo-banner.jpg +0 -0
- package/assets/logo-icon-64.jpg +0 -0
- package/assets/logo-icon-64.webp +0 -0
- package/assets/logo-icon.jpg +0 -0
- package/assets/logo-square.jpg +0 -0
- package/bun.lock +0 -312
- package/bunfig.toml +0 -4
- package/custom-elements.json +0 -1916
- package/demo/api/sample-data.json +0 -38
- package/demo/content/alerts.html +0 -115
- package/demo/content/avatars.html +0 -70
- package/demo/content/badges.html +0 -65
- package/demo/content/buttons.html +0 -188
- package/demo/content/callouts.html +0 -91
- package/demo/content/cards.html +0 -121
- package/demo/content/checkboxes.html +0 -178
- package/demo/content/chips.html +0 -67
- package/demo/content/codeblocks.html +0 -101
- package/demo/content/confirms.html +0 -115
- package/demo/content/datatables.html +0 -149
- package/demo/content/dividers.html +0 -119
- package/demo/content/dropdowns.html +0 -89
- package/demo/content/enterprise.html +0 -252
- package/demo/content/home.html +0 -149
- package/demo/content/icons.html +0 -89
- package/demo/content/inputs.html +0 -135
- package/demo/content/installation.html +0 -16
- package/demo/content/layout.html +0 -136
- package/demo/content/modals.html +0 -141
- package/demo/content/navbar.html +0 -70
- package/demo/content/progress.html +0 -119
- package/demo/content/radios.html +0 -88
- package/demo/content/skeletons.html +0 -109
- package/demo/content/spinners.html +0 -96
- package/demo/content/switches.html +0 -84
- package/demo/content/tables.html +0 -124
- package/demo/content/tabs.html +0 -85
- package/demo/content/toasts.html +0 -116
- package/demo/content/tooltips.html +0 -107
- package/demo/content/virtual-lists.html +0 -233
- package/demo/favicon.ico +0 -0
- package/demo/favicon.png +0 -0
- package/demo/full.html +0 -52
- package/demo/iife.html +0 -46
- package/demo/manifest.json +0 -34
- package/demo/pages/datatable-demo.html +0 -237
- package/demo/pages/prompt-ui-demo.html +0 -218
- package/demo/pages/responsive-demo.html +0 -122
- package/demo/pages/schema-form-demo.html +0 -270
- package/demo/robots.txt +0 -6
- package/demo/shell.html +0 -712
- package/demo/sw.js +0 -387
- package/lighthouse-audit.mjs +0 -113
- package/scripts/analyze-components.js +0 -105
- package/scripts/build-app.js +0 -193
- package/scripts/build-framework.js +0 -444
- package/scripts/build-utils.js +0 -101
- package/scripts/test-isolated.js +0 -151
- package/server.js +0 -256
- package/tests/agents/agent-integration.test.js +0 -76
- package/tests/benchmark.html +0 -296
- package/tests/build/scan-components.test.js +0 -173
- package/tests/components/all-components.test.js +0 -245
- package/tests/components/all-missing-components.test.js +0 -574
- package/tests/components/mu-alert.test.js +0 -113
- package/tests/components/mu-avatar.test.js +0 -148
- package/tests/components/mu-badge.test.js +0 -92
- package/tests/components/mu-button.test.js +0 -112
- package/tests/components/mu-card.test.js +0 -89
- package/tests/components/mu-checkbox.test.js +0 -158
- package/tests/components/mu-chip.test.js +0 -118
- package/tests/components/mu-container.test.js +0 -120
- package/tests/components/mu-divider.test.js +0 -98
- package/tests/components/mu-drawer-item.test.js +0 -199
- package/tests/components/mu-drawer.test.js +0 -96
- package/tests/components/mu-dropdown.test.js +0 -125
- package/tests/components/mu-form.test.js +0 -138
- package/tests/components/mu-grid.test.js +0 -135
- package/tests/components/mu-icon.test.js +0 -110
- package/tests/components/mu-input.test.js +0 -131
- package/tests/components/mu-lazy.test.js +0 -103
- package/tests/components/mu-modal.test.js +0 -275
- package/tests/components/mu-navbar.test.js +0 -101
- package/tests/components/mu-progress.test.js +0 -115
- package/tests/components/mu-radio.test.js +0 -114
- package/tests/components/mu-repeat.test.js +0 -106
- package/tests/components/mu-sidebar.test.js +0 -126
- package/tests/components/mu-skeleton.test.js +0 -162
- package/tests/components/mu-stack.test.js +0 -143
- package/tests/components/mu-switch.test.js +0 -292
- package/tests/components/mu-table.test.js +0 -124
- package/tests/components/mu-tabs.test.js +0 -104
- package/tests/components/mu-textarea.test.js +0 -115
- package/tests/components/mu-toast.test.js +0 -321
- package/tests/components/mu-tooltip.test.js +0 -133
- package/tests/components/mu-virtual-list.test.js +0 -109
- package/tests/core/MuElement.test.js +0 -120
- package/tests/core/agent-api.test.js +0 -125
- package/tests/core/all-core-modules.test.js +0 -442
- package/tests/core/bus.test.js +0 -364
- package/tests/core/component-schema.test.js +0 -160
- package/tests/core/feature-registry.test.js +0 -198
- package/tests/core/form-state.test.js +0 -167
- package/tests/core/http.test.js +0 -119
- package/tests/core/keyboard.test.js +0 -319
- package/tests/core/layers.test.js +0 -129
- package/tests/core/namespaced-stores.test.js +0 -114
- package/tests/core/render.test.js +0 -121
- package/tests/core/ripple.test.js +0 -131
- package/tests/core/router.test.js +0 -89
- package/tests/core/scheduler.test.js +0 -121
- package/tests/core/signals.test.js +0 -128
- package/tests/core/store.test.js +0 -171
- package/tests/core/transitions.test.js +0 -82
- package/tests/e2e/accessibility-harness.html +0 -58
- package/tests/e2e/accessibility.test.js +0 -401
- package/tests/e2e/agent-features.test.js +0 -372
- package/tests/e2e/card-spacing.test.js +0 -287
- package/tests/e2e/components.test.js +0 -439
- package/tests/e2e/demo-routes.test.js +0 -478
- package/tests/e2e/layout-css-fallback.test.js +0 -334
- package/tests/e2e/mu-alert.e2e.test.js +0 -111
- package/tests/e2e/mu-checkbox.test.js +0 -489
- package/tests/e2e/mu-chip.test.js +0 -347
- package/tests/e2e/mu-form.test.js +0 -499
- package/tests/e2e/mu-icon.test.js +0 -114
- package/tests/e2e/mu-radio.test.js +0 -113
- package/tests/e2e/mu-skeleton.test.js +0 -140
- package/tests/e2e/mu-switch.test.js +0 -415
- package/tests/e2e/mu-tabs.test.js +0 -494
- package/tests/e2e/mu-textarea.test.js +0 -242
- package/tests/e2e/mu-virtual-list.test.js +0 -427
- package/tests/e2e/perf-memory.test.js +0 -161
- package/tests/e2e/puppeteer-helper.js +0 -137
- package/tests/e2e/puppeteer.test.js +0 -226
- package/tests/e2e/pwa.test.js +0 -261
- package/tests/e2e/test-harness.html +0 -319
- package/tests/manual/test-components.html +0 -120
- package/tests/memory-test.html +0 -309
- package/tests/setup-dom.js +0 -93
- package/tests/visual-test.html +0 -301
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Unit Tests for mu-toast Component and SignalBus Integration
|
|
3
|
-
*
|
|
4
|
-
* CRITICAL: These tests prevent regressions for:
|
|
5
|
-
* - Toast rendering and structure
|
|
6
|
-
* - Auto-dismiss functionality
|
|
7
|
-
* - Severity variants
|
|
8
|
-
* - Toast.show() programmatic API
|
|
9
|
-
* - SignalBus listener registration (fixes lazy loading)
|
|
10
|
-
* - Container management
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { describe, test, expect, beforeAll, beforeEach, afterEach } from 'bun:test';
|
|
14
|
-
|
|
15
|
-
// Setup linkedom for DOM testing
|
|
16
|
-
import { parseHTML } from 'linkedom';
|
|
17
|
-
|
|
18
|
-
let document, customElements, HTMLElement, body;
|
|
19
|
-
let MuToast, MuToastContainer, Toast, bus, UIEvents;
|
|
20
|
-
|
|
21
|
-
describe('mu-toast Component', () => {
|
|
22
|
-
|
|
23
|
-
beforeAll(async () => {
|
|
24
|
-
const dom = parseHTML('<!DOCTYPE html><html><body></body></html>');
|
|
25
|
-
document = dom.document;
|
|
26
|
-
customElements = dom.customElements;
|
|
27
|
-
HTMLElement = dom.HTMLElement;
|
|
28
|
-
body = document.body;
|
|
29
|
-
|
|
30
|
-
globalThis.document = document;
|
|
31
|
-
globalThis.customElements = customElements;
|
|
32
|
-
globalThis.HTMLElement = HTMLElement;
|
|
33
|
-
globalThis.window = {
|
|
34
|
-
__MICROUI_SIGNALBUS__: null,
|
|
35
|
-
__MICROUI_TOAST_LISTENER__: false
|
|
36
|
-
};
|
|
37
|
-
globalThis.CustomEvent = class CustomEvent extends Event {
|
|
38
|
-
constructor(type, options = {}) {
|
|
39
|
-
super(type, options);
|
|
40
|
-
this.detail = options.detail;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// Import bus first (creates SignalBus)
|
|
45
|
-
const busModule = await import('../../src/core/bus.js');
|
|
46
|
-
bus = busModule.bus;
|
|
47
|
-
UIEvents = busModule.UIEvents;
|
|
48
|
-
|
|
49
|
-
// Import component (this also registers it and SignalBus listener)
|
|
50
|
-
const module = await import('../../src/components/mu-toast.js');
|
|
51
|
-
MuToast = module.MuToast;
|
|
52
|
-
MuToastContainer = module.MuToastContainer;
|
|
53
|
-
Toast = module.Toast;
|
|
54
|
-
|
|
55
|
-
// Patch emit for linkedom compatibility
|
|
56
|
-
MuToast.prototype.emit = function (eventName, detail) {
|
|
57
|
-
try {
|
|
58
|
-
this.dispatchEvent(new Event(eventName, { bubbles: true }));
|
|
59
|
-
} catch (e) {
|
|
60
|
-
// linkedom throws on eventPhase assignment, safe to ignore
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
beforeEach(() => {
|
|
66
|
-
body.innerHTML = '';
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// ============================================================
|
|
70
|
-
// REGISTRATION AND BASE SETUP
|
|
71
|
-
// ============================================================
|
|
72
|
-
|
|
73
|
-
test('mu-toast should be registered as custom element', () => {
|
|
74
|
-
expect(customElements.get('mu-toast')).toBe(MuToast);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('mu-toast-container should be registered as custom element', () => {
|
|
78
|
-
expect(customElements.get('mu-toast-container')).toBe(MuToastContainer);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('mu-toast should have correct baseClass', () => {
|
|
82
|
-
expect(MuToast.baseClass).toBe('mu-toast');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('mu-toast-container should have correct baseClass', () => {
|
|
86
|
-
expect(MuToastContainer.baseClass).toBe('mu-toast-container');
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('mu-toast should observe correct attributes', () => {
|
|
90
|
-
expect(MuToast.observedAttributes).toContain('severity');
|
|
91
|
-
expect(MuToast.observedAttributes).toContain('duration');
|
|
92
|
-
expect(MuToast.observedAttributes).toContain('position');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// ============================================================
|
|
96
|
-
// DOM STRUCTURE
|
|
97
|
-
// ============================================================
|
|
98
|
-
|
|
99
|
-
test('mu-toast should render with base class', () => {
|
|
100
|
-
const toast = document.createElement('mu-toast');
|
|
101
|
-
toast.textContent = 'Test message';
|
|
102
|
-
body.appendChild(toast);
|
|
103
|
-
|
|
104
|
-
expect(toast.classList.contains('mu-toast')).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('mu-toast should create content wrapper', () => {
|
|
108
|
-
const toast = document.createElement('mu-toast');
|
|
109
|
-
toast.textContent = 'Test message';
|
|
110
|
-
body.appendChild(toast);
|
|
111
|
-
|
|
112
|
-
const content = toast.querySelector('.mu-toast__content');
|
|
113
|
-
expect(content).not.toBeNull();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('mu-toast should create close button', () => {
|
|
117
|
-
const toast = document.createElement('mu-toast');
|
|
118
|
-
toast.textContent = 'Test message';
|
|
119
|
-
body.appendChild(toast);
|
|
120
|
-
|
|
121
|
-
const closeBtn = toast.querySelector('.mu-toast__close');
|
|
122
|
-
expect(closeBtn).not.toBeNull();
|
|
123
|
-
expect(closeBtn.getAttribute('aria-label')).toBe('Dismiss');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test('mu-toast should preserve message in content', () => {
|
|
127
|
-
const toast = document.createElement('mu-toast');
|
|
128
|
-
toast.textContent = 'Hello World';
|
|
129
|
-
body.appendChild(toast);
|
|
130
|
-
|
|
131
|
-
const content = toast.querySelector('.mu-toast__content');
|
|
132
|
-
expect(content.textContent).toContain('Hello World');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
// ============================================================
|
|
136
|
-
// SEVERITY VARIANTS
|
|
137
|
-
// ============================================================
|
|
138
|
-
|
|
139
|
-
test('mu-toast should apply severity class', () => {
|
|
140
|
-
const toast = document.createElement('mu-toast');
|
|
141
|
-
toast.setAttribute('severity', 'success');
|
|
142
|
-
toast.textContent = 'Success!';
|
|
143
|
-
body.appendChild(toast);
|
|
144
|
-
|
|
145
|
-
expect(toast.className).toContain('mu-toast--success');
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test('mu-toast should default to info severity', () => {
|
|
149
|
-
const toast = document.createElement('mu-toast');
|
|
150
|
-
toast.textContent = 'Info message';
|
|
151
|
-
body.appendChild(toast);
|
|
152
|
-
|
|
153
|
-
expect(toast.className).toContain('mu-toast--info');
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test('mu-toast should support error severity', () => {
|
|
157
|
-
const toast = document.createElement('mu-toast');
|
|
158
|
-
toast.setAttribute('severity', 'error');
|
|
159
|
-
toast.textContent = 'Error!';
|
|
160
|
-
body.appendChild(toast);
|
|
161
|
-
|
|
162
|
-
expect(toast.className).toContain('mu-toast--error');
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test('mu-toast should support warning severity', () => {
|
|
166
|
-
const toast = document.createElement('mu-toast');
|
|
167
|
-
toast.setAttribute('severity', 'warning');
|
|
168
|
-
toast.textContent = 'Warning!';
|
|
169
|
-
body.appendChild(toast);
|
|
170
|
-
|
|
171
|
-
expect(toast.className).toContain('mu-toast--warning');
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// ============================================================
|
|
175
|
-
// DISMISS FUNCTIONALITY
|
|
176
|
-
// ============================================================
|
|
177
|
-
|
|
178
|
-
test('mu-toast.dismiss() should add exiting class', () => {
|
|
179
|
-
const toast = document.createElement('mu-toast');
|
|
180
|
-
toast.textContent = 'Test';
|
|
181
|
-
body.appendChild(toast);
|
|
182
|
-
|
|
183
|
-
toast.dismiss();
|
|
184
|
-
|
|
185
|
-
expect(toast.classList.contains('is-exiting')).toBe(true);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
test('clicking close button should dismiss toast', () => {
|
|
189
|
-
const toast = document.createElement('mu-toast');
|
|
190
|
-
toast.textContent = 'Test';
|
|
191
|
-
body.appendChild(toast);
|
|
192
|
-
|
|
193
|
-
const closeBtn = toast.querySelector('.mu-toast__close');
|
|
194
|
-
closeBtn.click();
|
|
195
|
-
|
|
196
|
-
expect(toast.classList.contains('is-exiting')).toBe(true);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// ============================================================
|
|
200
|
-
// TOAST CONTAINER
|
|
201
|
-
// ============================================================
|
|
202
|
-
|
|
203
|
-
test('mu-toast-container should render with base class', () => {
|
|
204
|
-
const container = document.createElement('mu-toast-container');
|
|
205
|
-
body.appendChild(container);
|
|
206
|
-
|
|
207
|
-
expect(container.classList.contains('mu-toast-container')).toBe(true);
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
test('mu-toast-container should have accessibility attributes', () => {
|
|
211
|
-
const container = document.createElement('mu-toast-container');
|
|
212
|
-
body.appendChild(container);
|
|
213
|
-
|
|
214
|
-
expect(container.getAttribute('role')).toBe('status');
|
|
215
|
-
expect(container.getAttribute('aria-live')).toBe('polite');
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
// ============================================================
|
|
219
|
-
// TOAST.SHOW() PROGRAMMATIC API
|
|
220
|
-
// ============================================================
|
|
221
|
-
|
|
222
|
-
test('Toast.show() should create a toast element', () => {
|
|
223
|
-
const toast = Toast.show('Test message');
|
|
224
|
-
|
|
225
|
-
expect(toast).not.toBeNull();
|
|
226
|
-
expect(toast.tagName.toLowerCase()).toBe('mu-toast');
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
test('Toast.show() should set message content', () => {
|
|
230
|
-
const toast = Toast.show('My custom message');
|
|
231
|
-
|
|
232
|
-
expect(toast.textContent).toContain('My custom message');
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
test('Toast.show() should create container if not exists', () => {
|
|
236
|
-
// Clear containers
|
|
237
|
-
document.querySelectorAll('mu-toast-container').forEach(c => c.remove());
|
|
238
|
-
|
|
239
|
-
Toast.show('Test');
|
|
240
|
-
|
|
241
|
-
const container = document.querySelector('mu-toast-container');
|
|
242
|
-
expect(container).not.toBeNull();
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
test('Toast.show() should apply severity option', () => {
|
|
246
|
-
const toast = Toast.show('Success!', { severity: 'success' });
|
|
247
|
-
|
|
248
|
-
expect(toast.getAttribute('severity')).toBe('success');
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
test('Toast.show() should apply duration option', () => {
|
|
252
|
-
const toast = Toast.show('Quick message', { duration: 1000 });
|
|
253
|
-
|
|
254
|
-
expect(toast.getAttribute('duration')).toBe('1000');
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
test('Toast.show() should respect position option', () => {
|
|
258
|
-
const toast = Toast.show('Top message', { position: 'top-right' });
|
|
259
|
-
|
|
260
|
-
const container = document.querySelector('mu-toast-container[position="top-right"]');
|
|
261
|
-
expect(container).not.toBeNull();
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
// ============================================================
|
|
265
|
-
// SIGNALBUS INTEGRATION - CRITICAL FOR LAZY LOADING FIX
|
|
266
|
-
// ============================================================
|
|
267
|
-
|
|
268
|
-
test('SignalBus should have UIEvents.TOAST_SHOW constant', () => {
|
|
269
|
-
expect(UIEvents.TOAST_SHOW).toBe('ui:toast:show');
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
test('SignalBus should have toast listener registered on module load', () => {
|
|
273
|
-
// This is the critical fix - listener auto-registers when module loads
|
|
274
|
-
expect(bus.hasListeners(UIEvents.TOAST_SHOW)).toBe(true);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
test('emitting ui:toast:show should create a toast', async () => {
|
|
278
|
-
// Clear existing toasts
|
|
279
|
-
document.querySelectorAll('mu-toast').forEach(t => t.remove());
|
|
280
|
-
|
|
281
|
-
// Emit signal
|
|
282
|
-
await bus.emit(UIEvents.TOAST_SHOW, { message: 'Signal test!' });
|
|
283
|
-
|
|
284
|
-
// Should create toast
|
|
285
|
-
const toasts = document.querySelectorAll('mu-toast');
|
|
286
|
-
expect(toasts.length).toBeGreaterThanOrEqual(1);
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
test('emitting toast signal with severity should apply it', async () => {
|
|
290
|
-
document.querySelectorAll('mu-toast').forEach(t => t.remove());
|
|
291
|
-
|
|
292
|
-
await bus.emit(UIEvents.TOAST_SHOW, {
|
|
293
|
-
message: 'Error signal!',
|
|
294
|
-
severity: 'error'
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
const toast = document.querySelector('mu-toast[severity="error"]');
|
|
298
|
-
expect(toast).not.toBeNull();
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
// ============================================================
|
|
302
|
-
// IDEMPOTENT LISTENER REGISTRATION
|
|
303
|
-
// ============================================================
|
|
304
|
-
|
|
305
|
-
test('multiple module imports should not duplicate listeners', async () => {
|
|
306
|
-
// Import module again
|
|
307
|
-
await import('../../src/components/mu-toast.js');
|
|
308
|
-
await import('../../src/components/mu-toast.js');
|
|
309
|
-
|
|
310
|
-
// Should still have only one listener
|
|
311
|
-
// (hasListeners doesn't tell us count, but we can verify it works)
|
|
312
|
-
expect(bus.hasListeners(UIEvents.TOAST_SHOW)).toBe(true);
|
|
313
|
-
|
|
314
|
-
// Emit should create only one toast
|
|
315
|
-
document.querySelectorAll('mu-toast').forEach(t => t.remove());
|
|
316
|
-
await bus.emit(UIEvents.TOAST_SHOW, { message: 'Single toast' });
|
|
317
|
-
|
|
318
|
-
const toasts = document.querySelectorAll('mu-toast');
|
|
319
|
-
expect(toasts.length).toBe(1);
|
|
320
|
-
});
|
|
321
|
-
});
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Unit Tests for mu-tooltip Component
|
|
3
|
-
* Target: 25% → 90% coverage
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { describe, test, expect, beforeAll, beforeEach } from 'bun:test';
|
|
7
|
-
import { parseHTML } from 'linkedom';
|
|
8
|
-
|
|
9
|
-
let document, customElements, body;
|
|
10
|
-
let MuTooltip;
|
|
11
|
-
|
|
12
|
-
describe('mu-tooltip Unit Tests', () => {
|
|
13
|
-
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
const dom = parseHTML('<!DOCTYPE html><html><body></body></html>');
|
|
16
|
-
document = dom.document;
|
|
17
|
-
customElements = dom.customElements;
|
|
18
|
-
body = document.body;
|
|
19
|
-
|
|
20
|
-
globalThis.window = dom.window;
|
|
21
|
-
globalThis.document = document;
|
|
22
|
-
globalThis.customElements = customElements;
|
|
23
|
-
globalThis.HTMLElement = dom.HTMLElement;
|
|
24
|
-
globalThis.requestAnimationFrame = (cb) => { cb(Date.now()); return 0; };
|
|
25
|
-
|
|
26
|
-
const module = await import('../../src/components/mu-tooltip.js');
|
|
27
|
-
MuTooltip = module.MuTooltip;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
// Cleanup any portal tooltips first
|
|
32
|
-
body.querySelectorAll('.mu-tooltip__content').forEach(t => t.remove());
|
|
33
|
-
body.querySelectorAll('mu-tooltip').forEach(t => t.remove());
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// REGISTRATION
|
|
37
|
-
test('should be registered', () => {
|
|
38
|
-
expect(customElements.get('mu-tooltip')).toBe(MuTooltip);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('should have correct baseClass', () => {
|
|
42
|
-
expect(MuTooltip.baseClass).toBe('mu-tooltip');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('should observe content and position', () => {
|
|
46
|
-
expect(MuTooltip.observedAttributes).toContain('content');
|
|
47
|
-
expect(MuTooltip.observedAttributes).toContain('position');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// RENDER
|
|
51
|
-
test('should have relative position', () => {
|
|
52
|
-
const el = document.createElement('mu-tooltip');
|
|
53
|
-
body.appendChild(el);
|
|
54
|
-
expect(el.style.position).toBe('relative');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('should have inline-block display', () => {
|
|
58
|
-
const el = document.createElement('mu-tooltip');
|
|
59
|
-
body.appendChild(el);
|
|
60
|
-
expect(el.style.display).toBe('inline-block');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// SHOW
|
|
64
|
-
test('show() should create tooltip element in body (portal)', () => {
|
|
65
|
-
const el = document.createElement('mu-tooltip');
|
|
66
|
-
el.setAttribute('content', 'Help text');
|
|
67
|
-
body.appendChild(el);
|
|
68
|
-
el.show();
|
|
69
|
-
expect(body.querySelector('.mu-tooltip__content')).not.toBeNull();
|
|
70
|
-
el.hide(); // cleanup
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('show() should set tooltip content', () => {
|
|
74
|
-
const el = document.createElement('mu-tooltip');
|
|
75
|
-
el.setAttribute('content', 'This is help');
|
|
76
|
-
body.appendChild(el);
|
|
77
|
-
el.show();
|
|
78
|
-
expect(body.querySelector('.mu-tooltip__content').textContent).toBe('This is help');
|
|
79
|
-
el.hide(); // cleanup
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('show() should add position class', () => {
|
|
83
|
-
const el = document.createElement('mu-tooltip');
|
|
84
|
-
el.setAttribute('content', 'Text');
|
|
85
|
-
el.setAttribute('position', 'bottom');
|
|
86
|
-
body.appendChild(el);
|
|
87
|
-
el.show();
|
|
88
|
-
expect(el.classList.contains('mu-tooltip--bottom')).toBe(true);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('show() should set role=tooltip', () => {
|
|
92
|
-
const el = document.createElement('mu-tooltip');
|
|
93
|
-
el.setAttribute('content', 'Text');
|
|
94
|
-
body.appendChild(el);
|
|
95
|
-
el.show();
|
|
96
|
-
expect(body.querySelector('.mu-tooltip__content').getAttribute('role')).toBe('tooltip');
|
|
97
|
-
el.hide(); // cleanup
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('show() should not create if already visible', () => {
|
|
101
|
-
const el = document.createElement('mu-tooltip');
|
|
102
|
-
el.setAttribute('content', 'Text');
|
|
103
|
-
body.appendChild(el);
|
|
104
|
-
el.show();
|
|
105
|
-
el.show();
|
|
106
|
-
expect(body.querySelectorAll('.mu-tooltip__content').length).toBe(1);
|
|
107
|
-
el.hide(); // cleanup
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('show() should not create if no content', () => {
|
|
111
|
-
const el = document.createElement('mu-tooltip');
|
|
112
|
-
body.appendChild(el);
|
|
113
|
-
el.show();
|
|
114
|
-
expect(body.querySelector('.mu-tooltip__content')).toBeNull();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// HIDE
|
|
118
|
-
test('hide() should remove tooltip from body', () => {
|
|
119
|
-
const el = document.createElement('mu-tooltip');
|
|
120
|
-
el.setAttribute('content', 'Text');
|
|
121
|
-
body.appendChild(el);
|
|
122
|
-
el.show();
|
|
123
|
-
el.hide();
|
|
124
|
-
expect(body.querySelector('.mu-tooltip__content')).toBeNull();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('hide() should handle no tooltip gracefully', () => {
|
|
128
|
-
const el = document.createElement('mu-tooltip');
|
|
129
|
-
body.appendChild(el);
|
|
130
|
-
el.hide(); // Should not throw
|
|
131
|
-
expect(body.querySelector('.mu-tooltip__content')).toBeNull();
|
|
132
|
-
});
|
|
133
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Unit Tests for mu-virtual-list Component
|
|
3
|
-
* Target: 73% → 90% coverage
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { describe, test, expect, beforeAll, beforeEach } from 'bun:test';
|
|
7
|
-
import { parseHTML } from 'linkedom';
|
|
8
|
-
|
|
9
|
-
let document, customElements, body;
|
|
10
|
-
let MuVirtualList;
|
|
11
|
-
|
|
12
|
-
describe('mu-virtual-list Unit Tests', () => {
|
|
13
|
-
|
|
14
|
-
beforeAll(async () => {
|
|
15
|
-
const dom = parseHTML('<!DOCTYPE html><html><body></body></html>');
|
|
16
|
-
document = dom.document;
|
|
17
|
-
customElements = dom.customElements;
|
|
18
|
-
body = document.body;
|
|
19
|
-
|
|
20
|
-
globalThis.window = dom.window;
|
|
21
|
-
globalThis.document = document;
|
|
22
|
-
globalThis.customElements = customElements;
|
|
23
|
-
globalThis.HTMLElement = dom.HTMLElement;
|
|
24
|
-
globalThis.requestAnimationFrame = (cb) => { cb(Date.now()); return 0; };
|
|
25
|
-
|
|
26
|
-
const module = await import('../../src/components/mu-virtual-list.js');
|
|
27
|
-
MuVirtualList = module.MuVirtualList;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
beforeEach(() => { body.innerHTML = ''; });
|
|
31
|
-
|
|
32
|
-
// REGISTRATION
|
|
33
|
-
test('should be registered', () => {
|
|
34
|
-
expect(customElements.get('mu-virtual-list')).toBe(MuVirtualList);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('should have correct baseClass', () => {
|
|
38
|
-
expect(MuVirtualList.baseClass).toBe('mu-virtual-list');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('should observe item-height, buffer', () => {
|
|
42
|
-
expect(MuVirtualList.observedAttributes).toContain('item-height');
|
|
43
|
-
expect(MuVirtualList.observedAttributes).toContain('buffer');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// RENDER
|
|
47
|
-
test('should create content container', () => {
|
|
48
|
-
const el = document.createElement('mu-virtual-list');
|
|
49
|
-
body.appendChild(el);
|
|
50
|
-
expect(el.querySelector('.mu-virtual-list__content')).not.toBeNull();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('render should be idempotent', () => {
|
|
54
|
-
const el = document.createElement('mu-virtual-list');
|
|
55
|
-
body.appendChild(el);
|
|
56
|
-
el.render();
|
|
57
|
-
expect(el.querySelectorAll('.mu-virtual-list__content').length).toBe(1);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// ITEMS
|
|
61
|
-
test('should have items getter', () => {
|
|
62
|
-
const el = document.createElement('mu-virtual-list');
|
|
63
|
-
body.appendChild(el);
|
|
64
|
-
expect(el.items).toBeDefined();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('should have items setter', () => {
|
|
68
|
-
const el = document.createElement('mu-virtual-list');
|
|
69
|
-
body.appendChild(el);
|
|
70
|
-
el.items = [1, 2, 3];
|
|
71
|
-
expect(el.items).toEqual([1, 2, 3]);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// ITEM HEIGHT
|
|
75
|
-
test.skip('should have itemHeight getter (E2E only)', () => {
|
|
76
|
-
const el = document.createElement('mu-virtual-list');
|
|
77
|
-
body.appendChild(el);
|
|
78
|
-
expect(typeof el.itemHeight).toBe('number');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('should have itemHeight setter', () => {
|
|
82
|
-
const el = document.createElement('mu-virtual-list');
|
|
83
|
-
body.appendChild(el);
|
|
84
|
-
el.itemHeight = 60;
|
|
85
|
-
expect(el.itemHeight).toBe(60);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// RENDER ITEM
|
|
89
|
-
test.skip('should have renderItem getter (E2E only)', () => {
|
|
90
|
-
const el = document.createElement('mu-virtual-list');
|
|
91
|
-
body.appendChild(el);
|
|
92
|
-
expect(el.renderItem).toBeDefined();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test.skip('should have renderItem setter (E2E only)', () => {
|
|
96
|
-
const el = document.createElement('mu-virtual-list');
|
|
97
|
-
body.appendChild(el);
|
|
98
|
-
const fn = (item) => `<div>${item}</div>`;
|
|
99
|
-
el.renderItem = fn;
|
|
100
|
-
expect(el.renderItem).toBe(fn);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// BUFFER
|
|
104
|
-
test('should default buffer to 5', () => {
|
|
105
|
-
const el = document.createElement('mu-virtual-list');
|
|
106
|
-
body.appendChild(el);
|
|
107
|
-
expect(el.getAttribute('buffer') || '5').toBe('5');
|
|
108
|
-
});
|
|
109
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Unit Tests for MuElement Base Class
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, test, expect, beforeAll } from 'bun:test';
|
|
6
|
-
|
|
7
|
-
// Setup linkedom for DOM testing
|
|
8
|
-
import { parseHTML } from 'linkedom';
|
|
9
|
-
const { document, customElements, HTMLElement } = parseHTML('<!DOCTYPE html><html><body></body></html>');
|
|
10
|
-
globalThis.document = document;
|
|
11
|
-
globalThis.customElements = customElements;
|
|
12
|
-
globalThis.HTMLElement = HTMLElement;
|
|
13
|
-
globalThis.CustomEvent = class CustomEvent extends Event {
|
|
14
|
-
constructor(type, options = {}) {
|
|
15
|
-
super(type, options);
|
|
16
|
-
this.detail = options.detail;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
describe('MuElement Base Class', () => {
|
|
21
|
-
let MuElement, define;
|
|
22
|
-
|
|
23
|
-
beforeAll(async () => {
|
|
24
|
-
const module = await import('../../src/core/MuElement.js');
|
|
25
|
-
MuElement = module.MuElement;
|
|
26
|
-
define = module.define;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('MuElement should be defined', () => {
|
|
30
|
-
expect(MuElement).toBeDefined();
|
|
31
|
-
expect(typeof MuElement).toBe('function');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('MuElement should extend HTMLElement', () => {
|
|
35
|
-
expect(MuElement.prototype instanceof HTMLElement).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('define() should register custom element', () => {
|
|
39
|
-
class TestElement extends MuElement {
|
|
40
|
-
static baseClass = 'test-element';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
define('test-element', TestElement);
|
|
44
|
-
expect(customElements.get('test-element')).toBe(TestElement);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('define() should not re-register existing element', () => {
|
|
48
|
-
class TestElement2 extends MuElement { }
|
|
49
|
-
class TestElement2Alt extends MuElement { }
|
|
50
|
-
|
|
51
|
-
define('test-element-2', TestElement2);
|
|
52
|
-
define('test-element-2', TestElement2Alt); // Should not throw
|
|
53
|
-
|
|
54
|
-
expect(customElements.get('test-element-2')).toBe(TestElement2);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('MuElement should have static observedAttributes', () => {
|
|
58
|
-
expect(Array.isArray(MuElement.observedAttributes)).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('MuElement should have static baseClass', () => {
|
|
62
|
-
expect(typeof MuElement.baseClass).toBe('string');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('connectedCallback should add base class', () => {
|
|
66
|
-
class ClassTestElement extends MuElement {
|
|
67
|
-
static baseClass = 'my-base-class';
|
|
68
|
-
}
|
|
69
|
-
define('class-test-element', ClassTestElement);
|
|
70
|
-
|
|
71
|
-
const el = document.createElement('class-test-element');
|
|
72
|
-
document.body.appendChild(el);
|
|
73
|
-
|
|
74
|
-
expect(el.classList.contains('my-base-class')).toBe(true);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('connectedCallback should call render()', () => {
|
|
78
|
-
let renderCalled = false;
|
|
79
|
-
|
|
80
|
-
class RenderTestElement extends MuElement {
|
|
81
|
-
render() {
|
|
82
|
-
renderCalled = true;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
define('render-test-element', RenderTestElement);
|
|
86
|
-
|
|
87
|
-
const el = document.createElement('render-test-element');
|
|
88
|
-
document.body.appendChild(el);
|
|
89
|
-
|
|
90
|
-
expect(renderCalled).toBe(true);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test('attr() helper should return attribute value', () => {
|
|
94
|
-
class AttrTestElement extends MuElement { }
|
|
95
|
-
define('attr-test-element', AttrTestElement);
|
|
96
|
-
|
|
97
|
-
const el = document.createElement('attr-test-element');
|
|
98
|
-
el.setAttribute('variant', 'primary');
|
|
99
|
-
document.body.appendChild(el);
|
|
100
|
-
|
|
101
|
-
expect(el.attr('variant')).toBe('primary');
|
|
102
|
-
expect(el.attr('missing', 'default')).toBe('default');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('has() helper should check attribute existence', () => {
|
|
106
|
-
class HasTestElement extends MuElement { }
|
|
107
|
-
define('has-test-element', HasTestElement);
|
|
108
|
-
|
|
109
|
-
const el = document.createElement('has-test-element');
|
|
110
|
-
el.setAttribute('disabled', '');
|
|
111
|
-
document.body.appendChild(el);
|
|
112
|
-
|
|
113
|
-
expect(el.has('disabled')).toBe(true);
|
|
114
|
-
expect(el.has('readonly')).toBe(false);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// Note: emit() uses dispatchEvent which has readonly property issues in linkedom
|
|
118
|
-
// This is tested in E2E browser tests instead
|
|
119
|
-
test.skip('emit() should dispatch custom event (tested in E2E)', () => { });
|
|
120
|
-
});
|