sdc_client 0.58.5 → 0.158.0
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/.github/workflows/node.js.yml +2 -2
- package/.idea/inspectionProfiles/Project_Default.xml +17 -0
- package/.idea/workspace.xml +122 -23
- package/.readthedocs.yaml +13 -0
- package/dist/index.js +70 -51
- package/dist/ugly.index.js +1 -1
- package/docs/api-reference.rst +225 -0
- package/docs/conf.py +11 -0
- package/docs/controllers.rst +228 -0
- package/docs/events-and-dom.rst +120 -0
- package/docs/getting-started.rst +143 -0
- package/docs/index.rst +22 -0
- package/docs/models.rst +351 -0
- package/docs/overview.rst +66 -0
- package/docs/requirements.txt +1 -0
- package/eslint.config.js +60 -0
- package/gulp/gulp.jsx +15 -13
- package/package.json +13 -3
- package/src/index.js +44 -11
- package/src/simpleDomControl/AbstractSDC.js +287 -286
- package/src/simpleDomControl/sdc_controller.js +157 -132
- package/src/simpleDomControl/sdc_dom_events.js +99 -88
- package/src/simpleDomControl/sdc_events.js +39 -40
- package/src/simpleDomControl/sdc_main.js +88 -67
- package/src/simpleDomControl/sdc_model.js +1510 -0
- package/src/simpleDomControl/sdc_params.js +44 -29
- package/src/simpleDomControl/sdc_server_call.js +153 -154
- package/src/simpleDomControl/sdc_socket.js +8 -821
- package/src/simpleDomControl/sdc_test_utils.js +77 -80
- package/src/simpleDomControl/sdc_utils.js +295 -176
- package/src/simpleDomControl/sdc_view.js +245 -177
- package/test/model.test.js +332 -0
- package/test/models/Author.js +145 -0
- package/test/models/Book.js +112 -0
- package/test/models/BookContent.js +114 -0
- package/test/models/SdcUser.js +75 -0
- package/test/models/src.js +8 -0
- package/test/sdc_model_dates.ai.test.js +57 -0
- package/test/sdc_server_call.ai.test.js +267 -0
|
@@ -1,52 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*/
|
|
4
|
-
;
|
|
4
|
+
import { app } from "./sdc_main.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
let spy = [], _originAjax;
|
|
6
|
+
let spy = [],
|
|
7
|
+
_originAjax;
|
|
9
8
|
|
|
10
9
|
function setDefaults() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return html;
|
|
24
|
-
});
|
|
10
|
+
if (!jest) throw new Error("JEST is not defined");
|
|
11
|
+
if (spy.length === 0) {
|
|
12
|
+
_originAjax = $.ajax.bind($);
|
|
13
|
+
|
|
14
|
+
spy.push(jest.spyOn($, "ajax"));
|
|
15
|
+
spy[0].mockImplementation(function (a) {
|
|
16
|
+
return _originAjax(a)
|
|
17
|
+
.then((html) => {
|
|
18
|
+
return html;
|
|
19
|
+
})
|
|
20
|
+
.catch((html) => {
|
|
21
|
+
return html;
|
|
25
22
|
});
|
|
26
|
-
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
|
|
30
27
|
function getCookie(name) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
28
|
+
let cookieValue = null;
|
|
29
|
+
if (document.cookie && document.cookie !== "") {
|
|
30
|
+
const cookies = document.cookie.split(";");
|
|
31
|
+
for (let i = 0; i < cookies.length; i++) {
|
|
32
|
+
const cookie = cookies[i].trim();
|
|
33
|
+
// Does this cookie string begin with the name we want?
|
|
34
|
+
if (cookie.substring(0, name.length + 1) === name + "=") {
|
|
35
|
+
return decodeURIComponent(cookie.substring(name.length + 1));
|
|
36
|
+
}
|
|
41
37
|
}
|
|
42
|
-
|
|
38
|
+
}
|
|
39
|
+
return "";
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
/**
|
|
46
43
|
* Returns the CSRF token
|
|
47
44
|
*/
|
|
48
45
|
export function getCsrfToken() {
|
|
49
|
-
|
|
46
|
+
return getCookie("csrftoken");
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
/**
|
|
@@ -56,36 +53,32 @@ export function getCsrfToken() {
|
|
|
56
53
|
* @returns {Promise<Array<{AbstractSDC}>>}
|
|
57
54
|
*/
|
|
58
55
|
export async function controllerFromTestHtml(html, afterLifecycle = null) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
refreshSpy.mockRestore();
|
|
84
|
-
const res = origenRefresh.apply(children[0], arguments);
|
|
85
|
-
resolve(children);
|
|
86
|
-
return res;
|
|
87
|
-
});
|
|
56
|
+
setDefaults();
|
|
57
|
+
const $body = $("body");
|
|
58
|
+
app.updateJquery();
|
|
59
|
+
$body.safeEmpty().append(html);
|
|
60
|
+
app._isInit = false;
|
|
61
|
+
app.cleanCache();
|
|
62
|
+
await app.init_sdc();
|
|
63
|
+
|
|
64
|
+
let children = app.rootController.iterateAllChildren();
|
|
65
|
+
|
|
66
|
+
if (!afterLifecycle) {
|
|
67
|
+
return children;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const origenRefresh = children[0].onRefresh;
|
|
71
|
+
|
|
72
|
+
const refreshSpy = jest.spyOn(children[0], "onRefresh");
|
|
73
|
+
|
|
74
|
+
return new Promise((resolve) => {
|
|
75
|
+
refreshSpy.mockImplementation(function () {
|
|
76
|
+
refreshSpy.mockRestore();
|
|
77
|
+
const res = origenRefresh.apply(children[0], arguments);
|
|
78
|
+
resolve(children);
|
|
79
|
+
return res;
|
|
88
80
|
});
|
|
81
|
+
});
|
|
89
82
|
}
|
|
90
83
|
|
|
91
84
|
/**
|
|
@@ -96,22 +89,26 @@ export async function controllerFromTestHtml(html, afterLifecycle = null) {
|
|
|
96
89
|
* @param origen_html{string} HTML: Mocked content of the content in your target HTML container.
|
|
97
90
|
* @returns {Promise<{AbstractSDC}>}
|
|
98
91
|
*/
|
|
99
|
-
export async function get_controller(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
$
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
92
|
+
export async function get_controller(
|
|
93
|
+
tag_name,
|
|
94
|
+
init_arguments = {},
|
|
95
|
+
origen_html = "",
|
|
96
|
+
) {
|
|
97
|
+
setDefaults();
|
|
98
|
+
const $body = $("body");
|
|
99
|
+
app.updateJquery();
|
|
100
|
+
|
|
101
|
+
$body.safeEmpty();
|
|
102
|
+
|
|
103
|
+
const $controller = $(`<${tag_name}>${origen_html}</${tag_name}>`);
|
|
104
|
+
for (const [key, value] of Object.entries(init_arguments)) {
|
|
105
|
+
$controller.data(key, value);
|
|
106
|
+
}
|
|
107
|
+
const $divContainer = $("<div></div>").append($controller);
|
|
108
|
+
|
|
109
|
+
$body.append($divContainer);
|
|
110
|
+
app._isInit = false;
|
|
111
|
+
app.cleanCache();
|
|
112
|
+
await app.init_sdc();
|
|
113
|
+
return app.getController($controller);
|
|
114
|
+
}
|