lightview 2.2.2 → 2.3.4

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,125 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from 'vitest';
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import Lightview from '../../src/lightview.js';
6
- import LightviewX from '../../src/lightview-x.js';
7
- import LightviewCDOM from '../../src/lightview-cdom.js';
8
-
9
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
-
11
- describe('cdom Full Loader Tests', () => {
12
- let handleSrc;
13
-
14
- beforeEach(() => {
15
- globalThis.window = globalThis;
16
- globalThis.__DEBUG__ = true;
17
- globalThis.Lightview = Lightview;
18
- globalThis.LightviewX = LightviewX;
19
- globalThis.LightviewCDOM = LightviewCDOM;
20
-
21
- if (typeof document !== 'undefined') {
22
- document.body.innerHTML = '';
23
- }
24
-
25
- Lightview.registry.clear();
26
- LightviewX.state({
27
- user: {
28
- name: 'Alice',
29
- age: 30,
30
- role: 'Admin',
31
- status: 'Available',
32
- score: 100,
33
- level: 5,
34
- points: [10, 20, 30],
35
- isVip: true,
36
- account: { type: 'Premium' },
37
- details: { city: 'NYC', zip: '10001' },
38
- discount: 10,
39
- activity: {
40
- purchases: [5, 10, 15]
41
- }
42
- }
43
- }, 'app');
44
-
45
- if (globalThis.LightviewX?.internals?.handleSrcAttribute) {
46
- handleSrc = globalThis.LightviewX.internals.handleSrcAttribute;
47
- }
48
-
49
- globalThis.fetch = vi.fn().mockImplementation((url) => {
50
- const fileName = url.toString().split('/').pop();
51
- const filePath = path.join(__dirname, 'fixtures', fileName);
52
- if (!fs.existsSync(filePath)) return Promise.resolve({ ok: false, status: 404 });
53
- const content = fs.readFileSync(filePath, 'utf8');
54
- return Promise.resolve({
55
- ok: true,
56
- text: () => Promise.resolve(content),
57
- json: () => Promise.resolve(JSON.parse(content)),
58
- url: url.toString()
59
- });
60
- });
61
- });
62
-
63
- const cleanHTML = (html) => html.replace(/<!--lv:[se]-->/g, '').replace(/\s+/g, ' ').trim();
64
-
65
- it('should load and parse user.vdom with cdom expressions', async () => {
66
- const container = Lightview.tags.div({ src: '/user.vdom' });
67
- await handleSrc(container, '/user.vdom', 'div', {
68
- element: Lightview.element,
69
- setupChildren: Lightview.internals.setupChildren
70
- });
71
-
72
- const html = cleanHTML(container.domEl.innerHTML);
73
- expect(html).toContain('Alice');
74
- expect(html).toContain('Age: 30');
75
- expect(html).toContain('Account: Premium');
76
- expect(html).toContain('VIP Status: Yes');
77
- expect(html).toContain('Location: NYC');
78
- });
79
-
80
- it('should load and parse user.odom with cdom expressions', async () => {
81
- const container = Lightview.tags.div({ src: '/user.odom' });
82
- await handleSrc(container, '/user.odom', 'div', {
83
- element: Lightview.element,
84
- setupChildren: Lightview.internals.setupChildren
85
- });
86
-
87
- const html = cleanHTML(container.domEl.innerHTML);
88
- expect(html).toContain('Alice');
89
- expect(html).toContain('Score: 100');
90
- expect(html).toContain('Level: 5');
91
- // Activity: purchases [5, 10, 15] -> sum = 30
92
- expect(html).toContain('Activity Total: 30');
93
- // Relative path: ../discount (10) * sum(purchases...) (30) = 300
94
- expect(html).toContain('With Discount: 300');
95
- });
96
-
97
- it('should load and parse user.cdom (JSON ODOM file)', async () => {
98
- const container = Lightview.tags.div({ src: '/user.cdom' });
99
- await handleSrc(container, '/user.cdom', 'div', {
100
- element: Lightview.element,
101
- setupChildren: Lightview.internals.setupChildren
102
- });
103
-
104
- const html = cleanHTML(container.domEl.innerHTML);
105
- expect(html).toContain('cdom-card');
106
- expect(html).toContain('Welcome, Alice');
107
- expect(html).toContain('(VIP)');
108
- expect(html).toContain('Discount: 20%');
109
- });
110
-
111
- it('should load and parse user.cdomc (Unquoted Properties/Expressions)', async () => {
112
- const container = Lightview.tags.div({ src: '/user.cdomc' });
113
- await handleSrc(container, '/user.cdomc', 'div', {
114
- element: Lightview.element,
115
- setupChildren: Lightview.internals.setupChildren
116
- });
117
-
118
- const html = cleanHTML(container.domEl.innerHTML);
119
- if (__DEBUG__) console.log('ACTUAL HTML:', html);
120
- expect(html).toContain('profile-compiled');
121
- expect(html).toContain('Alice');
122
- expect(html).toContain('Available');
123
- expect(html).toContain('Tier: Platinum');
124
- });
125
- });