Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1373, 1428, 1443: fixes with Locator clicks + fix on update xpath handler #1444

Merged
merged 10 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.13.547",
"version": "3.13.548",
"icons": {
"128": "icon128.png"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jdn-ai-chrome-extension",
"version": "3.13.547",
"version": "3.13.548",
"description": "jdn-ai chrome extension",
"scripts": {
"start": "webpack --watch --env devenv",
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/throttler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Middleware } from "@reduxjs/toolkit";
import { areInProgress } from "../../features/locators/selectors/locatorsFiltered.selectors";
import { selectAreInProgress } from "../../features/locators/selectors/locatorsByPO.selectors";

class Throttler {
accumulatedArgs: any[] = [];
Expand Down Expand Up @@ -47,7 +47,7 @@ export const quitThrottlerMiddleware: Middleware = (store) => (next) => (action)
switch (action.type) {
case "locators/updateLocatorGroup":
case "locators/failGeneration":
if (!areInProgress(store.getState())) {
if (!selectAreInProgress(store.getState())) {
throttler.quitThrottler();
}
break;
Expand Down
17 changes: 5 additions & 12 deletions src/features/locators/Locator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ export const Locator: React.FC<Props> = ({ element, currentPage, searchState, de
}
}, [scriptMessage]);

const handleOnChange: React.MouseEventHandler<HTMLDivElement> = (evt) => {
evt.stopPropagation();
const handleOnChange: React.MouseEventHandler<HTMLDivElement> = () => {
dispatch(toggleElementGeneration(element_id));
if (allChildrenChecked && size(element.children)) {
dispatch(setChildrenGeneration({ locator: element, generate: false }));
Expand All @@ -115,7 +114,9 @@ export const Locator: React.FC<Props> = ({ element, currentPage, searchState, de
if (keyForMultiSelect) {
if (active) dispatch(elementUnsetActive(element_id));
else dispatch(elementSetActive(element));
} else dispatch(setActiveSingle(element));
} else {
if (!active) dispatch(setActiveSingle(element));
}
};

const handleLocatorRightClick: React.MouseEventHandler<HTMLDivElement> = (evt) => {
Expand All @@ -128,15 +129,7 @@ export const Locator: React.FC<Props> = ({ element, currentPage, searchState, de

const renderColorizedString = () => {
const handleClick: React.MouseEventHandler<HTMLDivElement> = (event) => {
event.stopPropagation();
if (event.detail === 2) {
setIsEditModalOpen(true);
clearTimeout(timer);
} else {
timer = setTimeout(() => {
handleLocatorClick(event);
}, 200);
}
if (event.detail === 2) setIsEditModalOpen(true);
};

return (
Expand Down
42 changes: 22 additions & 20 deletions src/features/locators/reducers/shouldRunGeneration.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
import { Middleware } from "@reduxjs/toolkit";
import { ElementId, Locator } from "../types/locator.types";
import { Locator } from "../types/locator.types";
import { runLocatorsGeneration } from "./runLocatorsGeneration.thunk";
import { getNoLocatorsElements, hasAllLocators } from "../utils/utils";
import { selectLocatorById } from "../selectors/locators.selectors";

const onSetActiveGroup = (dispatch: any, locators: Locator[]) => {
const noLocators = getNoLocatorsElements(locators);
if (noLocators.length) {
dispatch(
// @ts-ignore
runLocatorsGeneration({
locators: noLocators,
generateMissingLocator: true,
})
);
}
};

export const shouldRunGeneration: Middleware = (store) => (next) => (action) => {
const { type, payload } = action;
const state = store.getState();

switch (type) {
case "locators/setElementGroupGeneration": {
const { locators, generate } = payload;
if (generate) onSetActiveGroup(store.dispatch, locators);
break;
}
case "locators/elementGroupSetActive": {
const noLocators = getNoLocatorsElements(payload.locators);
if (noLocators.length) {
store.dispatch(
// @ts-ignore
runLocatorsGeneration({
locators: noLocators,
generateMissingLocator: true,
})
);
}
onSetActiveGroup(store.dispatch, payload.locators as Locator[]);
break;
}
case "locators/toggleElementGeneration":
case "locators/setActiveSingle":
case "locators/elementSetActive": {
const _locator =
typeof payload === "string" ? selectLocatorById(state, payload as ElementId) : (payload as Locator);
if (!_locator) break;

const noLocators = !hasAllLocators(_locator);
const noLocators = !hasAllLocators(payload);
if (noLocators) {
store.dispatch(
// @ts-ignore
runLocatorsGeneration({
locators: [_locator as Locator],
locators: [payload as Locator],
generateMissingLocator: true,
})
);
Expand Down
11 changes: 11 additions & 0 deletions src/features/locators/selectors/locatorsByPO.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { sortLocatorsWithChildren } from "../utils/sortLocators";
import { selectLocatorById, selectLocators } from "./locators.selectors";
import { isValidLocator } from "../utils/utils";
import { LocatorType } from "../../../common/types/common";
import { filterInProgress } from "../utils/helpers";
import { selectCurrentPage } from "../../../app/main.selectors";
import { isLocatorListPage } from "../../../app/utils/heplers";

export const getLocatorsIdsByPO = (state: RootState, pageObjId?: PageObjectId) => {
pageObjId = isNil(pageObjId) ? selectCurrentPageObject(state)?.id : pageObjId;
Expand Down Expand Up @@ -68,3 +71,11 @@ export const selectValidLocators = createSelector(selectPresentLocatorsByPO, (lo
export const selectPresentActiveLocators = createSelector(selectPresentLocatorsByPO, (locators) =>
locators.filter((loc) => loc.active)
);

export const selectPresentLocatorsInProgress = createSelector(selectPresentLocatorsByPO, filterInProgress);

export const selectAreInProgress = createSelector(
selectPresentLocatorsInProgress,
selectCurrentPage,
(locators, page) => isLocatorListPage(page.page) && locators.length > 0
);
16 changes: 2 additions & 14 deletions src/features/locators/selectors/locatorsFiltered.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import { LocatorCalculationPriority, LocatorTaskStatus } from "../types/locator.
import { selectClassFilterByPO } from "../../filter/filter.selectors";
import { Locator } from "../types/locator.types";
import { filterLocatorsByClassFilter } from "../utils/filterLocators";
import { isProgressStatus } from "../utils/locatorGenerationController";
import { selectLocatorsByPageObject, selectSortedLocators } from "./locatorsByPO.selectors";
import { selectCurrentPage } from "../../../app/main.selectors";
import { isLocatorListPage } from "../../../app/utils/heplers";
import { filterInProgress, isProgressStatus } from "../utils/helpers";

export const selectFilteredLocators = createSelector(
selectLocatorsByPageObject,
Expand Down Expand Up @@ -102,11 +100,7 @@ export const selectActualActiveByPageObject = createSelector(
(locators) => locators
);

export const selectInProgressByPageObj = createSelector(selectFilteredLocators, (elements) =>
chain(elements)
.filter((el) => isProgressStatus(el.locator.taskStatus) && !el.deleted)
.value()
);
export const selectInProgressByPageObj = createSelector(selectFilteredLocators, filterInProgress);

export const selectInProgressActiveByPageObject = createSelector(selectInProgressByPageObj, (items) =>
items.filter((item) => item.active)
Expand Down Expand Up @@ -150,9 +144,3 @@ export const selectActiveLocators = createSelector(selectFilteredLocators, (loca
export const selectCheckedLocators = createSelector(selectFilteredLocators, (locators) =>
locators.filter((_loc) => _loc.generate)
);

export const areInProgress = createSelector(
selectInProgressByPageObj,
selectCurrentPage,
(locators, page) => isLocatorListPage(page.page) && locators.length > 0
);
8 changes: 7 additions & 1 deletion src/features/locators/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { IdentificationStatus } from "../types/locator.types";
import { IdentificationStatus, Locator, LocatorTaskStatus } from "../types/locator.types";
import { AUTO_GENERATION_TRESHOLD } from "./constants";

export const isIdentificationLoading = (status: IdentificationStatus) => status === IdentificationStatus.loading;

export const isAutoStartGeneration = (items: any[]) => items.length <= AUTO_GENERATION_TRESHOLD;

export const isProgressStatus = (taskStatus?: LocatorTaskStatus) =>
LocatorTaskStatus.PENDING === taskStatus || taskStatus === LocatorTaskStatus.STARTED;

export const filterInProgress = (elements: Locator[]) =>
elements.filter((el) => isProgressStatus(el.locator.taskStatus) && !el.deleted);
2 changes: 0 additions & 2 deletions src/features/locators/utils/locatorGenerationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { getDocument } from "../../../common/utils/getDocument";
import { MainState, MaxGenerationTime } from "../../../app/types/mainSlice.types";
import { PageObject } from "../../pageObjects/types/pageObjectSlice.types";

export const isProgressStatus = (taskStatus?: LocatorTaskStatus) =>
LocatorTaskStatus.PENDING === taskStatus || taskStatus === LocatorTaskStatus.STARTED;
export const isGeneratedStatus = (taskStatus: LocatorTaskStatus) => taskStatus === LocatorTaskStatus.SUCCESS;

class LocatorGenerationController {
Expand Down
7 changes: 4 additions & 3 deletions src/services/webSocketMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { NETWORK_ERROR, NO_ELEMENT_IN_DOCUMENT } from "../features/locators/util
import { locatorGenerationController } from "../features/locators/utils/locatorGenerationController";
import { sendMessage } from "../pageServices/connector";
import { webSocketController } from "./webSocketController";
import { areInProgress, selectInProgressByPageObj } from "../features/locators/selectors/locatorsFiltered.selectors";
import { selectInProgressByPageObj } from "../features/locators/selectors/locatorsFiltered.selectors";
import { selectCurrentPageObject } from "../features/pageObjects/selectors/pageObjects.selectors";
import { selectAreInProgress } from "../features/locators/selectors/locatorsByPO.selectors";

const reScheduledTasks = new Set();

Expand Down Expand Up @@ -63,12 +64,12 @@ export const updateSocketMessageHandler = (dispatch: any, state: any) => {
const pageObject = selectCurrentPageObject(state)!;
dispatch(updateLocatorGroup({ locators, pageObject }));
};
if (areInProgress(state)) throttler.accumulateAndThrottle(onStatusChange)([payload]);
if (selectAreInProgress(state)) throttler.accumulateAndThrottle(onStatusChange)([payload]);
break;
}
}
if (pong) {
if (!areInProgress(state)) webSocketController.stopPing();
if (!selectAreInProgress(state)) webSocketController.stopPing();
}
};

Expand Down
Loading