@etsoo/shared 1.2.54 → 1.2.56

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,432 +1,432 @@
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';
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
- 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
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
- 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
- });
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
- 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
- });
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('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');
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
- // Act
85
- const result = DomUtils.formDataToObject(form1);
84
+ // Act
85
+ const result = DomUtils.formDataToObject(form1);
86
86
 
87
- // Assert
88
- expect(Array.isArray(result['item'])).toBeTruthy();
87
+ // Assert
88
+ expect(Array.isArray(result["item"])).toBeTruthy();
89
89
  });
90
90
 
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();
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('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();
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('Tests for formDataToObject', () => {
121
- const formData = new FormData();
122
- formData.append('id', '1234');
123
- formData.append('name', 'test');
120
+ test("Tests for formDataToObject", () => {
121
+ const formData = new FormData();
122
+ formData.append("id", "1234");
123
+ formData.append("name", "test");
124
124
 
125
- expect(DomUtils.formDataToObject(formData)).toEqual({
126
- id: '1234',
127
- name: 'test'
128
- });
125
+ expect(DomUtils.formDataToObject(formData)).toEqual({
126
+ id: "1234",
127
+ name: "test"
128
+ });
129
129
  });
130
130
 
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');
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('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');
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('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);
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('Tests for detectedCulture', () => {
220
- expect(DomUtils.detectedCulture).toBe('en-US');
219
+ test("Tests for detectedCulture", () => {
220
+ expect(DomUtils.detectedCulture).toBe("en-US");
221
221
  });
222
222
 
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
- ];
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
- const [culture1, match1] = DomUtils.getCulture(cultures, 'zh-CN');
235
- expect(culture1?.name).toBe('zh-Hans');
236
- expect(match1).toBe(DomUtils.CultureMatch.Compatible);
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
- const [culture2] = DomUtils.getCulture(cultures, 'zh-Hans-CN');
239
- expect(culture2?.name).toBe('zh-Hans');
238
+ const [culture2] = DomUtils.getCulture(cultures, "zh-Hans-CN");
239
+ expect(culture2?.name).toBe("zh-Hans");
240
240
 
241
- const [culture3] = DomUtils.getCulture(cultures, 'zh-Hans-HK');
242
- expect(culture3?.name).toBe('zh-Hans');
241
+ const [culture3] = DomUtils.getCulture(cultures, "zh-Hans-HK");
242
+ expect(culture3?.name).toBe("zh-Hans");
243
243
 
244
- const [culture4] = DomUtils.getCulture(cultures, 'zh-SG');
245
- expect(culture4?.name).toBe('zh-Hans');
244
+ const [culture4] = DomUtils.getCulture(cultures, "zh-SG");
245
+ expect(culture4?.name).toBe("zh-Hans");
246
246
 
247
- const [culture5] = DomUtils.getCulture(cultures, 'en-GB');
248
- expect(culture5?.name).toBe('en');
247
+ const [culture5] = DomUtils.getCulture(cultures, "en-GB");
248
+ expect(culture5?.name).toBe("en");
249
249
 
250
- const [culture6, match6] = DomUtils.getCulture(cultures, 'fr-CA');
251
- expect(culture6?.name).toBe('zh-Hans');
252
- expect(match6).toBe(DomUtils.CultureMatch.Default);
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('Tests for getLocationKey', () => {
256
- expect(DomUtils.getLocationKey('test')).toBe('http://localhost/:test');
255
+ test("Tests for getLocationKey", () => {
256
+ expect(DomUtils.getLocationKey("test")).toBe("http://localhost:3000/:test");
257
257
  });
258
258
 
259
- test('Tests for headersToObject', () => {
260
- expect(DomUtils.headersToObject({ t1: 'a', t2: 'b' })).toHaveProperty(
261
- 't2',
262
- 'b'
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('Tests for isFormData', () => {
267
- const formData = new FormData();
268
- expect(DomUtils.isFormData(formData)).toBeTruthy();
269
- expect(DomUtils.isFormData({})).toBeFalsy();
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('Tests for isJSONContentType', () => {
273
- expect(DomUtils.isJSONContentType('application/problem+json')).toBeTruthy();
274
- expect(DomUtils.isJSONContentType('application/javascript')).toBeTruthy();
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('Tests for mergeURLSearchParams', () => {
278
- // Arrange
279
- const params = new URLSearchParams();
280
- params.set('id', '123');
277
+ test("Tests for mergeURLSearchParams", () => {
278
+ // Arrange
279
+ const params = new URLSearchParams();
280
+ params.set("id", "123");
281
281
 
282
- const data: DataTypes.SimpleObject = {
283
- name: 'test',
284
- favor: ['pear', 'apple']
285
- };
282
+ const data: DataTypes.SimpleObject = {
283
+ name: "test",
284
+ favor: ["pear", "apple"]
285
+ };
286
286
 
287
- // Assert
288
- expect(DomUtils.mergeURLSearchParams(params, data).get('favor')).toBe(
289
- 'pear,apple'
290
- );
287
+ // Assert
288
+ expect(DomUtils.mergeURLSearchParams(params, data).get("favor")).toBe(
289
+ "pear,apple"
290
+ );
291
291
  });
292
292
 
293
- test('Tests for setFocus', () => {
294
- // Arrange
295
- const focus = jest.fn();
293
+ test("Tests for setFocus", () => {
294
+ // Arrange
295
+ const focus = vi.fn();
296
296
 
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);
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
- DomUtils.setFocus('test');
306
- expect(focus).toHaveBeenCalledTimes(1);
305
+ DomUtils.setFocus("test");
306
+ expect(focus).toHaveBeenCalledTimes(1);
307
307
 
308
- input.blur();
308
+ input.blur();
309
309
 
310
- DomUtils.setFocus({ test: 'No content' }, container);
311
- expect(focus).toHaveBeenCalledTimes(2);
310
+ DomUtils.setFocus({ test: "No content" }, container);
311
+ expect(focus).toHaveBeenCalledTimes(2);
312
312
  });
313
313
 
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
- }
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('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');
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('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();
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('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
- );
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
- 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();
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('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
- );
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
- 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();
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('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
- );
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
- expect(data?.device).toBe('SMART-TV');
382
- expect(data?.platform).toBe('Tizen');
383
- expect(data?.platformVersion).toBe('2.3');
384
- expect(data?.mobile).toBeFalsy();
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('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
- );
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
- 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();
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('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
- );
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
- expect(data?.device).toBe('LEO-DLXXE');
404
- expect(data?.platform).toBe('Android');
405
- expect(data?.platformVersion).toBe('8.1');
406
- expect(data?.mobile).toBeTruthy();
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('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
- );
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
- expect(data?.device).toBe('SM-R825F');
415
- expect(data?.platform).toBe('Android');
416
- expect(data?.platformVersion).toBe('9');
417
- expect(data?.mobile).toBeTruthy();
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('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);
420
+ test("Tests for setupLogging", async () => {
421
+ // Arrange
422
+ const action = vi.fn((data: ErrorData) => {
423
+ expect(data.message).toBe("Test");
424
+ });
425
+ DomUtils.setupLogging(action, true, globalThis.self);
426
426
 
427
- // Act
428
- console.error('Test');
427
+ // Act
428
+ console.error("Test");
429
429
 
430
- // Assert
431
- expect(action).toHaveBeenCalledTimes(1);
430
+ // Assert
431
+ expect(action).toHaveBeenCalledTimes(1);
432
432
  });