@etsoo/shared 1.2.52 → 1.2.55
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/main.yml +6 -5
- package/__tests__/ArrayUtils.ts +126 -126
- package/__tests__/ColorUtils.ts +24 -24
- package/__tests__/ContentDisposition.ts +18 -18
- package/__tests__/DataTypes.ts +222 -204
- package/__tests__/DateUtils.ts +82 -82
- package/__tests__/DomUtils.ts +352 -352
- package/__tests__/EHistory.ts +62 -62
- package/__tests__/ExtendUtils.ts +40 -40
- package/__tests__/Keyboard.ts +14 -14
- package/__tests__/NumberUtils.ts +37 -39
- package/__tests__/StorageUtils.ts +27 -27
- package/__tests__/Utils.ts +361 -363
- package/__tests__/tsconfig.json +15 -15
- package/lib/cjs/ActionResult.d.ts +1 -1
- package/lib/cjs/ActionResult.js +3 -3
- package/lib/cjs/ArrayUtils.d.ts +1 -1
- package/lib/cjs/ArrayUtils.js +4 -4
- package/lib/cjs/ColorUtils.d.ts +1 -1
- package/lib/cjs/ColorUtils.js +2 -2
- package/lib/cjs/DataTypes.d.ts +6 -6
- package/lib/cjs/DataTypes.js +50 -51
- package/lib/cjs/DateUtils.d.ts +1 -1
- package/lib/cjs/DateUtils.js +27 -28
- package/lib/cjs/DomUtils.d.ts +3 -3
- package/lib/cjs/DomUtils.js +64 -73
- package/lib/cjs/ExtendUtils.d.ts +1 -1
- package/lib/cjs/ExtendUtils.js +6 -6
- package/lib/cjs/IActionResult.d.ts +1 -1
- package/lib/cjs/NumberUtils.d.ts +1 -1
- package/lib/cjs/NumberUtils.js +9 -9
- package/lib/cjs/StorageUtils.js +2 -2
- package/lib/cjs/Utils.d.ts +4 -4
- package/lib/cjs/Utils.js +58 -62
- package/lib/cjs/index.d.ts +22 -22
- package/lib/cjs/storage/WindowStorage.d.ts +1 -1
- package/lib/cjs/types/ContentDisposition.d.ts +2 -2
- package/lib/cjs/types/ContentDisposition.js +11 -13
- package/lib/cjs/types/EColor.js +5 -7
- package/lib/cjs/types/EHistory.d.ts +3 -3
- package/lib/cjs/types/EHistory.js +4 -4
- package/lib/cjs/types/ErrorData.d.ts +1 -1
- package/lib/cjs/types/EventClass.js +1 -1
- package/lib/mjs/ActionResult.d.ts +1 -1
- package/lib/mjs/ActionResult.js +3 -3
- package/lib/mjs/ArrayUtils.d.ts +1 -1
- package/lib/mjs/ArrayUtils.js +5 -5
- package/lib/mjs/ColorUtils.d.ts +1 -1
- package/lib/mjs/ColorUtils.js +3 -3
- package/lib/mjs/DataTypes.d.ts +6 -6
- package/lib/mjs/DataTypes.js +50 -51
- package/lib/mjs/DateUtils.d.ts +1 -1
- package/lib/mjs/DateUtils.js +27 -28
- package/lib/mjs/DomUtils.d.ts +3 -3
- package/lib/mjs/DomUtils.js +67 -76
- package/lib/mjs/ExtendUtils.d.ts +1 -1
- package/lib/mjs/ExtendUtils.js +6 -6
- package/lib/mjs/IActionResult.d.ts +1 -1
- package/lib/mjs/NumberUtils.d.ts +1 -1
- package/lib/mjs/NumberUtils.js +9 -9
- package/lib/mjs/StorageUtils.js +4 -4
- package/lib/mjs/Utils.d.ts +4 -4
- package/lib/mjs/Utils.js +61 -65
- package/lib/mjs/index.d.ts +22 -22
- package/lib/mjs/index.js +22 -22
- package/lib/mjs/storage/WindowStorage.d.ts +1 -1
- package/lib/mjs/storage/WindowStorage.js +2 -2
- package/lib/mjs/types/ContentDisposition.d.ts +2 -2
- package/lib/mjs/types/ContentDisposition.js +12 -14
- package/lib/mjs/types/EColor.js +5 -7
- package/lib/mjs/types/EHistory.d.ts +3 -3
- package/lib/mjs/types/EHistory.js +5 -5
- package/lib/mjs/types/ErrorData.d.ts +1 -1
- package/lib/mjs/types/EventClass.js +1 -1
- package/package.json +61 -63
- package/src/ActionResult.ts +23 -23
- package/src/ArrayUtils.ts +164 -172
- package/src/ColorUtils.ts +80 -82
- package/src/DataTypes.ts +745 -754
- package/src/DateUtils.ts +266 -268
- package/src/DomUtils.ts +806 -831
- package/src/ExtendUtils.ts +191 -191
- package/src/IActionResult.ts +42 -42
- package/src/Keyboard.ts +258 -258
- package/src/NumberUtils.ts +135 -135
- package/src/StorageUtils.ts +117 -117
- package/src/Utils.ts +908 -930
- package/src/index.ts +22 -22
- package/src/node/Storage.ts +53 -53
- package/src/storage/IStorage.ts +62 -62
- package/src/storage/WindowStorage.ts +140 -140
- package/src/types/ContentDisposition.ts +59 -63
- package/src/types/DataError.ts +15 -15
- package/src/types/DelayedExecutorType.ts +15 -15
- package/src/types/EColor.ts +241 -248
- package/src/types/EHistory.ts +151 -151
- package/src/types/ErrorData.ts +11 -11
- package/src/types/EventClass.ts +220 -220
- package/src/types/FormData.ts +25 -25
- package/src/types/ParsedPath.ts +5 -5
- package/tsconfig.cjs.json +16 -16
- package/tsconfig.json +16 -16
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -29
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
package/__tests__/DomUtils.ts
CHANGED
|
@@ -1,432 +1,432 @@
|
|
|
1
|
-
import { DomUtils } from
|
|
2
|
-
import { DataTypes } from
|
|
3
|
-
import { DateUtils } from
|
|
4
|
-
import { ErrorData } from
|
|
1
|
+
import { DomUtils } from "../src/DomUtils";
|
|
2
|
+
import { DataTypes } from "../src/DataTypes";
|
|
3
|
+
import { DateUtils } from "../src/DateUtils";
|
|
4
|
+
import { ErrorData } from "../src/types/ErrorData";
|
|
5
5
|
|
|
6
6
|
// Implement for tests
|
|
7
7
|
class Rect implements DOMRect {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
constructor(width: number, height: number, x: number = 0, y: number = 0) {
|
|
30
|
-
this.x = x;
|
|
31
|
-
this.y = y;
|
|
32
|
-
this.width = width;
|
|
33
|
-
this.height = height;
|
|
34
|
-
|
|
35
|
-
this.left = x;
|
|
36
|
-
this.top = y;
|
|
37
|
-
this.bottom = this.top + this.height;
|
|
38
|
-
this.right = this.left = this.width;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe('Tests for clearFormData', () => {
|
|
43
|
-
// Applies only to tests in this describe block
|
|
44
|
-
// Arrange
|
|
45
|
-
let form: FormData;
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
form = new FormData();
|
|
48
|
-
form.append('id', '1');
|
|
49
|
-
form.append('item', 'a');
|
|
50
|
-
form.append('item', 'b');
|
|
51
|
-
form.append('item', 'c');
|
|
52
|
-
form.append('job', 'good');
|
|
53
|
-
form.append('empty', '');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('Remove empties only', () => {
|
|
57
|
-
const result = DomUtils.clearFormData(form);
|
|
58
|
-
expect(Array.from(result.keys()).includes('empty')).toBeFalsy();
|
|
8
|
+
readonly bottom: number;
|
|
9
|
+
readonly height: number;
|
|
10
|
+
readonly left: number;
|
|
11
|
+
readonly right: number;
|
|
12
|
+
readonly top: number;
|
|
13
|
+
readonly width: number;
|
|
14
|
+
readonly x: number;
|
|
15
|
+
readonly y: number;
|
|
16
|
+
toJSON(): any {
|
|
17
|
+
return JSON.stringify({
|
|
18
|
+
bottom: this.bottom,
|
|
19
|
+
height: this.height,
|
|
20
|
+
left: this.left,
|
|
21
|
+
right: this.right,
|
|
22
|
+
top: this.top,
|
|
23
|
+
width: this.width,
|
|
24
|
+
x: this.x,
|
|
25
|
+
y: this.y
|
|
59
26
|
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor(width: number, height: number, x: number = 0, y: number = 0) {
|
|
30
|
+
this.x = x;
|
|
31
|
+
this.y = y;
|
|
32
|
+
this.width = width;
|
|
33
|
+
this.height = height;
|
|
34
|
+
|
|
35
|
+
this.left = x;
|
|
36
|
+
this.top = y;
|
|
37
|
+
this.bottom = this.top + this.height;
|
|
38
|
+
this.right = this.left = this.width;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
60
41
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
42
|
+
describe("Tests for clearFormData", () => {
|
|
43
|
+
// Applies only to tests in this describe block
|
|
44
|
+
// Arrange
|
|
45
|
+
let form: FormData;
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
form = new FormData();
|
|
48
|
+
form.append("id", "1");
|
|
49
|
+
form.append("item", "a");
|
|
50
|
+
form.append("item", "b");
|
|
51
|
+
form.append("item", "c");
|
|
52
|
+
form.append("job", "good");
|
|
53
|
+
form.append("empty", "");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("Remove empties only", () => {
|
|
57
|
+
const result = DomUtils.clearFormData(form);
|
|
58
|
+
expect(Array.from(result.keys()).includes("empty")).toBeFalsy();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("Clear with source", () => {
|
|
62
|
+
const result = DomUtils.clearFormData(form, { id: 1, job: "good" });
|
|
63
|
+
const keys = Array.from(result.keys());
|
|
64
|
+
expect(expect.arrayContaining(keys)).not.toContainEqual(
|
|
65
|
+
expect.arrayContaining(["id", "job", "empty"])
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
test("Clear with source and hold fields", () => {
|
|
70
|
+
const result = DomUtils.clearFormData(form, {}, ["id"]);
|
|
71
|
+
const keys = Array.from(result.keys());
|
|
72
|
+
expect(keys.includes("id")).toBeTruthy();
|
|
73
|
+
});
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
test(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
test("Tests for formDataToObject", () => {
|
|
77
|
+
// Arrange
|
|
78
|
+
const form1 = new FormData();
|
|
79
|
+
form1.append("item", "a");
|
|
80
|
+
form1.append("item", "b");
|
|
81
|
+
form1.append("item", "c");
|
|
82
|
+
form1.append("job", "good");
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
// Act
|
|
85
|
+
const result = DomUtils.formDataToObject(form1);
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
// Assert
|
|
88
|
+
expect(Array.isArray(result["item"])).toBeTruthy();
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
test(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
91
|
+
test("Tests for mergeFormData", () => {
|
|
92
|
+
// Arrange
|
|
93
|
+
const form1 = new FormData();
|
|
94
|
+
form1.append("item", "a");
|
|
95
|
+
form1.append("item", "b");
|
|
96
|
+
form1.append("item", "c");
|
|
97
|
+
form1.append("job", "good");
|
|
98
|
+
form1.append("job", "bad");
|
|
99
|
+
|
|
100
|
+
const form2 = new FormData();
|
|
101
|
+
form2.append("job", "x");
|
|
102
|
+
form2.append("job", "y");
|
|
103
|
+
|
|
104
|
+
// Act
|
|
105
|
+
const result = DomUtils.mergeFormData(form1, form2);
|
|
106
|
+
const values = result.getAll("job");
|
|
107
|
+
|
|
108
|
+
// Assert
|
|
109
|
+
expect(values.includes("x")).toBeTruthy();
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
test(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
test("Tests for dimensionEqual", () => {
|
|
113
|
+
const rect1: DOMRect = new Rect(200, 300);
|
|
114
|
+
const rect2: DOMRect = new Rect(100, 200);
|
|
115
|
+
expect(DomUtils.dimensionEqual(undefined, undefined)).toBeTruthy();
|
|
116
|
+
expect(DomUtils.dimensionEqual(rect1, undefined)).toBeFalsy();
|
|
117
|
+
expect(DomUtils.dimensionEqual(rect1, rect2)).toBeFalsy();
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
-
test(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
test("Tests for formDataToObject", () => {
|
|
121
|
+
const formData = new FormData();
|
|
122
|
+
formData.append("id", "1234");
|
|
123
|
+
formData.append("name", "test");
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
expect(DomUtils.formDataToObject(formData)).toEqual({
|
|
126
|
+
id: "1234",
|
|
127
|
+
name: "test"
|
|
128
|
+
});
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
-
test(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
131
|
+
test("Tests for dataAs", () => {
|
|
132
|
+
const formData = new FormData();
|
|
133
|
+
formData.append("id", "1234");
|
|
134
|
+
formData.append("name", "test");
|
|
135
|
+
formData.append("price", "34.25");
|
|
136
|
+
formData.append("options", "1,2,3,4");
|
|
137
|
+
formData.append("memo", "Memo");
|
|
138
|
+
formData.append("email", "a@b");
|
|
139
|
+
formData.append("email", "c@d");
|
|
140
|
+
formData.append("code", "123");
|
|
141
|
+
formData.append("code", "456");
|
|
142
|
+
|
|
143
|
+
const data = DomUtils.dataAs(formData, {
|
|
144
|
+
id: "number",
|
|
145
|
+
name: "string",
|
|
146
|
+
price: "number",
|
|
147
|
+
options: "number[]",
|
|
148
|
+
email: "string[]",
|
|
149
|
+
code: "number[]"
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
expect(data.id).toStrictEqual(1234);
|
|
153
|
+
expect(data.options?.length).toStrictEqual(4);
|
|
154
|
+
expect(data.options![0]).toStrictEqual(1);
|
|
155
|
+
|
|
156
|
+
expect(data.email).toEqual(["a@b", "c@d"]);
|
|
157
|
+
expect(data.code?.length).toStrictEqual(2);
|
|
158
|
+
expect(data.code).toEqual([123, 456]);
|
|
159
|
+
expect(data).not.toHaveProperty("memo", "Memo");
|
|
160
|
+
|
|
161
|
+
const keepSourceData = DomUtils.dataAs(
|
|
162
|
+
formData,
|
|
163
|
+
{
|
|
164
|
+
id: "number",
|
|
165
|
+
name: "string",
|
|
166
|
+
price: "number",
|
|
167
|
+
options: "number[]"
|
|
168
|
+
},
|
|
169
|
+
true
|
|
170
|
+
);
|
|
171
|
+
expect(keepSourceData).toHaveProperty("memo", "Memo");
|
|
172
172
|
});
|
|
173
173
|
|
|
174
|
-
test(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
174
|
+
test("Tests for dataValueAs", () => {
|
|
175
|
+
const formData = new FormData();
|
|
176
|
+
formData.append("id", "1234");
|
|
177
|
+
formData.append("name", "test");
|
|
178
|
+
formData.append("price", "34.25");
|
|
179
|
+
formData.append("options", "1,2,3,4");
|
|
180
|
+
formData.append("memo", "Memo");
|
|
181
|
+
|
|
182
|
+
const templateValue = {
|
|
183
|
+
id: 0,
|
|
184
|
+
name: "",
|
|
185
|
+
price: 0,
|
|
186
|
+
options: [0]
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const data = DomUtils.dataValueAs(formData, templateValue);
|
|
190
|
+
|
|
191
|
+
expect(data.id).toStrictEqual(1234);
|
|
192
|
+
expect(data.options?.length).toStrictEqual(4);
|
|
193
|
+
expect(data.options![0]).toStrictEqual(1);
|
|
194
|
+
expect(data).not.toHaveProperty("memo", "Memo");
|
|
195
|
+
|
|
196
|
+
const keepSourceData = DomUtils.dataValueAs(formData, templateValue, true);
|
|
197
|
+
expect(keepSourceData).toHaveProperty("memo", "Memo");
|
|
198
198
|
});
|
|
199
199
|
|
|
200
|
-
test(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
200
|
+
test("Tests for dataValueAs", () => {
|
|
201
|
+
const formData = new FormData();
|
|
202
|
+
formData.append("id", "1234");
|
|
203
|
+
formData.append("name", "test");
|
|
204
|
+
formData.append("price", "34.25");
|
|
205
|
+
formData.append("options", "1,2,3,4");
|
|
206
|
+
|
|
207
|
+
const data = DomUtils.dataValueAs(formData, {
|
|
208
|
+
id: 0,
|
|
209
|
+
name: "",
|
|
210
|
+
price: 0,
|
|
211
|
+
options: [0]
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
expect(data.id).toStrictEqual(1234);
|
|
215
|
+
expect(data.options?.length).toStrictEqual(4);
|
|
216
|
+
expect(data.options![0]).toStrictEqual(1);
|
|
217
217
|
});
|
|
218
218
|
|
|
219
|
-
test(
|
|
220
|
-
|
|
219
|
+
test("Tests for detectedCulture", () => {
|
|
220
|
+
expect(DomUtils.detectedCulture).toBe("en-US");
|
|
221
221
|
});
|
|
222
222
|
|
|
223
|
-
test(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
223
|
+
test("Tests for getCulture", () => {
|
|
224
|
+
const cultures: DataTypes.CultureDefinition[] = [
|
|
225
|
+
{
|
|
226
|
+
name: "zh-Hans",
|
|
227
|
+
label: "简体中文",
|
|
228
|
+
resources: {},
|
|
229
|
+
compatibleNames: ["zh-CN", "zh-SG"]
|
|
230
|
+
},
|
|
231
|
+
{ name: "en", label: "English", resources: {} }
|
|
232
|
+
];
|
|
233
233
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
234
|
+
const [culture1, match1] = DomUtils.getCulture(cultures, "zh-CN");
|
|
235
|
+
expect(culture1?.name).toBe("zh-Hans");
|
|
236
|
+
expect(match1).toBe(DomUtils.CultureMatch.Compatible);
|
|
237
237
|
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
const [culture2] = DomUtils.getCulture(cultures, "zh-Hans-CN");
|
|
239
|
+
expect(culture2?.name).toBe("zh-Hans");
|
|
240
240
|
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
const [culture3] = DomUtils.getCulture(cultures, "zh-Hans-HK");
|
|
242
|
+
expect(culture3?.name).toBe("zh-Hans");
|
|
243
243
|
|
|
244
|
-
|
|
245
|
-
|
|
244
|
+
const [culture4] = DomUtils.getCulture(cultures, "zh-SG");
|
|
245
|
+
expect(culture4?.name).toBe("zh-Hans");
|
|
246
246
|
|
|
247
|
-
|
|
248
|
-
|
|
247
|
+
const [culture5] = DomUtils.getCulture(cultures, "en-GB");
|
|
248
|
+
expect(culture5?.name).toBe("en");
|
|
249
249
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
250
|
+
const [culture6, match6] = DomUtils.getCulture(cultures, "fr-CA");
|
|
251
|
+
expect(culture6?.name).toBe("zh-Hans");
|
|
252
|
+
expect(match6).toBe(DomUtils.CultureMatch.Default);
|
|
253
253
|
});
|
|
254
254
|
|
|
255
|
-
test(
|
|
256
|
-
|
|
255
|
+
test("Tests for getLocationKey", () => {
|
|
256
|
+
expect(DomUtils.getLocationKey("test")).toBe("http://localhost/:test");
|
|
257
257
|
});
|
|
258
258
|
|
|
259
|
-
test(
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
259
|
+
test("Tests for headersToObject", () => {
|
|
260
|
+
expect(DomUtils.headersToObject({ t1: "a", t2: "b" })).toHaveProperty(
|
|
261
|
+
"t2",
|
|
262
|
+
"b"
|
|
263
|
+
);
|
|
264
264
|
});
|
|
265
265
|
|
|
266
|
-
test(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
266
|
+
test("Tests for isFormData", () => {
|
|
267
|
+
const formData = new FormData();
|
|
268
|
+
expect(DomUtils.isFormData(formData)).toBeTruthy();
|
|
269
|
+
expect(DomUtils.isFormData({})).toBeFalsy();
|
|
270
270
|
});
|
|
271
271
|
|
|
272
|
-
test(
|
|
273
|
-
|
|
274
|
-
|
|
272
|
+
test("Tests for isJSONContentType", () => {
|
|
273
|
+
expect(DomUtils.isJSONContentType("application/problem+json")).toBeTruthy();
|
|
274
|
+
expect(DomUtils.isJSONContentType("application/javascript")).toBeTruthy();
|
|
275
275
|
});
|
|
276
276
|
|
|
277
|
-
test(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
277
|
+
test("Tests for mergeURLSearchParams", () => {
|
|
278
|
+
// Arrange
|
|
279
|
+
const params = new URLSearchParams();
|
|
280
|
+
params.set("id", "123");
|
|
281
281
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
282
|
+
const data: DataTypes.SimpleObject = {
|
|
283
|
+
name: "test",
|
|
284
|
+
favor: ["pear", "apple"]
|
|
285
|
+
};
|
|
286
286
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
287
|
+
// Assert
|
|
288
|
+
expect(DomUtils.mergeURLSearchParams(params, data).get("favor")).toBe(
|
|
289
|
+
"pear,apple"
|
|
290
|
+
);
|
|
291
291
|
});
|
|
292
292
|
|
|
293
|
-
test(
|
|
294
|
-
|
|
295
|
-
|
|
293
|
+
test("Tests for setFocus", () => {
|
|
294
|
+
// Arrange
|
|
295
|
+
const focus = jest.fn();
|
|
296
296
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
297
|
+
const root = document.body;
|
|
298
|
+
const container = document.createElement("div");
|
|
299
|
+
root.append(container);
|
|
300
|
+
const input = document.createElement("input");
|
|
301
|
+
input.name = "test";
|
|
302
|
+
input.onfocus = focus;
|
|
303
|
+
container.append(input);
|
|
304
304
|
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
DomUtils.setFocus("test");
|
|
306
|
+
expect(focus).toHaveBeenCalledTimes(1);
|
|
307
307
|
|
|
308
|
-
|
|
308
|
+
input.blur();
|
|
309
309
|
|
|
310
|
-
|
|
311
|
-
|
|
310
|
+
DomUtils.setFocus({ test: "No content" }, container);
|
|
311
|
+
expect(focus).toHaveBeenCalledTimes(2);
|
|
312
312
|
});
|
|
313
313
|
|
|
314
|
-
test(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
314
|
+
test("Tests for getInputValue", () => {
|
|
315
|
+
// Arrange
|
|
316
|
+
const input = document.createElement("input");
|
|
317
|
+
input.type = "datetime-local";
|
|
318
|
+
input.value = DateUtils.formatForInput("2023-09-21T23:08", false) ?? "";
|
|
319
|
+
|
|
320
|
+
// Act
|
|
321
|
+
const result = DomUtils.getInputValue(input);
|
|
322
|
+
|
|
323
|
+
// Assert
|
|
324
|
+
expect(result).not.toBeUndefined();
|
|
325
|
+
expect(result instanceof Date).toBeTruthy();
|
|
326
|
+
if (result instanceof Date) {
|
|
327
|
+
expect(result.getDate()).toBe(21);
|
|
328
|
+
}
|
|
329
329
|
});
|
|
330
330
|
|
|
331
|
-
test(
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
331
|
+
test("Tests for getUserAgentData 1", () => {
|
|
332
|
+
const data = DomUtils.parseUserAgent(
|
|
333
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
|
|
334
|
+
);
|
|
335
|
+
expect(data?.device).toBe("Desktop");
|
|
336
|
+
expect(data?.platform).toBe("Windows NT");
|
|
337
|
+
expect(data?.platformVersion).toBe("10.0");
|
|
338
|
+
expect(data?.brands.find((b) => b.brand === "Chrome")?.version).toBe("124");
|
|
339
339
|
});
|
|
340
340
|
|
|
341
|
-
test(
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
341
|
+
test("Tests for getUserAgentData 2", () => {
|
|
342
|
+
const data = DomUtils.parseUserAgent(
|
|
343
|
+
"Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MicroMessenger/4.5.255"
|
|
344
|
+
);
|
|
345
|
+
expect(data?.device).toBe("GT-S5660");
|
|
346
|
+
expect(data?.platform).toBe("Android");
|
|
347
|
+
expect(data?.platformVersion).toBe("2.3.6");
|
|
348
|
+
expect(data?.mobile).toBeTruthy();
|
|
349
|
+
expect(DomUtils.isWechatClient(data)).toBeTruthy();
|
|
350
350
|
});
|
|
351
351
|
|
|
352
|
-
test(
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
352
|
+
test("Tests for getUserAgentData 3", () => {
|
|
353
|
+
const data = DomUtils.parseUserAgent(
|
|
354
|
+
"Mozilla/5.0 (Linux; Android 7.1.1;MEIZU E3 Build/NGI77B; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/9.6 TBS/044428 Mobile Safari/537.36 MicroMessenger/6.6.7.1321(0x26060739) NetType/WIFI Language/zh_CN"
|
|
355
|
+
);
|
|
356
356
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
357
|
+
expect(data?.device).toBe("MEIZU E3");
|
|
358
|
+
expect(data?.platform).toBe("Android");
|
|
359
|
+
expect(data?.platformVersion).toBe("7.1.1");
|
|
360
|
+
expect(data?.mobile).toBeTruthy();
|
|
361
|
+
expect(DomUtils.isWechatClient(data)).toBeTruthy();
|
|
362
362
|
});
|
|
363
363
|
|
|
364
|
-
test(
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
364
|
+
test("Tests for getUserAgentData 4", () => {
|
|
365
|
+
const data = DomUtils.parseUserAgent(
|
|
366
|
+
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Mobile/15E148 Safari/604.1"
|
|
367
|
+
);
|
|
368
368
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
369
|
+
expect(data?.device).toBe("iPhone");
|
|
370
|
+
expect(data?.platform).toBe("iPhone OS");
|
|
371
|
+
expect(data?.platformVersion).toBe("17.5.1");
|
|
372
|
+
expect(data?.mobile).toBeTruthy();
|
|
373
|
+
expect(DomUtils.isWechatClient(data)).toBeFalsy();
|
|
374
374
|
});
|
|
375
375
|
|
|
376
|
-
test(
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
376
|
+
test("Tests for getUserAgentData 5", () => {
|
|
377
|
+
const data = DomUtils.parseUserAgent(
|
|
378
|
+
"Mozilla/5.0 (SMART-TV; Linux; Tizen 2.3) AppleWebkit/538.1 (KHTML, like Gecko) SamsungBrowser/1.0 TV Safari/538.1"
|
|
379
|
+
);
|
|
380
380
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
381
|
+
expect(data?.device).toBe("SMART-TV");
|
|
382
|
+
expect(data?.platform).toBe("Tizen");
|
|
383
|
+
expect(data?.platformVersion).toBe("2.3");
|
|
384
|
+
expect(data?.mobile).toBeFalsy();
|
|
385
385
|
});
|
|
386
386
|
|
|
387
|
-
test(
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
387
|
+
test("Tests for getUserAgentData 6", () => {
|
|
388
|
+
const data = DomUtils.parseUserAgent(
|
|
389
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15"
|
|
390
|
+
);
|
|
391
391
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
392
|
+
expect(data?.device).toBe("Macintosh");
|
|
393
|
+
expect(data?.platform).toBe("Mac OS X");
|
|
394
|
+
expect(data?.platformVersion).toBe("10.15");
|
|
395
|
+
expect(data?.mobile).toBeFalsy();
|
|
396
396
|
});
|
|
397
397
|
|
|
398
|
-
test(
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
398
|
+
test("Tests for getUserAgentData 7", () => {
|
|
399
|
+
const data = DomUtils.parseUserAgent(
|
|
400
|
+
"Mozilla/5.0 (Linux; Android 8.1; LEO-DLXXE Build/HONORLRA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.111 HuaweiBrowser/9.1.1.308 Mobile Safari/537.36"
|
|
401
|
+
);
|
|
402
402
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
403
|
+
expect(data?.device).toBe("LEO-DLXXE");
|
|
404
|
+
expect(data?.platform).toBe("Android");
|
|
405
|
+
expect(data?.platformVersion).toBe("8.1");
|
|
406
|
+
expect(data?.mobile).toBeTruthy();
|
|
407
407
|
});
|
|
408
408
|
|
|
409
|
-
test(
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
409
|
+
test("Tests for getUserAgentData 8", () => {
|
|
410
|
+
const data = DomUtils.parseUserAgent(
|
|
411
|
+
"Mozilla/5.0 (Linux; Android 9; SM-R825F Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.119 Mobile Safari/537.36"
|
|
412
|
+
);
|
|
413
413
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
414
|
+
expect(data?.device).toBe("SM-R825F");
|
|
415
|
+
expect(data?.platform).toBe("Android");
|
|
416
|
+
expect(data?.platformVersion).toBe("9");
|
|
417
|
+
expect(data?.mobile).toBeTruthy();
|
|
418
418
|
});
|
|
419
419
|
|
|
420
|
-
test(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
420
|
+
test("Tests for setupLogging", async () => {
|
|
421
|
+
// Arrange
|
|
422
|
+
const action = jest.fn((data: ErrorData) => {
|
|
423
|
+
expect(data.message).toBe("Test");
|
|
424
|
+
});
|
|
425
|
+
DomUtils.setupLogging(action, true, globalThis.self);
|
|
426
426
|
|
|
427
|
-
|
|
428
|
-
|
|
427
|
+
// Act
|
|
428
|
+
console.error("Test");
|
|
429
429
|
|
|
430
|
-
|
|
431
|
-
|
|
430
|
+
// Assert
|
|
431
|
+
expect(action).toHaveBeenCalledTimes(1);
|
|
432
432
|
});
|