@cypress/unique-selector 1.0.0 → 1.1.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/lib/{getData.js → getAttribute.js} +4 -4
- package/lib/index.js +15 -11
- package/package.json +1 -1
|
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
/**
|
|
7
|
-
* Returns the
|
|
8
|
-
* @param { String } selectorType - The
|
|
7
|
+
* Returns the {attr} selector of the element
|
|
8
|
+
* @param { String } selectorType - The attribute selector to return.
|
|
9
9
|
* @param { String } attributes - The attributes of the element.
|
|
10
|
-
* @return { String | null } - The
|
|
10
|
+
* @return { String | null } - The {attr} selector of the element.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var getAttribute = exports.getAttribute = function getAttribute(selectorType, attributes) {
|
|
14
14
|
for (var i = 0; i < attributes.length; i++) {
|
|
15
15
|
// extract node name + value
|
|
16
16
|
var _attributes$i = attributes[i],
|
package/lib/index.js
CHANGED
|
@@ -23,13 +23,14 @@ var _isUnique = require('./isUnique');
|
|
|
23
23
|
|
|
24
24
|
var _getParents = require('./getParents');
|
|
25
25
|
|
|
26
|
-
var
|
|
26
|
+
var _getAttribute = require('./getAttribute');
|
|
27
27
|
|
|
28
28
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } /**
|
|
29
29
|
* Expose `unique`
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
|
-
var dataRegex = /^data
|
|
32
|
+
var dataRegex = /^data-.+/;
|
|
33
|
+
var attrRegex = /^attribute:(.+)/m;
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Returns all the selectors of the element
|
|
@@ -49,7 +50,7 @@ function getAllSelectors(el, selectors, attributesToIgnore) {
|
|
|
49
50
|
};
|
|
50
51
|
|
|
51
52
|
return selectors.filter(function (selector) {
|
|
52
|
-
return !dataRegex.test(selector);
|
|
53
|
+
return !dataRegex.test(selector) && !attrRegex.test(selector);
|
|
53
54
|
}).reduce(function (res, next) {
|
|
54
55
|
res[next] = funcs[next](el);
|
|
55
56
|
return res;
|
|
@@ -136,20 +137,23 @@ function getUniqueSelector(element, selectorTypes, attributesToIgnore) {
|
|
|
136
137
|
var selector = elementSelectors[selectorType];
|
|
137
138
|
|
|
138
139
|
// if we are a data attribute
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
var isDataAttributeSelectorType = dataRegex.test(selectorType);
|
|
141
|
+
var isAttributeSelectorType = !isDataAttributeSelectorType && attrRegex.test(selectorType);
|
|
142
|
+
if (isDataAttributeSelectorType || isAttributeSelectorType) {
|
|
143
|
+
var attributeToQuery = isDataAttributeSelectorType ? selectorType : selectorType.replace(attrRegex, '$1');
|
|
144
|
+
var attributeSelector = (0, _getAttribute.getAttribute)(attributeToQuery, attributes);
|
|
145
|
+
|
|
146
|
+
// if we found a selector via attribute
|
|
147
|
+
if (attributeSelector) {
|
|
148
|
+
selector = attributeSelector;
|
|
149
|
+
selectorType = 'attribute';
|
|
146
150
|
}
|
|
147
151
|
}
|
|
148
152
|
|
|
149
153
|
if (!Boolean(selector)) continue;
|
|
150
154
|
|
|
151
155
|
switch (selectorType) {
|
|
152
|
-
case '
|
|
156
|
+
case 'attribute':
|
|
153
157
|
case 'id':
|
|
154
158
|
case 'name':
|
|
155
159
|
case 'tag':
|
package/package.json
CHANGED