@testid/antd-testid-runtime 1.0.6 → 1.0.8

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/dist/index.d.mts CHANGED
@@ -10,7 +10,7 @@
10
10
  /**
11
11
  * 支持的浮层类型
12
12
  */
13
- type PopupType = 'modal' | 'drawer' | 'select' | 'datePicker' | 'popconfirm' | 'dropdown' | 'tooltip';
13
+ type PopupType = 'modal' | 'drawer' | 'select' | 'datePicker' | 'popconfirm' | 'dropdown' | 'tooltip' | 'message';
14
14
  /**
15
15
  * 全量配置接口
16
16
  */
@@ -291,7 +291,7 @@ declare class TestIdObserver {
291
291
  * 因为 Ant Design Vue 4 可能在浮层根节点外包一层 wrapper DIV)。
292
292
  * 找到浮层根节点后,继续向上验证其祖先链能到达 body (确保不在 #app 内)。
293
293
  *
294
- * @returns 浮层类型或 null (不在任何浮层内)
294
+ * @returns 浮层类型 + 祖先元素,或 null (不在任何浮层内)
295
295
  */
296
296
  private detectPopupAncestor;
297
297
  /**
@@ -314,6 +314,9 @@ declare class TestIdObserver {
314
314
  /**
315
315
  * 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
316
316
  *
317
+ * 每个浮层实例独立计数: 以浮层根节点 data-testid 作为隔离 key,
318
+ * 重复打开相同类型的浮层,子元素 ID 均从 0 重新开始。
319
+ *
317
320
  * ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
318
321
  * 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
319
322
  *
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  /**
11
11
  * 支持的浮层类型
12
12
  */
13
- type PopupType = 'modal' | 'drawer' | 'select' | 'datePicker' | 'popconfirm' | 'dropdown' | 'tooltip';
13
+ type PopupType = 'modal' | 'drawer' | 'select' | 'datePicker' | 'popconfirm' | 'dropdown' | 'tooltip' | 'message';
14
14
  /**
15
15
  * 全量配置接口
16
16
  */
@@ -291,7 +291,7 @@ declare class TestIdObserver {
291
291
  * 因为 Ant Design Vue 4 可能在浮层根节点外包一层 wrapper DIV)。
292
292
  * 找到浮层根节点后,继续向上验证其祖先链能到达 body (确保不在 #app 内)。
293
293
  *
294
- * @returns 浮层类型或 null (不在任何浮层内)
294
+ * @returns 浮层类型 + 祖先元素,或 null (不在任何浮层内)
295
295
  */
296
296
  private detectPopupAncestor;
297
297
  /**
@@ -314,6 +314,9 @@ declare class TestIdObserver {
314
314
  /**
315
315
  * 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
316
316
  *
317
+ * 每个浮层实例独立计数: 以浮层根节点 data-testid 作为隔离 key,
318
+ * 重复打开相同类型的浮层,子元素 ID 均从 0 重新开始。
319
+ *
317
320
  * ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
318
321
  * 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
319
322
  *
package/dist/index.js CHANGED
@@ -68,7 +68,8 @@ var defaultConfig = {
68
68
  datePicker: "datePicker_",
69
69
  popconfirm: "popconfirm_",
70
70
  dropdown: "dropdown_",
71
- tooltip: "tooltip_"
71
+ tooltip: "tooltip_",
72
+ message: "message_"
72
73
  },
73
74
  ignoreTags: ["script", "style", "svg", "br", "iframe"],
74
75
  ignoreClass: ["no-test-mark", "hidden"],
@@ -155,7 +156,8 @@ var popupCounters = {
155
156
  datePicker: 0,
156
157
  popconfirm: 0,
157
158
  dropdown: 0,
158
- tooltip: 0
159
+ tooltip: 0,
160
+ message: 0
159
161
  };
160
162
  function getNextPopupId(type) {
161
163
  const key = type in popupCounters ? type : "modal";
@@ -184,26 +186,31 @@ function buildPopupTestId(type, tag, counterId) {
184
186
 
185
187
  // src/utils/testIdObserver.ts
186
188
  var POPUP_CLASS_SUFFIX_MAP = {
187
- modal: ["-modal"],
188
- drawer: ["-drawer"],
189
- select: ["-select-dropdown"],
189
+ modal: [["-modal"]],
190
+ drawer: [["-drawer"]],
191
+ select: [["-select-dropdown"]],
190
192
  datePicker: [
191
- "-picker-dropdown",
193
+ ["-picker-dropdown"],
192
194
  // Ant Design Vue 4.x (新)
193
- "-calendar-picker-container"
195
+ ["-calendar-picker-container"]
194
196
  // Ant Design Vue 1.x (旧)
195
197
  ],
196
- popconfirm: ["-popover", "-popconfirm"],
197
- dropdown: ["-dropdown"],
198
- tooltip: ["-tooltip"]
198
+ popconfirm: [["-popover", "-popconfirm"]],
199
+ dropdown: [["-dropdown"]],
200
+ tooltip: [["-tooltip"]],
201
+ message: [["-message"]]
199
202
  };
200
203
  function buildPopupClassMap(prefixes) {
201
204
  const result = {};
202
205
  const entries = Object.entries(POPUP_CLASS_SUFFIX_MAP);
203
- for (const [type, suffixClasses] of entries) {
204
- result[type] = prefixes.map(
205
- (prefix) => suffixClasses.map((suffix) => `${prefix}${suffix}`)
206
- );
206
+ for (const [type, suffixGroups] of entries) {
207
+ const selectorSets = [];
208
+ for (const suffixGroup of suffixGroups) {
209
+ for (const prefix of prefixes) {
210
+ selectorSets.push(suffixGroup.map((suffix) => `${prefix}${suffix}`));
211
+ }
212
+ }
213
+ result[type] = selectorSets;
207
214
  }
208
215
  return result;
209
216
  }
@@ -330,9 +337,9 @@ var TestIdObserver = class {
330
337
  this.handlePopupNode(node, popupType);
331
338
  return;
332
339
  }
333
- const popupAncestorType = this.detectPopupAncestor(node);
334
- if (popupAncestorType) {
335
- this.handlePopupChildNode(node, popupAncestorType, config);
340
+ const popupAncestor = this.detectPopupAncestor(node);
341
+ if (popupAncestor) {
342
+ this.handlePopupChildNode(node, popupAncestor.type, popupAncestor.element, config);
336
343
  return;
337
344
  }
338
345
  if (this.isInsideApp(node)) {
@@ -427,7 +434,7 @@ var TestIdObserver = class {
427
434
  * 因为 Ant Design Vue 4 可能在浮层根节点外包一层 wrapper DIV)。
428
435
  * 找到浮层根节点后,继续向上验证其祖先链能到达 body (确保不在 #app 内)。
429
436
  *
430
- * @returns 浮层类型或 null (不在任何浮层内)
437
+ * @returns 浮层类型 + 祖先元素,或 null (不在任何浮层内)
431
438
  */
432
439
  detectPopupAncestor(node) {
433
440
  let current = node.parentElement;
@@ -435,7 +442,7 @@ var TestIdObserver = class {
435
442
  const type = this.matchPopupClass(current);
436
443
  if (type) {
437
444
  const reachesBody = this.reachesBody(current);
438
- if (reachesBody) return type;
445
+ if (reachesBody) return { type, element: current };
439
446
  }
440
447
  if (current === document.body || current.id === "app") break;
441
448
  current = current.parentElement;
@@ -494,15 +501,19 @@ var TestIdObserver = class {
494
501
  /**
495
502
  * 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
496
503
  *
504
+ * 每个浮层实例独立计数: 以浮层根节点 data-testid 作为隔离 key,
505
+ * 重复打开相同类型的浮层,子元素 ID 均从 0 重新开始。
506
+ *
497
507
  * ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
498
508
  * 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
499
509
  *
500
510
  * 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
501
511
  */
502
- handlePopupChildNode(node, popupType, config) {
512
+ handlePopupChildNode(node, popupType, popupElement, config) {
503
513
  if (config.onlyInteractive && !this.isInteractive(node)) return;
504
514
  const tag = this.getSimpleTag(node);
505
- const key = `${popupType}_${tag}`;
515
+ const popupRootTestId = popupElement.getAttribute("data-testid") || `${popupType}_unknown`;
516
+ const key = `${popupRootTestId}_${tag}`;
506
517
  const current = this.state.popupChildCounter.get(key) ?? 0;
507
518
  this.state.popupChildCounter.set(key, current + 1);
508
519
  const popupPrefix = config.popupPrefixMap[popupType] || `${popupType}_`;
@@ -586,7 +597,8 @@ var GROUP_LABELS = {
586
597
  datePicker: "[DatePicker \u6D6E\u5C42]",
587
598
  popconfirm: "[Popconfirm \u6D6E\u5C42]",
588
599
  dropdown: "[Dropdown \u6D6E\u5C42]",
589
- tooltip: "[Tooltip \u6D6E\u5C42]"
600
+ tooltip: "[Tooltip \u6D6E\u5C42]",
601
+ message: "[Message \u6D6E\u5C42]"
590
602
  };
591
603
  var GROUP_SUGGESTIONS = {
592
604
  custom: "\u4E1A\u52A1\u4EE3\u7801\u4E2D\u5B58\u5728\u624B\u5199\u56FA\u5B9A\u91CD\u590D data-testid\uFF0C\u8BF7\u68C0\u67E5\u76F8\u5173\u6A21\u677F\u4EE3\u7801",
@@ -598,7 +610,8 @@ var GROUP_SUGGESTIONS = {
598
610
  datePicker: "DatePicker \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
599
611
  popconfirm: "Popconfirm \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
600
612
  dropdown: "Dropdown \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
601
- tooltip: "Tooltip \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548"
613
+ tooltip: "Tooltip \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
614
+ message: "Message \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548"
602
615
  };
603
616
  var TestIdChecker = class {
604
617
  /**
@@ -695,7 +708,8 @@ var TestIdChecker = class {
695
708
  "datePicker",
696
709
  "popconfirm",
697
710
  "dropdown",
698
- "tooltip"
711
+ "tooltip",
712
+ "message"
699
713
  ];
700
714
  for (const type of popupTypes) {
701
715
  if (prefix === `${type}_`) return type;
package/dist/index.mjs CHANGED
@@ -26,7 +26,8 @@ var defaultConfig = {
26
26
  datePicker: "datePicker_",
27
27
  popconfirm: "popconfirm_",
28
28
  dropdown: "dropdown_",
29
- tooltip: "tooltip_"
29
+ tooltip: "tooltip_",
30
+ message: "message_"
30
31
  },
31
32
  ignoreTags: ["script", "style", "svg", "br", "iframe"],
32
33
  ignoreClass: ["no-test-mark", "hidden"],
@@ -113,7 +114,8 @@ var popupCounters = {
113
114
  datePicker: 0,
114
115
  popconfirm: 0,
115
116
  dropdown: 0,
116
- tooltip: 0
117
+ tooltip: 0,
118
+ message: 0
117
119
  };
118
120
  function getNextPopupId(type) {
119
121
  const key = type in popupCounters ? type : "modal";
@@ -142,26 +144,31 @@ function buildPopupTestId(type, tag, counterId) {
142
144
 
143
145
  // src/utils/testIdObserver.ts
144
146
  var POPUP_CLASS_SUFFIX_MAP = {
145
- modal: ["-modal"],
146
- drawer: ["-drawer"],
147
- select: ["-select-dropdown"],
147
+ modal: [["-modal"]],
148
+ drawer: [["-drawer"]],
149
+ select: [["-select-dropdown"]],
148
150
  datePicker: [
149
- "-picker-dropdown",
151
+ ["-picker-dropdown"],
150
152
  // Ant Design Vue 4.x (新)
151
- "-calendar-picker-container"
153
+ ["-calendar-picker-container"]
152
154
  // Ant Design Vue 1.x (旧)
153
155
  ],
154
- popconfirm: ["-popover", "-popconfirm"],
155
- dropdown: ["-dropdown"],
156
- tooltip: ["-tooltip"]
156
+ popconfirm: [["-popover", "-popconfirm"]],
157
+ dropdown: [["-dropdown"]],
158
+ tooltip: [["-tooltip"]],
159
+ message: [["-message"]]
157
160
  };
158
161
  function buildPopupClassMap(prefixes) {
159
162
  const result = {};
160
163
  const entries = Object.entries(POPUP_CLASS_SUFFIX_MAP);
161
- for (const [type, suffixClasses] of entries) {
162
- result[type] = prefixes.map(
163
- (prefix) => suffixClasses.map((suffix) => `${prefix}${suffix}`)
164
- );
164
+ for (const [type, suffixGroups] of entries) {
165
+ const selectorSets = [];
166
+ for (const suffixGroup of suffixGroups) {
167
+ for (const prefix of prefixes) {
168
+ selectorSets.push(suffixGroup.map((suffix) => `${prefix}${suffix}`));
169
+ }
170
+ }
171
+ result[type] = selectorSets;
165
172
  }
166
173
  return result;
167
174
  }
@@ -288,9 +295,9 @@ var TestIdObserver = class {
288
295
  this.handlePopupNode(node, popupType);
289
296
  return;
290
297
  }
291
- const popupAncestorType = this.detectPopupAncestor(node);
292
- if (popupAncestorType) {
293
- this.handlePopupChildNode(node, popupAncestorType, config);
298
+ const popupAncestor = this.detectPopupAncestor(node);
299
+ if (popupAncestor) {
300
+ this.handlePopupChildNode(node, popupAncestor.type, popupAncestor.element, config);
294
301
  return;
295
302
  }
296
303
  if (this.isInsideApp(node)) {
@@ -385,7 +392,7 @@ var TestIdObserver = class {
385
392
  * 因为 Ant Design Vue 4 可能在浮层根节点外包一层 wrapper DIV)。
386
393
  * 找到浮层根节点后,继续向上验证其祖先链能到达 body (确保不在 #app 内)。
387
394
  *
388
- * @returns 浮层类型或 null (不在任何浮层内)
395
+ * @returns 浮层类型 + 祖先元素,或 null (不在任何浮层内)
389
396
  */
390
397
  detectPopupAncestor(node) {
391
398
  let current = node.parentElement;
@@ -393,7 +400,7 @@ var TestIdObserver = class {
393
400
  const type = this.matchPopupClass(current);
394
401
  if (type) {
395
402
  const reachesBody = this.reachesBody(current);
396
- if (reachesBody) return type;
403
+ if (reachesBody) return { type, element: current };
397
404
  }
398
405
  if (current === document.body || current.id === "app") break;
399
406
  current = current.parentElement;
@@ -452,15 +459,19 @@ var TestIdObserver = class {
452
459
  /**
453
460
  * 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
454
461
  *
462
+ * 每个浮层实例独立计数: 以浮层根节点 data-testid 作为隔离 key,
463
+ * 重复打开相同类型的浮层,子元素 ID 均从 0 重新开始。
464
+ *
455
465
  * ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
456
466
  * 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
457
467
  *
458
468
  * 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
459
469
  */
460
- handlePopupChildNode(node, popupType, config) {
470
+ handlePopupChildNode(node, popupType, popupElement, config) {
461
471
  if (config.onlyInteractive && !this.isInteractive(node)) return;
462
472
  const tag = this.getSimpleTag(node);
463
- const key = `${popupType}_${tag}`;
473
+ const popupRootTestId = popupElement.getAttribute("data-testid") || `${popupType}_unknown`;
474
+ const key = `${popupRootTestId}_${tag}`;
464
475
  const current = this.state.popupChildCounter.get(key) ?? 0;
465
476
  this.state.popupChildCounter.set(key, current + 1);
466
477
  const popupPrefix = config.popupPrefixMap[popupType] || `${popupType}_`;
@@ -544,7 +555,8 @@ var GROUP_LABELS = {
544
555
  datePicker: "[DatePicker \u6D6E\u5C42]",
545
556
  popconfirm: "[Popconfirm \u6D6E\u5C42]",
546
557
  dropdown: "[Dropdown \u6D6E\u5C42]",
547
- tooltip: "[Tooltip \u6D6E\u5C42]"
558
+ tooltip: "[Tooltip \u6D6E\u5C42]",
559
+ message: "[Message \u6D6E\u5C42]"
548
560
  };
549
561
  var GROUP_SUGGESTIONS = {
550
562
  custom: "\u4E1A\u52A1\u4EE3\u7801\u4E2D\u5B58\u5728\u624B\u5199\u56FA\u5B9A\u91CD\u590D data-testid\uFF0C\u8BF7\u68C0\u67E5\u76F8\u5173\u6A21\u677F\u4EE3\u7801",
@@ -556,7 +568,8 @@ var GROUP_SUGGESTIONS = {
556
568
  datePicker: "DatePicker \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
557
569
  popconfirm: "Popconfirm \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
558
570
  dropdown: "Dropdown \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
559
- tooltip: "Tooltip \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548"
571
+ tooltip: "Tooltip \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
572
+ message: "Message \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548"
560
573
  };
561
574
  var TestIdChecker = class {
562
575
  /**
@@ -653,7 +666,8 @@ var TestIdChecker = class {
653
666
  "datePicker",
654
667
  "popconfirm",
655
668
  "dropdown",
656
- "tooltip"
669
+ "tooltip",
670
+ "message"
657
671
  ];
658
672
  for (const type of popupTypes) {
659
673
  if (prefix === `${type}_`) return type;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testid/antd-testid-runtime",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "运行时兜底打标模块 — MutationObserver + 锚点计数器 + 浮层计数器 + ID 重复检测",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -20,7 +20,6 @@
20
20
  "url": "https://github.com/testid/testid-plugins.git",
21
21
  "directory": "packages/antd-testid-runtime"
22
22
  },
23
-
24
23
  "scripts": {
25
24
  "build": "tsup src/index.ts --dts --format esm,cjs --clean",
26
25
  "dev": "tsup src/index.ts --dts --format esm,cjs --watch"
@@ -30,4 +29,4 @@
30
29
  "tsup": "^8.0.0",
31
30
  "typescript": "^5.3.0"
32
31
  }
33
- }
32
+ }