@testid/antd-testid-runtime 1.0.7 → 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";
@@ -195,7 +197,8 @@ var POPUP_CLASS_SUFFIX_MAP = {
195
197
  ],
196
198
  popconfirm: [["-popover", "-popconfirm"]],
197
199
  dropdown: [["-dropdown"]],
198
- tooltip: [["-tooltip"]]
200
+ tooltip: [["-tooltip"]],
201
+ message: [["-message"]]
199
202
  };
200
203
  function buildPopupClassMap(prefixes) {
201
204
  const result = {};
@@ -334,9 +337,9 @@ var TestIdObserver = class {
334
337
  this.handlePopupNode(node, popupType);
335
338
  return;
336
339
  }
337
- const popupAncestorType = this.detectPopupAncestor(node);
338
- if (popupAncestorType) {
339
- this.handlePopupChildNode(node, popupAncestorType, config);
340
+ const popupAncestor = this.detectPopupAncestor(node);
341
+ if (popupAncestor) {
342
+ this.handlePopupChildNode(node, popupAncestor.type, popupAncestor.element, config);
340
343
  return;
341
344
  }
342
345
  if (this.isInsideApp(node)) {
@@ -431,7 +434,7 @@ var TestIdObserver = class {
431
434
  * 因为 Ant Design Vue 4 可能在浮层根节点外包一层 wrapper DIV)。
432
435
  * 找到浮层根节点后,继续向上验证其祖先链能到达 body (确保不在 #app 内)。
433
436
  *
434
- * @returns 浮层类型或 null (不在任何浮层内)
437
+ * @returns 浮层类型 + 祖先元素,或 null (不在任何浮层内)
435
438
  */
436
439
  detectPopupAncestor(node) {
437
440
  let current = node.parentElement;
@@ -439,7 +442,7 @@ var TestIdObserver = class {
439
442
  const type = this.matchPopupClass(current);
440
443
  if (type) {
441
444
  const reachesBody = this.reachesBody(current);
442
- if (reachesBody) return type;
445
+ if (reachesBody) return { type, element: current };
443
446
  }
444
447
  if (current === document.body || current.id === "app") break;
445
448
  current = current.parentElement;
@@ -498,15 +501,19 @@ var TestIdObserver = class {
498
501
  /**
499
502
  * 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
500
503
  *
504
+ * 每个浮层实例独立计数: 以浮层根节点 data-testid 作为隔离 key,
505
+ * 重复打开相同类型的浮层,子元素 ID 均从 0 重新开始。
506
+ *
501
507
  * ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
502
508
  * 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
503
509
  *
504
510
  * 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
505
511
  */
506
- handlePopupChildNode(node, popupType, config) {
512
+ handlePopupChildNode(node, popupType, popupElement, config) {
507
513
  if (config.onlyInteractive && !this.isInteractive(node)) return;
508
514
  const tag = this.getSimpleTag(node);
509
- const key = `${popupType}_${tag}`;
515
+ const popupRootTestId = popupElement.getAttribute("data-testid") || `${popupType}_unknown`;
516
+ const key = `${popupRootTestId}_${tag}`;
510
517
  const current = this.state.popupChildCounter.get(key) ?? 0;
511
518
  this.state.popupChildCounter.set(key, current + 1);
512
519
  const popupPrefix = config.popupPrefixMap[popupType] || `${popupType}_`;
@@ -590,7 +597,8 @@ var GROUP_LABELS = {
590
597
  datePicker: "[DatePicker \u6D6E\u5C42]",
591
598
  popconfirm: "[Popconfirm \u6D6E\u5C42]",
592
599
  dropdown: "[Dropdown \u6D6E\u5C42]",
593
- tooltip: "[Tooltip \u6D6E\u5C42]"
600
+ tooltip: "[Tooltip \u6D6E\u5C42]",
601
+ message: "[Message \u6D6E\u5C42]"
594
602
  };
595
603
  var GROUP_SUGGESTIONS = {
596
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",
@@ -602,7 +610,8 @@ var GROUP_SUGGESTIONS = {
602
610
  datePicker: "DatePicker \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
603
611
  popconfirm: "Popconfirm \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
604
612
  dropdown: "Dropdown \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
605
- 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"
606
615
  };
607
616
  var TestIdChecker = class {
608
617
  /**
@@ -699,7 +708,8 @@ var TestIdChecker = class {
699
708
  "datePicker",
700
709
  "popconfirm",
701
710
  "dropdown",
702
- "tooltip"
711
+ "tooltip",
712
+ "message"
703
713
  ];
704
714
  for (const type of popupTypes) {
705
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";
@@ -153,7 +155,8 @@ var POPUP_CLASS_SUFFIX_MAP = {
153
155
  ],
154
156
  popconfirm: [["-popover", "-popconfirm"]],
155
157
  dropdown: [["-dropdown"]],
156
- tooltip: [["-tooltip"]]
158
+ tooltip: [["-tooltip"]],
159
+ message: [["-message"]]
157
160
  };
158
161
  function buildPopupClassMap(prefixes) {
159
162
  const result = {};
@@ -292,9 +295,9 @@ var TestIdObserver = class {
292
295
  this.handlePopupNode(node, popupType);
293
296
  return;
294
297
  }
295
- const popupAncestorType = this.detectPopupAncestor(node);
296
- if (popupAncestorType) {
297
- this.handlePopupChildNode(node, popupAncestorType, config);
298
+ const popupAncestor = this.detectPopupAncestor(node);
299
+ if (popupAncestor) {
300
+ this.handlePopupChildNode(node, popupAncestor.type, popupAncestor.element, config);
298
301
  return;
299
302
  }
300
303
  if (this.isInsideApp(node)) {
@@ -389,7 +392,7 @@ var TestIdObserver = class {
389
392
  * 因为 Ant Design Vue 4 可能在浮层根节点外包一层 wrapper DIV)。
390
393
  * 找到浮层根节点后,继续向上验证其祖先链能到达 body (确保不在 #app 内)。
391
394
  *
392
- * @returns 浮层类型或 null (不在任何浮层内)
395
+ * @returns 浮层类型 + 祖先元素,或 null (不在任何浮层内)
393
396
  */
394
397
  detectPopupAncestor(node) {
395
398
  let current = node.parentElement;
@@ -397,7 +400,7 @@ var TestIdObserver = class {
397
400
  const type = this.matchPopupClass(current);
398
401
  if (type) {
399
402
  const reachesBody = this.reachesBody(current);
400
- if (reachesBody) return type;
403
+ if (reachesBody) return { type, element: current };
401
404
  }
402
405
  if (current === document.body || current.id === "app") break;
403
406
  current = current.parentElement;
@@ -456,15 +459,19 @@ var TestIdObserver = class {
456
459
  /**
457
460
  * 处理浮层内部子节点 (Modal/Drawer/Dropdown 内的按钮、输入框等)
458
461
  *
462
+ * 每个浮层实例独立计数: 以浮层根节点 data-testid 作为隔离 key,
463
+ * 重复打开相同类型的浮层,子元素 ID 均从 0 重新开始。
464
+ *
459
465
  * ID 格式: ${runtimePagePrefix}${popupPrefix}${tag}_${counter}
460
466
  * 例: hall_dynamic_modal_button_0, hall_dynamic_select_div_2
461
467
  *
462
468
  * 浮层子元素均为运行时注入,统一使用 runtimePagePrefix 前缀。
463
469
  */
464
- handlePopupChildNode(node, popupType, config) {
470
+ handlePopupChildNode(node, popupType, popupElement, config) {
465
471
  if (config.onlyInteractive && !this.isInteractive(node)) return;
466
472
  const tag = this.getSimpleTag(node);
467
- const key = `${popupType}_${tag}`;
473
+ const popupRootTestId = popupElement.getAttribute("data-testid") || `${popupType}_unknown`;
474
+ const key = `${popupRootTestId}_${tag}`;
468
475
  const current = this.state.popupChildCounter.get(key) ?? 0;
469
476
  this.state.popupChildCounter.set(key, current + 1);
470
477
  const popupPrefix = config.popupPrefixMap[popupType] || `${popupType}_`;
@@ -548,7 +555,8 @@ var GROUP_LABELS = {
548
555
  datePicker: "[DatePicker \u6D6E\u5C42]",
549
556
  popconfirm: "[Popconfirm \u6D6E\u5C42]",
550
557
  dropdown: "[Dropdown \u6D6E\u5C42]",
551
- tooltip: "[Tooltip \u6D6E\u5C42]"
558
+ tooltip: "[Tooltip \u6D6E\u5C42]",
559
+ message: "[Message \u6D6E\u5C42]"
552
560
  };
553
561
  var GROUP_SUGGESTIONS = {
554
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",
@@ -560,7 +568,8 @@ var GROUP_SUGGESTIONS = {
560
568
  datePicker: "DatePicker \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
561
569
  popconfirm: "Popconfirm \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
562
570
  dropdown: "Dropdown \u72EC\u7ACB\u8BA1\u6570\u5668\u81EA\u589E\u903B\u8F91\u5931\u6548",
563
- 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"
564
573
  };
565
574
  var TestIdChecker = class {
566
575
  /**
@@ -657,7 +666,8 @@ var TestIdChecker = class {
657
666
  "datePicker",
658
667
  "popconfirm",
659
668
  "dropdown",
660
- "tooltip"
669
+ "tooltip",
670
+ "message"
661
671
  ];
662
672
  for (const type of popupTypes) {
663
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.7",
3
+ "version": "1.0.8",
4
4
  "description": "运行时兜底打标模块 — MutationObserver + 锚点计数器 + 浮层计数器 + ID 重复检测",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",