Skip to content

Commit

Permalink
Merge pull request #1606 from jdi-testing/issue_1587_data-attr-unique…
Browse files Browse the repository at this point in the history
…-bug

Issue 1587: data attr unique bug
  • Loading branch information
Iogsotot authored Dec 18, 2023
2 parents 58a2bf9 + 8ae3d17 commit 14c8c87
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "JDN",
"description": "JDN – helps Test Automation Engineer to create Page Objects in the test automation framework and speed up test development",
"devtools_page": "index.html",
"version": "3.14.34",
"version": "3.14.35",
"icons": {
"128": "icon128.png"
},
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jdn-ai-chrome-extension",
"version": "3.14.34",
"version": "3.14.35",
"description": "jdn-ai chrome extension",
"scripts": {
"start": "webpack --watch --env devenv",
Expand Down Expand Up @@ -107,7 +107,6 @@
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"file-loader": "6.2.0",

"html-webpack-plugin": "5.5.3",
"husky": "^8.0.2",
"jest": "^29.7.0",
Expand Down
19 changes: 11 additions & 8 deletions src/features/locators/utils/createLocatorTypeOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const splitUniqueAndNonUniqueAttributes = (

Object.entries(attributes).forEach(([key, value]) => {
const keyType = key as keyof ElementAttributes;
const isValueEmpty = value === '' || value === null || value === undefined;

if (keyType === 'dataAttributes' && value) {
// Check and unpacked data-attributes:
Expand All @@ -152,10 +153,13 @@ const splitUniqueAndNonUniqueAttributes = (
const nonUniqueDataAttributes: { [key: string]: string | null } = {};

Object.entries(dataAttributes).forEach(([dataKey, dataValue]) => {
if (!attributesHashMap.has(dataKey) || !attributesHashMap.get(dataKey)?.has(dataValue)) {
uniqueDataAttributes[dataKey] = dataValue;
} else {
const isDataValueEmpty = dataValue === '' || dataValue === null || dataValue === undefined;
const isNonUnique =
isDataValueEmpty || !attributesHashMap.has(dataKey) || !attributesHashMap.get(dataKey)?.has(dataValue);
if (isNonUnique) {
nonUniqueDataAttributes[dataKey] = dataValue;
} else {
uniqueDataAttributes[dataKey] = dataValue;
}
});

Expand All @@ -167,12 +171,11 @@ const splitUniqueAndNonUniqueAttributes = (
mergeObjects(nonUniqueAttributes, nonUniqueDataAttributes);
}
} else {
const isUnique = !attributesHashMap.has(key) || !attributesHashMap.get(key)?.has(value);

if (isUnique) {
uniqueAttributes[keyType] = value;
} else {
const isNonUnique = isValueEmpty || !attributesHashMap.has(key) || !attributesHashMap.get(key)?.has(value);
if (isNonUnique) {
nonUniqueAttributes[keyType] = value;
} else {
uniqueAttributes[keyType] = value;
}
}
});
Expand Down

0 comments on commit 14c8c87

Please sign in to comment.