sdc_client 0.57.11 → 0.57.14
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/.idea/misc.xml +2 -2
- package/.idea/workspace.xml +125 -40
- package/SimpleDomControlClient.iml +5 -2
- package/dist/index.js +8 -8
- package/dist/ugly.index.js +1 -1
- package/package.json +1 -1
- package/src/simpleDomControl/AbstractSDC.js +9 -4
- package/src/simpleDomControl/sdc_controller.js +69 -17
- package/src/simpleDomControl/sdc_dom_events.js +1 -1
- package/src/simpleDomControl/sdc_main.js +361 -365
- package/src/simpleDomControl/sdc_socket.js +31 -10
- package/src/simpleDomControl/sdc_test_utils.js +34 -10
- package/src/simpleDomControl/sdc_utils.js +46 -24
- package/src/simpleDomControl/sdc_view.js +382 -206
- package/test/controller.test.js +1 -41
- package/test/dist.test.js +1 -1
- package/test/utils.js +89 -0
- package/test/view.test.js +158 -0
package/test/controller.test.js
CHANGED
|
@@ -9,49 +9,9 @@ import * as sdc_view from '../src/simpleDomControl/sdc_view.js';
|
|
|
9
9
|
const app = sdc.app;
|
|
10
10
|
|
|
11
11
|
import $ from 'jquery';
|
|
12
|
+
import {TestCtr, TestCtrA} from "./utils.js";
|
|
12
13
|
window.$ = $;
|
|
13
14
|
|
|
14
|
-
const TestControllerInfo = {
|
|
15
|
-
name: 'TestCtr',
|
|
16
|
-
tag: 'test-ctr'
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
class TestCtr extends sdc.AbstractSDC {
|
|
20
|
-
constructor() {
|
|
21
|
-
super();
|
|
22
|
-
this.contentUrl = TestControllerInfo.name; //<test-ctr>
|
|
23
|
-
this.events.unshift({});
|
|
24
|
-
this.val = 0;
|
|
25
|
-
this.contentReload = true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
sayA() {
|
|
29
|
-
return 'A'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
onInit() {}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
class TestCtrA extends sdc.AbstractSDC {
|
|
36
|
-
constructor() {
|
|
37
|
-
super();
|
|
38
|
-
this.contentUrl = 'TestCtrA'; //<test-ctr-a>
|
|
39
|
-
this.events.unshift({});
|
|
40
|
-
this.val = 1;
|
|
41
|
-
this.val_2 = 2;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
sayA() {
|
|
45
|
-
return 'B'
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
sayB() {
|
|
49
|
-
return 'B'
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
onInit() {}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
15
|
describe('Controller', () => {
|
|
56
16
|
let ajaxSpy;
|
|
57
17
|
beforeEach(() => {
|
package/test/dist.test.js
CHANGED
package/test/utils.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {AbstractSDC} from "../src/index.js";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const TestControllerInfo = {
|
|
5
|
+
name: 'TestCtr',
|
|
6
|
+
tag: 'test-ctr'
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export class TestCtr extends AbstractSDC {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.contentUrl = TestControllerInfo.name; //<test-ctr>
|
|
13
|
+
this.events.unshift({});
|
|
14
|
+
this.val = 0;
|
|
15
|
+
this.contentReload = true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
sayA() {
|
|
19
|
+
return 'A'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
onInit() {
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class TestCtrA extends AbstractSDC {
|
|
27
|
+
constructor() {
|
|
28
|
+
super();
|
|
29
|
+
this.contentUrl = 'TestCtrA'; //<test-ctr-a>
|
|
30
|
+
this.events.unshift({});
|
|
31
|
+
this.val = 1;
|
|
32
|
+
this.val_2 = 2;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
sayA() {
|
|
36
|
+
return 'B'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
sayB() {
|
|
40
|
+
return 'B'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
onInit() {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class TestList extends AbstractSDC {
|
|
48
|
+
constructor() {
|
|
49
|
+
super();
|
|
50
|
+
this.contentUrl = 'TestCtrA'; //<test-ctr-a>
|
|
51
|
+
this.events.unshift({});
|
|
52
|
+
this.number = 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onInit(number = 10) {
|
|
56
|
+
this.number = number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onLoad(html) {
|
|
60
|
+
$(html).append('<div><this.listview></this.listview></div>');
|
|
61
|
+
return super.onLoad(html);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
listview() {
|
|
65
|
+
const listItems = [];
|
|
66
|
+
for (let i = 0; i < this.number; i++) {
|
|
67
|
+
listItems.push(`<test-item data-idx="${i}"></test-item>`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return `<div>${listItems.join('\n')}</div>`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class TestItem extends AbstractSDC {
|
|
75
|
+
constructor() {
|
|
76
|
+
super();
|
|
77
|
+
this.contentUrl = 'TestCtrA'; //<test-item>
|
|
78
|
+
this.events.unshift({});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
onInit(idx) {
|
|
82
|
+
this.idx = idx;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
onLoad(html) {
|
|
86
|
+
$(html).append(`<input name="i_${this.idx}" />`);
|
|
87
|
+
return super.onLoad(html);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {TestItem, TestList} from "./utils.js";
|
|
6
|
+
import {reconcile} from "../src/simpleDomControl/sdc_view.js";
|
|
7
|
+
import {app} from "../src/index.js";
|
|
8
|
+
import $ from "jquery";
|
|
9
|
+
|
|
10
|
+
window.$ = $;
|
|
11
|
+
|
|
12
|
+
describe('Test reconcile', () => {
|
|
13
|
+
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
app.updateJquery();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('Load Content', async () => {
|
|
19
|
+
const a = '<div>' +
|
|
20
|
+
'<h1>Test</h1>' +
|
|
21
|
+
'<ul>' +
|
|
22
|
+
'<li>B</li>' +
|
|
23
|
+
'<li><input name="TEST" /></li>' +
|
|
24
|
+
'<li>D</li>' +
|
|
25
|
+
'</ul>' +
|
|
26
|
+
'</div>';
|
|
27
|
+
|
|
28
|
+
const b = '<div class="class.1">' +
|
|
29
|
+
'<p>UPS</p>' +
|
|
30
|
+
'<p>UPS</p>' +
|
|
31
|
+
'<h1>Test 1</h1>' +
|
|
32
|
+
'<ul>' +
|
|
33
|
+
'<li>A</li>' +
|
|
34
|
+
'<li>A1 <input name="TEST" type="text"/></li>' +
|
|
35
|
+
'<li>B</li>' +
|
|
36
|
+
'<li><input name="TEST" type="text"/></li>' +
|
|
37
|
+
'<li>D</li>' +
|
|
38
|
+
'</ul>' +
|
|
39
|
+
'</div>';
|
|
40
|
+
const $b = $(b);
|
|
41
|
+
const $a = $(a);
|
|
42
|
+
const input_a = $a.find('[name=TEST]')[0]
|
|
43
|
+
reconcile($b, $a);
|
|
44
|
+
expect($a.html()).toBe($(b).html());
|
|
45
|
+
expect($a[0].className).toBe('class.1');
|
|
46
|
+
expect(input_a).toBe($a.find('[name=TEST]')[0]);
|
|
47
|
+
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('Load Content 2', async () => {
|
|
51
|
+
const a = '<div>' +
|
|
52
|
+
'<p>UPS</p>' +
|
|
53
|
+
'<p>UPS</p>' +
|
|
54
|
+
'<h1>Test</h1>' +
|
|
55
|
+
'<ul>' +
|
|
56
|
+
'<li>B</li>' +
|
|
57
|
+
'<li><input name="TEST" /></li>' +
|
|
58
|
+
'<li>D</li>' +
|
|
59
|
+
'</ul>' +
|
|
60
|
+
'</div>';
|
|
61
|
+
|
|
62
|
+
const b = '<div class="class.1">' +
|
|
63
|
+
'<h1>Test 1</h1>' +
|
|
64
|
+
'<ul>' +
|
|
65
|
+
'<li>A</li>' +
|
|
66
|
+
'<li>A1 <input name="TEST" type="text"/></li>' +
|
|
67
|
+
'<li>B</li>' +
|
|
68
|
+
'<li><input name="TEST" type="text"/></li>' +
|
|
69
|
+
'<li>D</li>' +
|
|
70
|
+
'</ul>' +
|
|
71
|
+
'</div>';
|
|
72
|
+
const $b = $(b);
|
|
73
|
+
const $a = $(a);
|
|
74
|
+
const input_a = $a.find('[name=TEST]')[0]
|
|
75
|
+
reconcile($b, $a);
|
|
76
|
+
expect($a.html()).toBe($(b).html());
|
|
77
|
+
expect($a[0].className).toBe('class.1');
|
|
78
|
+
expect(input_a).toBe($a.find('[name=TEST]')[0]);
|
|
79
|
+
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('Load content 3', () => {
|
|
83
|
+
const a = '<div>' +
|
|
84
|
+
'<div><p>A1</p><p>B1</p></div>' +
|
|
85
|
+
'<div><p>A2</p><p>B2</p></div>' +
|
|
86
|
+
'</div>';
|
|
87
|
+
|
|
88
|
+
const b = '<div>' +
|
|
89
|
+
'<div><p>A2</p><p>B3</p></div>' +
|
|
90
|
+
'<div><p>A2</p><p>B4</p></div>' +
|
|
91
|
+
'</div>';
|
|
92
|
+
const $b = $(b);
|
|
93
|
+
const $a = $(a);
|
|
94
|
+
reconcile($b, $a);
|
|
95
|
+
expect($a.html()).toBe($(b).html());
|
|
96
|
+
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
test('Load Content Split', async () => {
|
|
101
|
+
const a = '<div>' +
|
|
102
|
+
'<ul>' +
|
|
103
|
+
'<li>X<input name="TEST" /></li>' +
|
|
104
|
+
'</ul>' +
|
|
105
|
+
'</div>';
|
|
106
|
+
|
|
107
|
+
const b = '<div class="class.1">' +
|
|
108
|
+
'<ul>' +
|
|
109
|
+
'<li>A1 <input name="TEST" type="text"/></li>' +
|
|
110
|
+
'<li>X</li>' +
|
|
111
|
+
'</ul>' +
|
|
112
|
+
'</div>';
|
|
113
|
+
const $b = $(b);
|
|
114
|
+
const $a = $(a);
|
|
115
|
+
const input_a = $a.find('[name=TEST]')[0]
|
|
116
|
+
reconcile($b, $a);
|
|
117
|
+
expect($a.html()).toBe($(b).html());
|
|
118
|
+
expect($a[0].className).toBe('class.1');
|
|
119
|
+
expect(input_a).toBe($a.find('[name=TEST]')[0]);
|
|
120
|
+
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('Controller reconcile', () => {
|
|
125
|
+
let ajaxSpy;
|
|
126
|
+
beforeEach(async () => {
|
|
127
|
+
ajaxSpy = jest.spyOn($, 'ajax');
|
|
128
|
+
ajaxSpy.mockImplementation(() => {
|
|
129
|
+
return Promise.resolve('<div></div>');
|
|
130
|
+
});
|
|
131
|
+
app.register(TestList);
|
|
132
|
+
app.register(TestItem);
|
|
133
|
+
const $body = $('body');
|
|
134
|
+
const $ctr_div = $(document.createElement('test-list'));
|
|
135
|
+
$body.append($ctr_div);
|
|
136
|
+
await app.init_sdc();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
afterEach(() => {
|
|
140
|
+
jest.restoreAllMocks();
|
|
141
|
+
$('body').safeEmpty();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('Load Content Split', async () => {
|
|
145
|
+
const oldList = $('body').find('input').toArray();
|
|
146
|
+
const controller = app.getController($('body').children());
|
|
147
|
+
controller.number = 5;
|
|
148
|
+
await controller.refresh();
|
|
149
|
+
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
150
|
+
const newList = $('body').find('input').toArray();
|
|
151
|
+
expect(newList.length).toBe(5);
|
|
152
|
+
newList.forEach((x, i) => {
|
|
153
|
+
expect(x).toBe(oldList[i]);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
});
|
|
158
|
+
});
|