Skip to content

Commit

Permalink
chore: add dedicated files for constants (#1402)
Browse files Browse the repository at this point in the history
* chore: split shared.js into multiple constants files

* chore: change names of Inspector tab-related methods/constants

* chore: ensure automationName is saved in lowercase

* chore: rename inspector tab constant

* chore: move locator strategies to constants

* chore: extract all Session Inspector constants

* chore: reorder imports + extract consts from ErrorBoundary

* chore: extract consts from Session Builder

* chore: separate Session Inspector consts from common consts

* chore: move AntdTypes file into constants

* chore: refactor parseCoordinates

* chore: rename constant files to kebab case
  • Loading branch information
eglitise authored Mar 27, 2024
1 parent 03558f6 commit a7ac797
Show file tree
Hide file tree
Showing 50 changed files with 503 additions and 417 deletions.
8 changes: 4 additions & 4 deletions app/renderer/actions/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {v4 as UUID} from 'uuid';

import i18n from '../../configs/i18next.config.renderer';
import {SAVED_FRAMEWORK, SET_SAVED_GESTURES, getSetting, setSetting} from '../../shared/settings';
import {APP_MODE, NATIVE_APP} from '../components/Inspector/shared';
import {APP_MODE, NATIVE_APP} from '../constants/session-inspector';
import AppiumClient from '../lib/appium-client';
import frameworks from '../lib/client-frameworks';
import {getOptimalXPath, getSuggestedLocators} from '../utils/locator-generation';
Expand Down Expand Up @@ -74,7 +74,7 @@ export const CLEAR_COORD_ACTION = 'CLEAR_COORD_ACTION';
export const PROMPT_KEEP_ALIVE = 'PROMPT_KEEP_ALIVE';
export const HIDE_PROMPT_KEEP_ALIVE = 'HIDE_PROMPT_KEEP_ALIVE';

export const SELECT_INTERACTION_MODE = 'SELECT_INTERACTION_MODE';
export const SELECT_INSPECTOR_TAB = 'SELECT_INSPECTOR_TAB';

export const ENTERING_COMMAND_ARGS = 'ENTERING_COMMAND_ARGS';
export const CANCEL_PENDING_COMMAND = 'CANCEL_PENDING_COMMAND';
Expand Down Expand Up @@ -705,9 +705,9 @@ export function clearCoordAction() {
};
}

export function selectInteractionMode(interaction) {
export function selectInspectorTab(interaction) {
return (dispatch) => {
dispatch({type: SELECT_INTERACTION_MODE, interaction});
dispatch({type: SELECT_INSPECTOR_TAB, interaction});
};
}

Expand Down
2 changes: 1 addition & 1 deletion app/renderer/actions/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
getSetting,
setSetting,
} from '../../shared/settings';
import {APP_MODE} from '../components/Inspector/shared';
import {APP_MODE} from '../constants/session-inspector';
import CloudProviders from '../components/Session/CloudProviders';
import {fs, ipcRenderer, util} from '../polyfills';
import {addVendorPrefixes} from '../utils/other';
Expand Down
26 changes: 0 additions & 26 deletions app/renderer/components/AntdTypes.js

This file was deleted.

9 changes: 4 additions & 5 deletions app/renderer/components/ErrorBoundary/ErrorMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import {CopyOutlined} from '@ant-design/icons';
import {Alert, Button, Tooltip} from 'antd';
import React from 'react';

import {ALERT} from '../../constants/antd-types';
import {LINKS} from '../../constants/common';
import {shell} from '../../polyfills';
import {withTranslation} from '../../utils/other';
import {ALERT} from '../AntdTypes';
import styles from './ErrorMessage.css';

const CREATE_ISSUE_URL = 'https://github.com/appium/appium-inspector/issues/new/choose';

const ErrorMessage = ({error, copyTrace, t}) => (
<div className={styles.errorMessage}>
<Alert
Expand All @@ -22,8 +21,8 @@ const ErrorMessage = ({error, copyTrace, t}) => (
description={
<>
{t('Please report this issue at:')}&nbsp;
<a onClick={(e) => e.preventDefault() || shell.openExternal(CREATE_ISSUE_URL)}>
{CREATE_ISSUE_URL}
<a onClick={(e) => e.preventDefault() || shell.openExternal(LINKS.CREATE_ISSUE)}>
{LINKS.CREATE_ISSUE}
</a>
<br />
{t('Full error trace:')}
Expand Down
8 changes: 3 additions & 5 deletions app/renderer/components/Inspector/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
import _ from 'lodash';
import React from 'react';

import {ALERT, INPUT} from '../AntdTypes';
import {ALERT, INPUT} from '../../constants/antd-types';
import {COMMAND_ARG_TYPES, COMMAND_DEFINITIONS} from '../../constants/commands';
import InspectorStyles from './Inspector.css';
import {COMMAND_ARG_TYPES, COMMAND_DEFINITIONS} from './shared';

const Commands = (props) => {
const {
Expand Down Expand Up @@ -133,9 +133,7 @@ const Commands = (props) => {
<Row>
{_.toPairs(commands).map(
([commandName, command], index) =>
(!automationName ||
!command.drivers ||
command.drivers.includes(_.toLower(automationName))) && (
(!command.drivers || command.drivers.includes(automationName)) && (
<Col key={index} xs={12} sm={12} md={12} lg={8} xl={6} xxl={4}>
<div className={InspectorStyles['btn-container']}>
<Tooltip
Expand Down
27 changes: 7 additions & 20 deletions app/renderer/components/Inspector/ElementLocator.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,22 @@
import {Alert, Input, Radio, Row, Space} from 'antd';
import React from 'react';

import {ALERT} from '../AntdTypes';
import {ALERT} from '../../constants/antd-types';
import {LOCATOR_STRATEGY_MAP as STRAT} from '../../constants/session-inspector';
import InspectorStyles from './Inspector.css';

const STRAT_ID = ['id', 'Id'];
const STRAT_XPATH = ['xpath', 'XPath'];
const STRAT_NAME = ['name', 'Name'];
const STRAT_CLASS_NAME = ['class name', 'Class Name'];
const STRAT_ACCESSIBILITY_ID = ['accessibility id', 'Accessibility ID'];
const STRAT_PREDICATE = ['-ios predicate string', 'Predicate String'];
const STRAT_CLASS_CHAIN = ['-ios class chain', 'Class Chain'];
const STRAT_UIAUTOMATOR = ['-android uiautomator', 'UIAutomator'];
const STRAT_DATAMATCHER = ['-android datamatcher', 'DataMatcher'];
const STRAT_VIEWTAG = ['-android viewtag', 'View Tag'];

const locatorStrategies = (automationName) => {
let strategies = [STRAT_ID, STRAT_XPATH, STRAT_NAME, STRAT_CLASS_NAME, STRAT_ACCESSIBILITY_ID];
if (!automationName) {
return strategies;
}
switch (automationName.toLowerCase()) {
let strategies = [STRAT.ID, STRAT.XPATH, STRAT.NAME, STRAT.CLASS_NAME, STRAT.ACCESSIBILITY_ID];
switch (automationName) {
case 'xcuitest':
case 'mac2':
strategies.push(STRAT_PREDICATE, STRAT_CLASS_CHAIN);
strategies.push(STRAT.PREDICATE, STRAT.CLASS_CHAIN);
break;
case 'espresso':
strategies.push(STRAT_DATAMATCHER, STRAT_VIEWTAG);
strategies.push(STRAT.DATAMATCHER, STRAT.VIEWTAG);
break;
case 'uiautomator2':
strategies.push(STRAT_UIAUTOMATOR);
strategies.push(STRAT.UIAUTOMATOR);
break;
}
return strategies;
Expand Down
Loading

0 comments on commit a7ac797

Please sign in to comment.