Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kostrubin committed Jul 24, 2023
1 parent d64fe56 commit 0e4c28e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
12 changes: 7 additions & 5 deletions src/common/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ export const floatToPercent = (value: number) => {
return Math.trunc(value * 100);
};

export const getLocatorPrefix = (annotationType: AnnotationType, locatorType: LocatorType): string => {
export const getLocatorPrefix = (annotationType?: AnnotationType, locatorType?: LocatorType): string => {
if (annotationType === AnnotationType.FindBy) {
return `${locatorType === LocatorType.xPath ? "xpath" : "css"} = `;
return `${locatorType === LocatorType.cssSelector ? "css" : "xpath"} = `;
}

return "";
};

export const getLocatorString = (
annotationType: AnnotationType,
locatorType: LocatorType,
annotationType: AnnotationType | undefined,
locatorType: LocatorType | undefined,
locator: LocatorValue,
type: ElementLibrary | ElementClass,
name: string
): string =>
`${annotationType}(${getLocatorPrefix(annotationType, locatorType)}"${locator.output}")\npublic ${type} ${name};`;
`${annotationType || AnnotationType.UI}(${getLocatorPrefix(annotationType, locatorType)}"${
locator.output
}")\npublic ${type} ${name};`;

export const isMacPlatform = (param: Window) => param.navigator?.userAgent.indexOf("Mac") != -1;

Expand Down
14 changes: 5 additions & 9 deletions src/features/locators/Locator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { selectFirstLocatorIdByPO } from "./selectors/locatorsByPO.selectors";
import { selectCalculatedActiveByPageObj, selectWaitingActiveByPageObj } from "./selectors/locatorsFiltered.selectors";
import { isLocatorListPage } from "../../app/utils/heplers";
import { selectCurrentPageObject } from "../pageObjects/selectors/pageObjects.selectors";
import { LocalStorageKey, getLocalStorage } from "../../common/utils/localStorage";
import { AnnotationType, LocatorType } from "../../common/types/common";

interface Props {
element: LocatorInterface;
Expand All @@ -54,15 +54,11 @@ export const Locator: React.FC<Props> = ({ element, currentPage, searchState, de

const { element_id, type, name, locator, generate, message, deleted, active, isCustomLocator } = element;

const annotationType =
element?.annotationType ||
getLocalStorage(LocalStorageKey.AnnotationType) ||
useSelector(selectCurrentPageObject)?.annotationType;
const pageObjectAnnotationType = useSelector(selectCurrentPageObject)?.annotationType;
const pageObjectLocatorType = useSelector(selectCurrentPageObject)?.locatorType;

const locatorType =
element?.locatorType ||
getLocalStorage(LocalStorageKey.LocatorType) ||
useSelector(selectCurrentPageObject)?.locatorType;
const annotationType = element?.annotationType || pageObjectAnnotationType || AnnotationType.UI;
const locatorType = element?.locatorType || pageObjectLocatorType || LocatorType.xPath;

const ref = useRef<HTMLDivElement>(null);

Expand Down
1 change: 0 additions & 1 deletion src/features/locators/components/LocatorEditDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ export const LocatorEditDialog: React.FC<Props> = ({
style={{ marginBottom: "8px" }}
>
<Select
disabled={!isValidLocator(validationMessage)}
options={[
{
value: AnnotationType.UI,
Expand Down
19 changes: 9 additions & 10 deletions src/features/locators/selectors/locatorsByPO.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSelector } from "@reduxjs/toolkit";
import { isNil } from "lodash";
import { RootState } from "../../../app/store/store";
import { LocatorType } from "../../../common/types/common";
// import { LocatorType, AnnotationType } from "../../../common/types/common";
import { selectCurrentPageObject, selectPageObjById } from "../../pageObjects/selectors/pageObjects.selectors";
import { PageObjectId } from "../../pageObjects/types/pageObjectSlice.types";
import { getLocator } from "../utils/locatorOutput";
Expand Down Expand Up @@ -31,15 +31,14 @@ export const selectPresentLocatorsByPO = createSelector(
const locByPageObj = pageObject?.locators || [];
return locators
.filter((loc) => locByPageObj.includes(loc.element_id))
.map((loc) =>
!loc.locatorType && pageObject?.locatorType === LocatorType.cssSelector
? {
...loc,
locatorType: pageObject?.locatorType,
locator: { ...loc.locator, output: getLocator(loc.locator, pageObject?.locatorType) },
}
: loc
);
.map((loc) => {
return {
...loc,
locatorType: loc.locatorType || pageObject?.locatorType,
annotationType: loc.annotationType || pageObject?.annotationType,
locator: { ...loc.locator, output: getLocator(loc.locator, pageObject?.locatorType) },
};
});
}
);

Expand Down
4 changes: 2 additions & 2 deletions src/features/locators/types/locator.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export interface Locator extends PredictedEntity {
active?: boolean;
isCustomName?: boolean;
isCustomLocator?: boolean;
annotationType: AnnotationType;
locatorType: LocatorType;
annotationType?: AnnotationType;
locatorType?: LocatorType;
message: LocatorValidationErrorType;
pageObj: PageObjectId;
parent_id: JDNHash;
Expand Down

0 comments on commit 0e4c28e

Please sign in to comment.