Skip to content

Commit

Permalink
feat: re-enable temporarily disabled CSS calculation functionality on…
Browse files Browse the repository at this point in the history
… the back end and download the template for the zip.
  • Loading branch information
Iogsotot committed Jun 12, 2024
1 parent eb3477c commit 181f53c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 72 deletions.
9 changes: 2 additions & 7 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { StatusBar } from './components/StatusBar';
import { SeveralTabsWarning } from './components/SeveralTabsWarning';
import { HttpEndpoint, request } from '../services/backend';
import { checkSession, initLocatorSocketController } from './utils/appUtils';
import { selectCurrentPage, selectServerLocation } from './main.selectors';
import { selectCurrentPage } from './main.selectors';
import { AppDispatch, RootState, store } from './store/store';
import { useOnDisconnect } from './utils/hooks/useOnDisconnect';

Expand All @@ -22,7 +22,6 @@ import { isPageObjectPage } from './utils/helpers';
import './styles/index.less';
import { Onboarding, useOnboarding } from '../features/onboarding/useOnboarding';
import { OnboardingProvider, useOnboardingContext } from '../features/onboarding/OnboardingProvider';
import { URL } from './utils/constants';

const App = () => {
const dispatch = useDispatch<AppDispatch>();
Expand All @@ -33,7 +32,6 @@ const App = () => {
const xpathConfig = useSelector((state: RootState) => state.main.xpathConfig);
const currentPage = useSelector(selectCurrentPage);
const isSessionUnique = useSelector((state: RootState) => state.main.isSessionUnique);
const serverLocation = useSelector(selectServerLocation);

const { stepsRef } = useOnboardingContext();

Expand All @@ -54,10 +52,7 @@ const App = () => {
};

if (backendAvailable === BackendStatus.Accessed) {
// TODO: remove condition ("serverLocation === URL.local") when back-end will be ready (issues/1734)
if (serverLocation === URL.local) {
fetchTemplates();
}
fetchTemplates();
initLocatorSocketController(xpathConfig);
}
}, [backendAvailable]);
Expand Down
32 changes: 10 additions & 22 deletions src/features/locators/utils/LocatorGenerationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class LocatorGenerationController {
pageDocument: string,
pageObject?: PageObject,
maxGenerationTime?: MaxGenerationTime,
isLocalServer?: boolean,
) {
if (pageObject) this.pageObject = pageObject;
this.pageDocument = pageDocument;
Expand Down Expand Up @@ -77,32 +76,21 @@ class LocatorGenerationController {
action: WebSocketMessage.SCHEDULE_MULTIPLE_CSS_SELECTOR_GENERATIONS,
payload: {
document: this.pageDocument,
// TODO: remove condition ("isLocalServer ?", ": []") when back-end will be ready (issues/1284)
id: isLocalServer ? hashes : [],
id: hashes,
},
};

const messages = getWebSocketMessages(locatorType, this.xPathGenerationMessage, this.CssSelectorGenerationMessage);

// TODO: remove condition and variable "webSocketOperation" when back-end will be ready (issues/1284) 88, 98-105 lines
const webSocketOperation = isLocalServer
? webSocketController
.sendSocket(JSON.stringify(messages[0]))
.then(() => webSocketController.sendSocket(JSON.stringify(messages[1])))
.then(() => {
webSocketController.startPing();
})
.catch((error: unknown) => {
console.error('Error sending messages: ', error);
})
: webSocketController
.sendSocket(JSON.stringify(this.xPathGenerationMessage))
.then(() => {
webSocketController.startPing();
})
.catch((error: unknown) => {
console.error('Error sending message: ', error);
});
const webSocketOperation = webSocketController
.sendSocket(JSON.stringify(messages[0]))
.then(() => webSocketController.sendSocket(JSON.stringify(messages[1])))
.then(() => {
webSocketController.startPing();
})
.catch((error: unknown) => {
console.error('Error sending messages: ', error);
});

return webSocketOperation;
}
Expand Down
8 changes: 0 additions & 8 deletions src/features/locators/utils/runLocatorGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { selectCurrentPageObject, selectCurrentPOLocatorType } from '../../pageO
import { ILocator, LocatorsGenerationStatus } from '../types/locator.types';
import { locatorGenerationController } from './LocatorGenerationController';
import { GeneralLocatorType, LocatorType } from '../../../common/types/common';
import { URL } from '../../../app/utils/constants';
import { selectServerLocation } from '../../../app/main.selectors';

export const runLocatorGeneration = (
state: RootState,
Expand All @@ -16,18 +14,12 @@ export const runLocatorGeneration = (
const pageObject = selectCurrentPageObject(state)!;
const locatorType: GeneralLocatorType = selectCurrentPOLocatorType(state) ?? LocatorType.xPath;

// TODO: remove when back-end will be ready (issues/1734) 20-21 lines
const serverLocation = selectServerLocation(state);
const isLocalServer = serverLocation === URL.local;

locatorGenerationController.scheduleMultipleLocatorGeneration(
locatorType,
generationData,
pageDocument,
pageObject,
maxGenerationTime,
// TODO: remove when back-end will be ready (issues/1734) 30 line
isLocalServer,
);

return LocatorsGenerationStatus.started;
Expand Down
47 changes: 22 additions & 25 deletions src/features/locators/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const getLocatorValueOnTypeSwitch = async (

({ cssSelector: newLocatorValue } = await generateSelectorByHash(elementId, foundHash));
} else {
if (newLocatorType === LocatorType.cssSelector) newLocatorValue = locatorValue.cssSelector; // а не original ли надо делать?
if (newLocatorType === LocatorType.cssSelector) newLocatorValue = locatorValue.cssSelector;
try {
newLocatorValue = getLocatorValueByType(locatorValue, newLocatorType);
} catch (error) {
Expand All @@ -239,31 +239,28 @@ export const getTaskStatus = (
cssSelectorStatus: LocatorTaskStatus,
): LocatorTaskStatus | null => {
if (!xPathStatus && !cssSelectorStatus) return LocatorTaskStatus.NOT_STARTED;
// TODO: delete when back-end will be ready (issues/1284)
return xPathStatus;

// TODO: uncomment when back-end will be ready (issues/1284) 246-266 lines
// const statusMap = {
// success: xPathStatus === LocatorTaskStatus.SUCCESS && cssSelectorStatus === LocatorTaskStatus.SUCCESS,
// pending: xPathStatus === LocatorTaskStatus.PENDING || cssSelectorStatus === LocatorTaskStatus.PENDING,
// failure: xPathStatus === LocatorTaskStatus.FAILURE || cssSelectorStatus === LocatorTaskStatus.FAILURE,
// revoked: xPathStatus === LocatorTaskStatus.REVOKED || cssSelectorStatus === LocatorTaskStatus.REVOKED,
// };
//
// if (statusMap.success) {
// return LocatorTaskStatus.SUCCESS;
// }
// if (statusMap.pending) {
// return LocatorTaskStatus.PENDING;
// }
// if (statusMap.failure) {
// return LocatorTaskStatus.FAILURE;
// }
// if (statusMap.revoked) {
// return LocatorTaskStatus.REVOKED;
// }
// // fallback for any unhandled cases
// return null;
const statusMap = {
success: xPathStatus === LocatorTaskStatus.SUCCESS && cssSelectorStatus === LocatorTaskStatus.SUCCESS,
pending: xPathStatus === LocatorTaskStatus.PENDING || cssSelectorStatus === LocatorTaskStatus.PENDING,
failure: xPathStatus === LocatorTaskStatus.FAILURE || cssSelectorStatus === LocatorTaskStatus.FAILURE,
revoked: xPathStatus === LocatorTaskStatus.REVOKED || cssSelectorStatus === LocatorTaskStatus.REVOKED,
};

if (statusMap.success) {
return LocatorTaskStatus.SUCCESS;
}
if (statusMap.pending) {
return LocatorTaskStatus.PENDING;
}
if (statusMap.failure) {
return LocatorTaskStatus.FAILURE;
}
if (statusMap.revoked) {
return LocatorTaskStatus.REVOKED;
}
// fallback for any unhandled cases
return null;
};

export const hasAllLocators = ({ locatorValue }: ILocator) =>
Expand Down
11 changes: 1 addition & 10 deletions src/services/webSocketMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import {
WSResponseAction,
XpathMultipleGenerationPayload,
} from './webSoket.types';
import { useSelector } from 'react-redux';
import { URL } from '../app/utils/constants';
import { selectServerLocation } from '../app/main.selectors';

const isCssSelectorsGenerationPayloadGuard = (payload: any): payload is CssSelectorsGenerationPayload => {
return (
Expand Down Expand Up @@ -75,17 +72,11 @@ export const updateSocketMessageHandler = (dispatch: any, state: any) => {
);
}
const locatorType: GeneralLocatorType = selectCurrentPOLocatorType(state) ?? LocatorType.xPath;
// TODO: remove when back-end will be ready (issues/1734) 79-80 lines
const serverLocation = useSelector(selectServerLocation);
const isLocalServer = serverLocation === URL.local;

locatorGenerationController.scheduleMultipleLocatorGeneration(
locatorType,
[element],
pageDocumentForRubula,
// TODO: remove when back-end will be ready (issues/1734) 86-88 lines
undefined,
undefined,
isLocalServer,
);
};
rescheduleTask();
Expand Down

0 comments on commit 181f53c

Please sign in to comment.