Skip to content

Commit

Permalink
Merge pull request #271 from jdi-testing/issue_259
Browse files Browse the repository at this point in the history
handle request xpathes
  • Loading branch information
MariiaNebesnova authored Aug 2, 2021
2 parents d8fa525 + 4730ecc commit 797fd19
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 430 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": "",
"devtools_page": "index.html",
"version": "3.0.33",
"version": "3.0.34",
"permissions": [
"activeTab",
"tabs",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jdi-react-extension",
"version": "3.0.33",
"version": "3.0.34",
"description": "jdi react extension",
"scripts": {
"start": "npm run webpack",
Expand Down Expand Up @@ -42,6 +42,7 @@
"classnames": "^2.2.6",
"cyrillic-to-translit-js": "^3.1.0",
"jszip": "^3.6.0",
"lodash": "^4.17.21",
"mobx": "^6.1.8",
"mobx-react": "^7.1.0",
"mobx-react-devtools": "^6.1.1",
Expand Down
41 changes: 21 additions & 20 deletions src/js/blocks/autoFind/autoFindProvider/AutoFindProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable indent */
import _ from "lodash";
import React, { useState, useEffect } from "react";
import { inject, observer } from "mobx-react";
import { useContext } from "react";
Expand All @@ -7,7 +8,7 @@ import {
highlightElements,
runDocumentListeners,
generatePageObject,
requestXpathes,
requestGenerationData,
} from "./pageDataHandlers";
import { reportProblemPopup } from "./contentScripts/reportProblemPopup/reportProblemPopup";
import { JDIclasses, getJdiClassName } from "./generationClassesMap";
Expand Down Expand Up @@ -103,7 +104,7 @@ const AutoFindProvider = inject("mainModel")(

const reportProblem = (predictedElements) => {
chrome.storage.sync.set(
{ predictedElements },
{ predictedElements },
connector.attachContentScript(reportProblemPopup)
);
};
Expand Down Expand Up @@ -163,12 +164,16 @@ const AutoFindProvider = inject("mainModel")(
const onHighlighted = () => {
setStatus(autoFindStatus.success);
setAvailableForGeneration(
predictedElements.filter(
(e) =>
e.predicted_probability >= perception &&
!e.skipGeneration &&
!e.hidden &&
!unreachableNodes.includes(e.element_id)
_.unionBy(
availableForGeneration,
predictedElements.filter(
(e) =>
e.predicted_probability >= perception &&
!e.skipGeneration &&
!e.hidden &&
!unreachableNodes.includes(e.element_id)
),
'element_id'
)
);
}
Expand All @@ -195,21 +200,17 @@ const AutoFindProvider = inject("mainModel")(
);
if (!noXpath.length) return;
setXpathStatus(xpathGenerationStatus.started);
requestXpathes(noXpath, ({ xpathElements, unreachableNodes }) => {
setAvailableForGeneration(xpathElements);
requestGenerationData(noXpath, ({ generationData, unreachableNodes }) => {
setAvailableForGeneration(
_.chain(availableForGeneration)
.map((el) => _.chain(generationData).find({ element_id: el.element_id }).merge(el).value())
.differenceBy(unreachableNodes, 'element_id')
.value()
);
setUnreachableNodes(unreachableNodes);
const updated = predictedElements.map((predictedElement) => {
const xPathEl = xpathElements.find(
(x) => x.element_id === predictedElement.element_id
);
return {
...predictedElement,
...xPathEl,
};
});
setPredictedElements(updated);
setXpathStatus(xpathGenerationStatus.complete);
});

}, [availableForGeneration]);

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/js/blocks/autoFind/autoFindProvider/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export const sendMessage = {
setHighlight: (payload) => connector.sendMessage("SET_HIGHLIGHT", payload),
killHighlight: (payload, onResponse) =>
connector.sendMessage("KILL_HIGHLIGHT", null, onResponse),
generateXpathes: (payload, onResponse) =>
connector.sendMessage("GENERATE_XPATHES", payload, onResponse),
generateAttributes: (payload, onResponse) =>
connector.sendMessage("GENERATE_ATTRIBUTES", payload, onResponse),
pingScript: (payload, onResponse) =>
connector.sendMessage("PING_SCRIPT", payload, onResponse),
highlightUnreached: (payload) => connector.sendMessage("HIGHLIGHT_ERRORS", payload),
Expand Down
Loading

0 comments on commit 797fd19

Please sign in to comment.