diff --git a/manifest.json b/manifest.json index 678c9299..32147cae 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "JDN — Page Object Generator", "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.15.34", + "version": "3.15.35", "icons": { "128": "icon128.png" }, diff --git a/package-lock.json b/package-lock.json index a524f50d..d9974878 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "jdn-ai-chrome-extension", - "version": "3.15.34", + "version": "3.15.35", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/package.json b/package.json index 9927b555..ee82819e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jdn-ai-chrome-extension", - "version": "3.15.34", + "version": "3.15.35", "description": "jdn-ai chrome extension", "scripts": { "start": "webpack --watch --env devenv", diff --git a/src/__tests__/__mocks__/locator.mock.js b/src/__tests__/__mocks__/locator.mock.js index 1f2d9ad7..d5b735d1 100644 --- a/src/__tests__/__mocks__/locator.mock.js +++ b/src/__tests__/__mocks__/locator.mock.js @@ -1,6 +1,6 @@ export const locator1 = { attrId: '', - element_id: '8736312404689610766421832473', + elementId: '8736312404689610766421832473', is_shown: true, height: 201.3333435059, locatorValue: { @@ -26,7 +26,7 @@ export const locator1 = { export const locator2 = { attrId: '', - element_id: '2222222222', + elementId: '2222222222', is_shown: true, height: 201.3333435059, locatorValue: { @@ -49,7 +49,7 @@ export const locator2 = { export const locator3 = { attrId: '', - element_id: '333333333333333', + elementId: '333333333333333', is_shown: true, height: 201.3333435059, locatorValue: { diff --git a/src/__tests__/__mocks__/pageObjectMocks/elementsWithoutNames.js b/src/__tests__/__mocks__/pageObjectMocks/elementsWithoutNames.js index 9617c026..e5330e17 100644 --- a/src/__tests__/__mocks__/pageObjectMocks/elementsWithoutNames.js +++ b/src/__tests__/__mocks__/pageObjectMocks/elementsWithoutNames.js @@ -1,6 +1,6 @@ export const elementsWithoutNames = [ { - element_id: '7824983223872788250093302805', + elementId: '7824983223872788250093302805', is_shown: true, predicted_label: 'radiogroup', elemId: 'radio79', @@ -11,7 +11,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '3976799717872788243800691939', + elementId: '3976799717872788243800691939', is_shown: true, predicted_label: 'list', elemId: 'radio79', @@ -22,7 +22,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '2531946027872788259730157905', + elementId: '2531946027872788259730157905', is_shown: true, predicted_label: 'list', elemId: 'radio79', @@ -33,7 +33,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '1788878284872788254954433922', + elementId: '1788878284872788254954433922', is_shown: true, predicted_label: 'badge', elemId: 'anyNymber', @@ -44,7 +44,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '8073262067872788257041578300', + elementId: '8073262067872788257041578300', is_shown: true, predicted_label: 'chip', elemId: '', @@ -55,7 +55,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '8162387396872788255600213565', + elementId: '8162387396872788255600213565', is_shown: true, predicted_label: 'chip', elemId: '', @@ -66,7 +66,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '3824832072872788248203820469', + elementId: '3824832072872788248203820469', is_shown: true, predicted_label: 'badge', elemId: 'anyNymber', @@ -77,7 +77,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '1195797979872788259469412332', + elementId: '1195797979872788259469412332', is_shown: true, predicted_label: 'list', elemId: '', @@ -88,7 +88,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '1195797979872788259469412444', + elementId: '1195797979872788259469412444', is_shown: true, predicted_label: 'list', elemId: '', @@ -99,7 +99,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '3265985627872788257228708643', + elementId: '3265985627872788257228708643', is_shown: true, predicted_label: 'button', locator: { @@ -107,7 +107,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '3901491381872788252561828171', + elementId: '3901491381872788252561828171', is_shown: true, predicted_label: 'button', elemId: '1001loginButton', @@ -116,7 +116,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '9384531537872788240323543297', + elementId: '9384531537872788240323543297', is_shown: true, predicted_label: 'menu', elemId: ' menu Foo ', @@ -125,7 +125,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '3901491381872788252561828179', + elementId: '3901491381872788252561828179', is_shown: true, predicted_label: 'button', elemId: '1001loginButton', @@ -134,7 +134,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '1195797979872788259469412450', + elementId: '1195797979872788259469412450', is_shown: true, predicted_label: 'list', elemId: '', @@ -145,7 +145,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '1195797979872788259469412460', + elementId: '1195797979872788259469412460', is_shown: true, predicted_label: 'list', elemId: '', @@ -156,7 +156,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '1195797979872788259469412460', + elementId: '1195797979872788259469412460', is_shown: true, predicted_label: 'list', elemId: '', @@ -167,7 +167,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '1195797979872788259469412000', + elementId: '1195797979872788259469412000', is_shown: true, predicted_label: 'list', elemId: '', @@ -178,7 +178,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '7824983223872788250093302', + elementId: '7824983223872788250093302', is_shown: true, predicted_label: 'radiogroup', elemAriaLabel: 'Click this control', @@ -188,7 +188,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '78249832238727882500933021', + elementId: '78249832238727882500933021', is_shown: true, predicted_label: 'radiogroup', elemAriaLabel: 'Click this control with very long text text text text text text text text text 123', @@ -198,7 +198,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '78249832238727882500933022', + elementId: '78249832238727882500933022', is_shown: true, predicted_label: 'radiogroup', elemAriaLabel: 'Click this control with very long text text text text text text text text text 123', @@ -208,7 +208,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '782498322387278825009330223', + elementId: '782498322387278825009330223', is_shown: true, predicted_label: 'radiogroup', elemAriaLabel: 'Кнопка вызова единорога', @@ -218,7 +218,7 @@ export const elementsWithoutNames = [ }, }, { - element_id: '782498322387278825009330200', + elementId: '782498322387278825009330200', is_shown: true, predicted_label: 'radiogroup', elemText: 'A string with non-latin (любой) unicode character ’ we expect to exclude ', diff --git a/src/__tests__/__mocks__/pageObjectMocks/pageObject.mock.js b/src/__tests__/__mocks__/pageObjectMocks/pageObject.mock.js index a289b1a9..03eddfbc 100644 --- a/src/__tests__/__mocks__/pageObjectMocks/pageObject.mock.js +++ b/src/__tests__/__mocks__/pageObjectMocks/pageObject.mock.js @@ -4,7 +4,7 @@ export const getLocatorsByAnnotationType = (value) => { return [ { attrId: '', - element_id: '0955274655778840492142094709', + elementId: '0955274655778840492142094709', is_shown: true, height: 60, locatorValue: { @@ -28,7 +28,7 @@ export const getLocatorsByAnnotationType = (value) => { }, { attrId: '', - element_id: '2022378243778840502461724770', + elementId: '2022378243778840502461724770', is_shown: true, height: 15.3333339691, locatorValue: { @@ -52,7 +52,7 @@ export const getLocatorsByAnnotationType = (value) => { }, { attrId: '', - element_id: '2713188863778840498565585241', + elementId: '2713188863778840498565585241', is_shown: true, height: 38.6666679382, locatorValue: { @@ -79,7 +79,7 @@ export const getLocatorsByAnnotationType = (value) => { export const locators = [ { attrId: '', - element_id: '0955274655778840492142094709', + elementId: '0955274655778840492142094709', is_shown: true, height: 60, locatorValue: { @@ -103,7 +103,7 @@ export const locators = [ }, { attrId: '', - element_id: '2022378243778840502461724770', + elementId: '2022378243778840502461724770', is_shown: true, height: 15.3333339691, locatorValue: { @@ -127,7 +127,7 @@ export const locators = [ }, { attrId: '', - element_id: '2713188863778840498565585241', + elementId: '2713188863778840498565585241', is_shown: true, height: 38.6666679382, locatorValue: { @@ -153,7 +153,7 @@ export const locators = [ export const locatorsWithFindBy = [ { attrId: '', - element_id: '0955274655778840492142094709', + elementId: '0955274655778840492142094709', is_shown: true, height: 60, locatorValue: { @@ -177,7 +177,7 @@ export const locatorsWithFindBy = [ }, { attrId: '', - element_id: '2022378243778840502461724770', + elementId: '2022378243778840502461724770', is_shown: true, height: 15.3333339691, locatorValue: { @@ -201,7 +201,7 @@ export const locatorsWithFindBy = [ }, { attrId: '', - element_id: '2713188863778840498565585241', + elementId: '2713188863778840498565585241', is_shown: true, height: 38.6666679382, locatorValue: { @@ -226,10 +226,10 @@ export const locatorsWithFindBy = [ export const locatorsVividus = [ { - element_id: '0057770603115098154872149076_0', + elementId: '0057770603115098154872149076_0', is_shown: true, predicted_label: 'label', - childs: ['1052464727115098158766915230'], + // childs: ['1052464727115098158766915230'], displayed: false, jdnHash: '0057770603115098154872149076', pageObj: 0, @@ -257,10 +257,10 @@ export const locatorsVividus = [ locatorType: LocatorType.cssSelector, }, { - element_id: '0735357117115098156691382591_0', + elementId: '0735357117115098156691382591_0', is_shown: true, predicted_label: 'label', - childs: null, + // childs: null, displayed: false, jdnHash: '0735357117115098156691382591', pageObj: 0, @@ -292,10 +292,10 @@ export const locatorsVividus = [ isGenerated: true, }, { - element_id: '0790139442115098150038335533_0', + elementId: '0790139442115098150038335533_0', is_shown: true, predicted_label: 'textarea', - childs: null, + // childs: null, displayed: false, jdnHash: '0790139442115098150038335533', pageObj: 0, @@ -327,10 +327,10 @@ export const locatorsVividus = [ isGenerated: true, }, { - element_id: '0928942213115098152027249027_0', + elementId: '0928942213115098152027249027_0', is_shown: true, predicted_label: 'label', - childs: null, + // childs: null, displayed: false, jdnHash: '0928942213115098152027249027', pageObj: 0, diff --git a/src/__tests__/locators/locatorsSlice.test.js b/src/__tests__/locators/locatorsSlice.test.js index f3988dbc..0d36e840 100644 --- a/src/__tests__/locators/locatorsSlice.test.js +++ b/src/__tests__/locators/locatorsSlice.test.js @@ -57,7 +57,7 @@ describe('changeLocatorAttributes reducer', () => { // Act store.dispatch( changeLocatorAttributes({ - element_id: '8736312404689610766421832473', + elementId: '8736312404689610766421832473', is_shown: true, locatorValue: "//*[@class='sidebar-menu left']", name: 'myAwesomeLocator', @@ -87,7 +87,7 @@ describe('changeLocatorAttributes reducer', () => { // Act store.dispatch( changeLocatorAttributes({ - element_id: '8736312404689610766421832473', + elementId: '8736312404689610766421832473', is_shown: true, locatorValue: "//*[@class='sidebar-menu left']", name: 'myAwesomeLocator', @@ -117,7 +117,7 @@ describe('changeLocatorAttributes reducer', () => { // Act store.dispatch( changeLocatorAttributes({ - element_id: '8736312404689610766421832473', + elementId: '8736312404689610766421832473', is_shown: true, locatorValue: "//*[@class='any-class']", locatorType: LocatorType.xPath, @@ -146,7 +146,7 @@ describe('changeLocatorAttributes reducer', () => { // Act store.dispatch( changeLocatorAttributes({ - element_id: '8736312404689610766421832473', + elementId: '8736312404689610766421832473', is_shown: true, locatorValue: "//*[@class='any-class112']", name: 'myAwesomeLocator', diff --git a/src/__tests__/locators/utils/__mocks__/locatorsList.mock.ts b/src/__tests__/locators/utils/__mocks__/locatorsList.mock.ts index 79727ec4..54db2e52 100644 --- a/src/__tests__/locators/utils/__mocks__/locatorsList.mock.ts +++ b/src/__tests__/locators/utils/__mocks__/locatorsList.mock.ts @@ -5,7 +5,7 @@ import { LocatorType } from '../../../../common/types/common'; export const locatorsListMock = [ { - element_id: '7967190244322359771369749968_0', + elementId: '7967190244322359771369749968_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -28,7 +28,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '3969471880322359761484771163_0', + elementId: '3969471880322359761484771163_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -51,7 +51,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '0045220328322359764482356698_0', + elementId: '0045220328322359764482356698_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -74,7 +74,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '6771529534322359778589411351_0', + elementId: '6771529534322359778589411351_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -97,7 +97,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '4899732051322359779677566872_0', + elementId: '4899732051322359779677566872_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -120,7 +120,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '4829071593322359778594168519_0', + elementId: '4829071593322359778594168519_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -143,7 +143,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '9636042053322359773245578788_0', + elementId: '9636042053322359773245578788_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -166,7 +166,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '8381553594322359777170267551_0', + elementId: '8381553594322359777170267551_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -189,7 +189,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '4899732051322359779677566873_0', + elementId: '4899732051322359779677566873_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -212,7 +212,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '4829071593322359778594168522_0', + elementId: '4829071593322359778594168522_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -235,7 +235,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '9636042053322359773245578777_0', + elementId: '9636042053322359773245578777_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -258,7 +258,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '8381553594322359777170267550_0', + elementId: '8381553594322359777170267550_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -281,7 +281,7 @@ export const locatorsListMock = [ isChecked: false, }, { - element_id: '796719024432235977136974900_0', + elementId: '796719024432235977136974900_0', is_shown: true, parent_id: '', jdnHash: '796719024432235977136974900', @@ -309,7 +309,7 @@ export const locatorsListMock = [ export const locatorsListMockForVividus = [ { - element_id: '7967190244322359771369749968_0', + elementId: '7967190244322359771369749968_0', is_shown: true, isGenerated: true, pageObj: 0, @@ -334,7 +334,7 @@ export const locatorsListMockForVividus = [ vividusOutput: "variables.HomePage.Label.materialUi=By.xPath(//*[@index='5']//*[@index='8']/a)", }, { - element_id: '3969471880322359761484771163_0', + elementId: '3969471880322359761484771163_0', is_shown: true, isGenerated: true, pageObj: 0, diff --git a/src/__tests__/locators/utils/__mocks__/locatorsTree.mock.ts b/src/__tests__/locators/utils/__mocks__/locatorsTree.mock.ts index 9f317677..7a78a7da 100644 --- a/src/__tests__/locators/utils/__mocks__/locatorsTree.mock.ts +++ b/src/__tests__/locators/utils/__mocks__/locatorsTree.mock.ts @@ -5,7 +5,7 @@ export const locatorsTreeMock = [ { depth: 0, searchState: undefined, - element_id: '7967190244322359771369749968_0', + elementId: '7967190244322359771369749968_0', is_shown: true, parent_id: '', jdnHash: '7967190244322359771369749968', @@ -30,7 +30,7 @@ export const locatorsTreeMock = [ { depth: 1, searchState: undefined, - element_id: '3969471880322359761484771163_0', + elementId: '3969471880322359761484771163_0', is_shown: true, parent_id: '7967190244322359771369749968', jdnHash: '3969471880322359761484771163', @@ -54,7 +54,7 @@ export const locatorsTreeMock = [ children: [ { searchState: undefined, - element_id: '0045220328322359764482356698_0', + elementId: '0045220328322359764482356698_0', is_shown: true, parent_id: '3969471880322359761484771163', jdnHash: '0045220328322359764482356698', @@ -79,7 +79,7 @@ export const locatorsTreeMock = [ depth: 2, }, { - element_id: '6771529534322359778589411351_0', + elementId: '6771529534322359778589411351_0', is_shown: true, parent_id: '3969471880322359761484771163', jdnHash: '6771529534322359778589411351', @@ -109,7 +109,7 @@ export const locatorsTreeMock = [ { depth: 1, searchState: undefined, - element_id: '4899732051322359779677566872_0', + elementId: '4899732051322359779677566872_0', is_shown: true, parent_id: '7967190244322359771369749968', jdnHash: '4899732051322359779677566872', @@ -134,7 +134,7 @@ export const locatorsTreeMock = [ { depth: 2, searchState: undefined, - element_id: '4829071593322359778594168519_0', + elementId: '4829071593322359778594168519_0', is_shown: true, parent_id: '4899732051322359779677566872', jdnHash: '4829071593322359778594168519', @@ -159,7 +159,7 @@ export const locatorsTreeMock = [ { depth: 3, searchState: undefined, - element_id: '9636042053322359773245578788_0', + elementId: '9636042053322359773245578788_0', is_shown: true, parent_id: '4829071593322359778594168519', jdnHash: '9636042053322359773245578788', @@ -185,7 +185,7 @@ export const locatorsTreeMock = [ { depth: 3, searchState: undefined, - element_id: '8381553594322359777170267551_0', + elementId: '8381553594322359777170267551_0', is_shown: true, parent_id: '4829071593322359778594168519', jdnHash: '8381553594322359777170267551', @@ -215,7 +215,7 @@ export const locatorsTreeMock = [ { depth: 1, searchState: undefined, - element_id: '4899732051322359779677566873_0', + elementId: '4899732051322359779677566873_0', is_shown: true, parent_id: '7967190244322359771369749968', jdnHash: '4899732051322359779677566873', @@ -240,7 +240,7 @@ export const locatorsTreeMock = [ { depth: 2, searchState: undefined, - element_id: '4829071593322359778594168522_0', + elementId: '4829071593322359778594168522_0', is_shown: true, parent_id: '4899732051322359779677566873', jdnHash: '4829071593322359778594168522', @@ -265,7 +265,7 @@ export const locatorsTreeMock = [ { depth: 3, searchState: undefined, - element_id: '9636042053322359773245578777_0', + elementId: '9636042053322359773245578777_0', is_shown: true, parent_id: '4829071593322359778594168522', jdnHash: '9636042053322359773245578777', @@ -291,7 +291,7 @@ export const locatorsTreeMock = [ { depth: 3, searchState: undefined, - element_id: '8381553594322359777170267550_0', + elementId: '8381553594322359777170267550_0', is_shown: true, parent_id: '4829071593322359778594168522', jdnHash: '8381553594322359777170267550', @@ -323,7 +323,7 @@ export const locatorsTreeMock = [ { depth: 0, searchState: undefined, - element_id: '796719024432235977136974900_0', + elementId: '796719024432235977136974900_0', is_shown: true, parent_id: '', jdnHash: '796719024432235977136974900', diff --git a/src/__tests__/locators/utils/__mocks__/locatorsTreeSearch.mock.ts b/src/__tests__/locators/utils/__mocks__/locatorsTreeSearch.mock.ts index e11ea8f2..4ecda521 100644 --- a/src/__tests__/locators/utils/__mocks__/locatorsTreeSearch.mock.ts +++ b/src/__tests__/locators/utils/__mocks__/locatorsTreeSearch.mock.ts @@ -5,7 +5,7 @@ export const locatorsTreeMockSearch = [ { depth: 0, searchState: 'hidden', - element_id: '7967190244322359771369749968_0', + elementId: '7967190244322359771369749968_0', is_shown: true, parent_id: '', jdnHash: '7967190244322359771369749968', @@ -30,7 +30,7 @@ export const locatorsTreeMockSearch = [ { depth: 2, searchState: 'none', - element_id: '9636042053322359773245578777_0', + elementId: '9636042053322359773245578777_0', is_shown: true, parent_id: '4829071593322359778594168522', jdnHash: '9636042053322359773245578777', @@ -58,7 +58,7 @@ export const locatorsTreeMockSearch = [ { depth: 0, searchState: 'none', - element_id: '796719024432235977136974900_0', + elementId: '796719024432235977136974900_0', is_shown: true, parent_id: '', jdnHash: '796719024432235977136974900', diff --git a/src/__tests__/locators/utils/__mocks__/locatorsTreeSearchNamesTypes.mock.ts b/src/__tests__/locators/utils/__mocks__/locatorsTreeSearchNamesTypes.mock.ts index e3435612..d56147e0 100644 --- a/src/__tests__/locators/utils/__mocks__/locatorsTreeSearchNamesTypes.mock.ts +++ b/src/__tests__/locators/utils/__mocks__/locatorsTreeSearchNamesTypes.mock.ts @@ -6,7 +6,7 @@ export const locatorsTreeMockSearchTypesNames = [ { depth: 0, searchState: SearchState.Hidden, - element_id: '7967190244322359771369749968_0', + elementId: '7967190244322359771369749968_0', is_shown: true, parent_id: '', jdnHash: '7967190244322359771369749968', @@ -31,7 +31,7 @@ export const locatorsTreeMockSearchTypesNames = [ { depth: 2, searchState: 'none', - element_id: '4829071593322359778594168519_0', + elementId: '4829071593322359778594168519_0', is_shown: true, parent_id: '4899732051322359779677566872', jdnHash: '4829071593322359778594168519', @@ -56,7 +56,7 @@ export const locatorsTreeMockSearchTypesNames = [ { depth: 3, searchState: 'none', - element_id: '9636042053322359773245578788_0', + elementId: '9636042053322359773245578788_0', is_shown: true, parent_id: '4829071593322359778594168519', jdnHash: '9636042053322359773245578788', @@ -82,7 +82,7 @@ export const locatorsTreeMockSearchTypesNames = [ { depth: 3, searchState: 'none', - element_id: '8381553594322359777170267551_0', + elementId: '8381553594322359777170267551_0', is_shown: true, parent_id: '4829071593322359778594168519', jdnHash: '8381553594322359777170267551', @@ -110,7 +110,7 @@ export const locatorsTreeMockSearchTypesNames = [ { depth: 2, searchState: 'none', - element_id: '4829071593322359778594168522_0', + elementId: '4829071593322359778594168522_0', is_shown: true, parent_id: '4899732051322359779677566873', jdnHash: '4829071593322359778594168522', @@ -135,7 +135,7 @@ export const locatorsTreeMockSearchTypesNames = [ { depth: 3, searchState: 'none', - element_id: '9636042053322359773245578777_0', + elementId: '9636042053322359773245578777_0', is_shown: true, parent_id: '4829071593322359778594168522', jdnHash: '9636042053322359773245578777', @@ -161,7 +161,7 @@ export const locatorsTreeMockSearchTypesNames = [ { depth: 3, searchState: 'none', - element_id: '8381553594322359777170267550_0', + elementId: '8381553594322359777170267550_0', is_shown: true, parent_id: '4829071593322359778594168522', jdnHash: '8381553594322359777170267550', diff --git a/src/__tests__/locators/utils/convertToListWithChildren.test.ts b/src/__tests__/locators/utils/convertToListWithChildren.test.ts index 9bdfc796..873a5093 100644 --- a/src/__tests__/locators/utils/convertToListWithChildren.test.ts +++ b/src/__tests__/locators/utils/convertToListWithChildren.test.ts @@ -4,7 +4,7 @@ import { convertToListWithChildren } from '../../../features/locators/utils/loca describe('convertToListWithChildren', () => { const inputList: Partial[] = [ { - element_id: '1', + elementId: '1', is_shown: true, jdnHash: 'hash1', name: 'Element 1', @@ -12,7 +12,7 @@ describe('convertToListWithChildren', () => { isGenerated: true, }, { - element_id: '2', + elementId: '2', is_shown: true, jdnHash: 'hash2', name: 'Element 2', @@ -20,7 +20,7 @@ describe('convertToListWithChildren', () => { isGenerated: true, }, { - element_id: '3', + elementId: '3', is_shown: true, jdnHash: 'hash3', name: 'Element 3', @@ -28,7 +28,7 @@ describe('convertToListWithChildren', () => { isGenerated: true, }, { - element_id: '4', + elementId: '4', is_shown: true, jdnHash: 'hash4', name: 'Element 4', @@ -39,7 +39,7 @@ describe('convertToListWithChildren', () => { const expectedOutput: Partial[] = [ { - element_id: '1', + elementId: '1', is_shown: true, jdnHash: 'hash1', name: 'Element 1', @@ -48,7 +48,7 @@ describe('convertToListWithChildren', () => { children: ['2'], }, { - element_id: '2', + elementId: '2', is_shown: true, jdnHash: 'hash2', name: 'Element 2', @@ -57,7 +57,7 @@ describe('convertToListWithChildren', () => { children: ['3'], }, { - element_id: '3', + elementId: '3', is_shown: true, jdnHash: 'hash3', name: 'Element 3', @@ -66,7 +66,7 @@ describe('convertToListWithChildren', () => { children: [], }, { - element_id: '4', + elementId: '4', is_shown: true, jdnHash: 'hash4', name: 'Element 4', @@ -78,7 +78,7 @@ describe('convertToListWithChildren', () => { const inputList2: Partial[] = [ { - element_id: '1', + elementId: '1', is_shown: true, jdnHash: 'hash1', name: 'Element 1', @@ -86,14 +86,14 @@ describe('convertToListWithChildren', () => { isGenerated: true, }, { - element_id: '2', + elementId: '2', is_shown: true, jdnHash: 'hash2', name: 'Element 2', isGenerated: true, }, { - element_id: '3', + elementId: '3', is_shown: true, jdnHash: 'hash3', name: 'Element 3', @@ -103,7 +103,7 @@ describe('convertToListWithChildren', () => { ]; const expectedOutput2: Partial[] = [ { - element_id: '1', + elementId: '1', is_shown: true, jdnHash: 'hash1', name: 'Element 1', @@ -112,7 +112,7 @@ describe('convertToListWithChildren', () => { children: [], }, { - element_id: '2', + elementId: '2', is_shown: true, jdnHash: 'hash2', name: 'Element 2', @@ -120,7 +120,7 @@ describe('convertToListWithChildren', () => { children: ['3'], }, { - element_id: '3', + elementId: '3', is_shown: true, jdnHash: 'hash3', name: 'Element 3', diff --git a/src/__tests__/locators/utils/sortLocatorsWithChildren.test..ts b/src/__tests__/locators/utils/sortLocatorsWithChildren.test..ts index 46efc01a..4b8b1097 100644 --- a/src/__tests__/locators/utils/sortLocatorsWithChildren.test..ts +++ b/src/__tests__/locators/utils/sortLocatorsWithChildren.test..ts @@ -4,35 +4,35 @@ import { sortLocatorsWithChildren } from '../../../features/locators/utils/sortL describe('sortLocatorsWithChildren', () => { const input = [ { - element_id: '1', + elementId: '1', is_shown: true, children: ['2', '5'], }, { - element_id: '4', + elementId: '4', is_shown: true, children: [], }, { - element_id: '2', + elementId: '2', is_shown: true, children: ['3'], parent_id: '1', }, { - element_id: '3', + elementId: '3', is_shown: true, children: [], parent_id: '2', }, { - element_id: '5', + elementId: '5', is_shown: true, children: ['8'], parent_id: '1', }, { - element_id: '6', + elementId: '6', is_shown: true, children: [], parent_id: '7', @@ -40,42 +40,42 @@ describe('sortLocatorsWithChildren', () => { ]; const expectedOutput = [ { - element_id: '1', + elementId: '1', is_shown: true, children: ['2', '5'], }, { - element_id: '2', + elementId: '2', is_shown: true, children: ['3'], parent_id: '1', }, { - element_id: '3', + elementId: '3', is_shown: true, children: [], parent_id: '2', }, { - element_id: '5', + elementId: '5', is_shown: true, children: ['8'], parent_id: '1', }, { - element_id: '4', + elementId: '4', is_shown: true, children: [], }, { - element_id: '6', + elementId: '6', is_shown: true, children: [], parent_id: '7', }, ]; - test('should sort locators with childs', () => { + test('should sort locators with children', () => { const output = sortLocatorsWithChildren(input as ILocator[]); expect(output).toEqual(expectedOutput); }); diff --git a/src/__tests__/pageObject/__mocks__/selectLocatorsByPageObject.mock.ts b/src/__tests__/pageObject/__mocks__/selectLocatorsByPageObject.mock.ts index 7b79d1ce..61c634b0 100644 --- a/src/__tests__/pageObject/__mocks__/selectLocatorsByPageObject.mock.ts +++ b/src/__tests__/pageObject/__mocks__/selectLocatorsByPageObject.mock.ts @@ -58,7 +58,7 @@ export const getRootState = (_pageObject: PageObject) => ({ present: { entities: { '7524916072510597399809892823_0': { - element_id: '7524916072510597399809892823_0', + elementId: '7524916072510597399809892823_0', is_shown: true, predicted_label: 'dialog', jdnHash: '7524916072510597399809892823', @@ -83,7 +83,7 @@ export const getRootState = (_pageObject: PageObject) => ({ active: false, }, '2075611903510597386448924232_0': { - element_id: '2075611903510597386448924232_0', + elementId: '2075611903510597386448924232_0', is_shown: true, predicted_label: 'list', jdnHash: '2075611903510597386448924232', @@ -111,7 +111,7 @@ export const getRootState = (_pageObject: PageObject) => ({ isGenerated: true, }, '4138940493550098806301857686_0': { - element_id: '4138940493550098806301857686_0', + elementId: '4138940493550098806301857686_0', is_shown: true, predicted_label: 'menu', jdnHash: '4138940493550098806301857686', @@ -143,7 +143,7 @@ export const getRootState = (_pageObject: PageObject) => ({ export const selectMockedLocators = (pageObject: PageObject) => [ { - element_id: '7524916072510597399809892823_0', + elementId: '7524916072510597399809892823_0', is_shown: true, predicted_label: 'dialog', jdnHash: '7524916072510597399809892823', @@ -168,7 +168,7 @@ export const selectMockedLocators = (pageObject: PageObject) => [ active: false, }, { - element_id: '2075611903510597386448924232_0', + elementId: '2075611903510597386448924232_0', is_shown: true, predicted_label: 'list', jdnHash: '2075611903510597386448924232', @@ -200,7 +200,7 @@ export const selectMockedLocators = (pageObject: PageObject) => [ isGenerated: true, }, { - element_id: '4138940493550098806301857686_0', + elementId: '4138940493550098806301857686_0', is_shown: true, predicted_label: 'menu', jdnHash: '4138940493550098806301857686', diff --git a/src/app/App.tsx b/src/app/App.tsx index 85f7e82f..a5ed8e82 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -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 } from './main.selectors'; +import { selectCurrentPage, selectServerLocation } from './main.selectors'; import { AppDispatch, RootState, store } from './store/store'; import { useOnDisconnect } from './utils/hooks/useOnDisconnect'; @@ -22,15 +22,18 @@ 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(); const [jdiTemplate, setJdiTemplate] = useState(undefined); const [vividusTemplate, setVividusTemplate] = useState(undefined); + const backendAvailable = useSelector((state: RootState) => state.main.backendAvailable); const xpathConfig = useSelector((state: RootState) => state.main.xpathConfig); const currentPage = useSelector(selectCurrentPage); - const dispatch = useDispatch(); const isSessionUnique = useSelector((state: RootState) => state.main.isSessionUnique); + const serverLocation = useSelector(selectServerLocation); const { stepsRef } = useOnboardingContext(); @@ -51,8 +54,10 @@ const App = () => { }; if (backendAvailable === BackendStatus.Accessed) { - // TODO: uncomment when back-end will be ready (issues/1734) - // fetchTemplates(); + // TODO: remove condition ("serverLocation === URL.local") when back-end will be ready (issues/1734) + if (serverLocation === URL.local) { + fetchTemplates(); + } initLocatorSocketController(xpathConfig); } }, [backendAvailable]); diff --git a/src/app/components/StatusBar.tsx b/src/app/components/StatusBar.tsx index 7e694503..688bb832 100644 --- a/src/app/components/StatusBar.tsx +++ b/src/app/components/StatusBar.tsx @@ -5,7 +5,7 @@ import { Button, Space, Tooltip, Typography } from 'antd'; import { isNil } from 'lodash'; import { CloudCheck, CloudSlash, DesktopTower, Info } from '@phosphor-icons/react'; import { BackendStatus } from '../types/mainSlice.types'; -import { URL, componentsTexts } from '../utils/constants'; +import { componentsTexts, URL } from '../utils/constants'; import { RootState } from '../store/store'; import DesktopSlash from '../assets/desktopTowerSlash.svg'; import { readmeLinkAddress } from '../../common/constants/constants'; @@ -14,6 +14,7 @@ import { LocatorsGenerationStatus } from '../../features/locators/types/locator. import { OnboardingButton } from './OnboardingButton'; import { OnboardingStep } from '../../features/onboarding/constants'; import { useOnboardingContext } from '../../features/onboarding/OnboardingProvider'; +import { selectServerLocation } from '../main.selectors'; type TServerIndicator = { backendAvailable: BackendStatus; @@ -72,16 +73,14 @@ const ServerIndicator: FC = ({ backendAvailable, serverLocatio }; export const StatusBar = () => { - const backendVer = useSelector((_state) => _state.main.serverVersion ?? ''); - const backendAvailable = useSelector((_state) => _state.main.backendAvailable); - const serverLocation = useSelector((_state) => _state.main.baseUrl ?? ''); - const generationStatus = useSelector( - (_state) => _state.locators.present.generationStatus, - ); + const backendVer = useSelector((state: RootState) => state.main.serverVersion ?? ''); + const backendAvailable = useSelector((state: RootState) => state.main.backendAvailable); + const serverLocation = useSelector(selectServerLocation); + const generationStatus = useSelector((state: RootState) => state.locators.present.generationStatus); + const isSessionUnique = useSelector((state: RootState) => state.main.isSessionUnique); const manifest = chrome.runtime.getManifest(); const pluginVer = manifest.version; - const isSessionUnique = useSelector((state: RootState) => state.main.isSessionUnique); const readmeRef = React.createRef(); diff --git a/src/app/main.selectors.ts b/src/app/main.selectors.ts index bc725be4..a27f19ce 100644 --- a/src/app/main.selectors.ts +++ b/src/app/main.selectors.ts @@ -9,6 +9,10 @@ export const selectCurrentPage = (state: RootState) => { return last(state.main.pageHistory) || ({ page: PageType.PageObject } as Page); }; +const selectMain = (state: RootState) => state.main; + +export const selectServerLocation = createSelector([selectMain], (main) => main.baseUrl ?? ''); + export const selectIsDefaultState = createSelector( selectCurrentPage, selectPageObjects, diff --git a/src/common/components/notification/middlewares/cancellableActions.ts b/src/common/components/notification/middlewares/cancellableActions.ts index 802ff71f..3cafe3ec 100644 --- a/src/common/components/notification/middlewares/cancellableActions.ts +++ b/src/common/components/notification/middlewares/cancellableActions.ts @@ -32,8 +32,8 @@ export const cancellableActions: Middleware = (store) => (next) => (action) => { } case 'locators/changeLocatorAttributes': case 'locators/changeLocatorElement/fulfilled': { - const { element_id } = payload; - pushNotificationHandler(selectLocatorById(prevState, element_id)); + const { elementId } = payload; + pushNotificationHandler(selectLocatorById(prevState, elementId)); break; } case 'locators/toggleDeleted': diff --git a/src/common/components/notification/utils/useNotificationController.ts b/src/common/components/notification/utils/useNotificationController.ts index 82af87f7..3b041c79 100644 --- a/src/common/components/notification/utils/useNotificationController.ts +++ b/src/common/components/notification/utils/useNotificationController.ts @@ -47,7 +47,7 @@ export const useNotificationController = ( openNotification( _prevValueLocator.deleted ? messages().RESTORE : messages().DELETE, _prevValueLocator.deleted ? 'success' : 'warning', - locatorUndo({ type: action?.type, payload: _prevValueLocator.element_id }), + locatorUndo({ type: action?.type, payload: _prevValueLocator.elementId }), ); break; case 'locators/toggleDeletedGroup': diff --git a/src/features/locators/Locator.tsx b/src/features/locators/Locator.tsx index 8ffebde4..5d26f270 100644 --- a/src/features/locators/Locator.tsx +++ b/src/features/locators/Locator.tsx @@ -56,7 +56,7 @@ export const Locator: FC = ({ element, currentPage, searchState, depth, s const [isEditModalOpen, setIsEditModalOpen] = useState(false); const { - element_id, + elementId, type, name, locatorValue, @@ -93,8 +93,8 @@ export const Locator: FC = ({ element, currentPage, searchState, depth, s } }, [isChecked]); - const indeterminate = useSelector((state: RootState) => isLocatorIndeterminate(state, element_id)); - const allChildrenChecked = useSelector((state: RootState) => areChildrenChecked(state, element_id)); + const indeterminate = useSelector((state: RootState) => isLocatorIndeterminate(state, elementId)); + const allChildrenChecked = useSelector((state: RootState) => areChildrenChecked(state, elementId)); const scriptMessage = useSelector((_state: RootState) => _state.main.scriptMessage); const calculatedActive: ILocator[] = useSelector(selectCalculatedActiveByPageObj); const waitingActive = useSelector(selectWaitingActiveByPageObj); @@ -112,7 +112,7 @@ export const Locator: FC = ({ element, currentPage, searchState, depth, s switch (message) { case ScriptMsg.OpenEditLocator: - if (param?.value.element_id !== element_id) return; + if (param?.value.elementId !== elementId) return; setIsEditModalOpen(true); dispatch(setScriptMessage({})); break; @@ -130,8 +130,8 @@ export const Locator: FC = ({ element, currentPage, searchState, depth, s const isVividusFramework = framework === FrameworkType.Vividus; const handleOnChange: React.MouseEventHandler = () => { - dispatch(toggleLocatorIsChecked(element_id)); - dispatch(toggleElementGeneration(element_id)); // ToDo isGenerated refactoring + dispatch(toggleLocatorIsChecked(elementId)); + dispatch(toggleElementGeneration(elementId)); // ToDo isGenerated refactoring if (allChildrenChecked && size(element.children)) { dispatch(setChildrenIsChecked({ locator: element, isChecked: false })); dispatch(setChildrenGeneration({ locator: element, isGenerated: false })); // ToDo isGenerated refactoring @@ -144,7 +144,7 @@ export const Locator: FC = ({ element, currentPage, searchState, depth, s const handleLocatorClick: React.MouseEventHandler = (event) => { const keyForMultiSelect = isMacPlatform(window) ? event.metaKey : event.ctrlKey; if (keyForMultiSelect) { - if (active) dispatch(elementUnsetActive(element_id)); + if (active) dispatch(elementUnsetActive(elementId)); else dispatch(elementSetActive(element)); } else { if (!active) dispatch(setActiveSingle(element)); diff --git a/src/features/locators/components/LocatorEditDialog.tsx b/src/features/locators/components/LocatorEditDialog.tsx index 6bbf4c0a..0b8a3860 100644 --- a/src/features/locators/components/LocatorEditDialog.tsx +++ b/src/features/locators/components/LocatorEditDialog.tsx @@ -18,21 +18,21 @@ import { LocatorValidationErrorType, LocatorValidationWarnings, } from '../types/locator.types'; - -import { changeLocatorAttributes } from '../locators.slice'; import { createNewName, getLocatorValidationStatus, getLocatorValueOnTypeSwitch } from '../utils/utils'; import { createLocatorValidationRules } from '../utils/locatorValidationRules'; import { createNameValidationRules } from '../utils/nameValidationRules'; import { AnnotationType, FrameworkType, LocatorType, SelectOption } from '../../../common/types/common'; import { isFilteredSelect } from '../../../common/utils/helpers'; import { CALCULATING, newLocatorStub } from '../utils/constants'; -import { changeLocatorElement } from '../reducers/changeLocatorElement.thunk'; import { addCustomLocator } from '../reducers/addCustomLocator.thunk'; import { selectPresentLocatorsByPO } from '../selectors/locatorsByPO.selectors'; import { LocatorMessageForDuplicate } from './LocatorMessageForDuplicate'; import { createLocatorTypeOptions, ILocatorTypeOptions } from '../utils/createLocatorTypeOptions'; import { validateLocator } from '../utils/locatorValidation'; import { annotationTypeOptions } from './utils'; +import { changeLocatorElement } from '../reducers/changeLocatorElement.thunk'; +import { changeLocatorAttributes } from '../locators.slice'; +import { selectNotShownElementIds } from '../../../services/pageDocument/pageDocument.selectors'; interface Props extends ILocator { isModalOpen: boolean; @@ -52,7 +52,7 @@ export const LocatorEditDialog: React.FC = ({ isModalOpen, setIsModalOpen, isCreatingForm = false, - element_id, + elementId, isCustomName = true, name, type, @@ -95,7 +95,7 @@ export const LocatorEditDialog: React.FC = ({ const [isOkButtonDisabled, setIsOkButtonDisabled] = useState(true); // ToDo: fix legacy: // eslint-disable-next-line @typescript-eslint/naming-convention - const _isNameUnique = (value: string) => !isNameUnique(locators, element_id, value); + const _isNameUnique = (value: string) => !isNameUnique(locators, elementId, value); const nameValidationRules: Rule[] = createNameValidationRules(_isNameUnique); @@ -103,6 +103,8 @@ export const LocatorEditDialog: React.FC = ({ form.resetFields(); setIsModalOpen(false); }; + + const notShownElementIds = useSelector(selectNotShownElementIds); const getLocatorValidationRules: () => Rule[] = () => createLocatorValidationRules( isCreatingForm, @@ -111,7 +113,8 @@ export const LocatorEditDialog: React.FC = ({ setValidationErrorOptions, locators, jdnHash, - element_id, + elementId, + notShownElementIds, ); const [locatorValidationRules, setLocatorValidationRules] = useState(getLocatorValidationRules()); @@ -119,7 +122,7 @@ export const LocatorEditDialog: React.FC = ({ if (isEditedName) return; const newName = createNewName( - { element_id, isCustomName, type, name, elemId, elemName, elemText } as ILocator, + { elementId, isCustomName, type, name, elemId, elemName, elemText } as ILocator, value, library, locators, @@ -177,7 +180,7 @@ export const LocatorEditDialog: React.FC = ({ locatorValue, annotationType, locatorType, - element_id, + elementId, library, message: validationMessage, isCustomName: isEditedName, @@ -229,7 +232,7 @@ export const LocatorEditDialog: React.FC = ({ const newLocatorValue = await getLocatorValueOnTypeSwitch( newLocatorType, validationMessage, - element_id, + elementId, jdnHash, locatorValue, form, @@ -276,7 +279,7 @@ export const LocatorEditDialog: React.FC = ({ } else { setLocatorTypeOptions(staticLocatorTypeOptions); } - }, [locatorValue, locators, element_id]); + }, [locatorValue, locators, elementId]); const handleLocatorDropdownOnChange = async () => { setValidationMessage(''); @@ -290,7 +293,8 @@ export const LocatorEditDialog: React.FC = ({ locatorTypeFromForm, jdnHash, locators, - element_id, + elementId, + notShownElementIds, isCreatingForm, ); diff --git a/src/features/locators/components/LocatorMenu.tsx b/src/features/locators/components/LocatorMenu.tsx index 10ae9154..9fea95cd 100644 --- a/src/features/locators/components/LocatorMenu.tsx +++ b/src/features/locators/components/LocatorMenu.tsx @@ -95,11 +95,11 @@ export const LocatorMenu: React.FC = ({ setIsEditModalOpen, children, tri const handleDelete = () => actualSelected.length > 1 ? dispatch(toggleDeletedGroup(actualSelected)) - : dispatch(toggleDeleted(actualSelected[0].element_id)); + : dispatch(toggleDeleted(actualSelected[0].elementId)); const handleUpPriority = () => { const hashes = [...decreasedPrioritySelected, ...noPrioritySelected].map((element) => element.jdnHash); - const ids = [...decreasedPrioritySelected, ...noPrioritySelected].map((element) => element.element_id); + const ids = [...decreasedPrioritySelected, ...noPrioritySelected].map((element) => element.elementId); dispatch( setCalculationPriority({ ids, @@ -111,7 +111,7 @@ export const LocatorMenu: React.FC = ({ setIsEditModalOpen, children, tri const handleDownPriority = () => { const hashes = [...increasedPrioritySelected, ...noPrioritySelected].map((element) => element.jdnHash); - const ids = [...increasedPrioritySelected, ...noPrioritySelected].map((element) => element.element_id); + const ids = [...increasedPrioritySelected, ...noPrioritySelected].map((element) => element.elementId); dispatch( setCalculationPriority({ ids, @@ -124,13 +124,13 @@ export const LocatorMenu: React.FC = ({ setIsEditModalOpen, children, tri const handlePause = () => { inProgressSelected.length > 1 ? dispatch(stopGenerationGroup(inProgressSelected)) - : dispatch(stopGeneration(inProgressSelected[0].element_id)); + : dispatch(stopGeneration(inProgressSelected[0].elementId)); }; const handleRestore = () => deletedActive.length > 1 ? dispatch(toggleDeletedGroup(deletedActive)) - : dispatch(toggleDeleted(deletedActive[0].element_id)); + : dispatch(toggleDeleted(deletedActive[0].elementId)); const handleMenuClick = ({ domEvent }: { domEvent: SyntheticEvent }) => { domEvent.stopPropagation(); diff --git a/src/features/locators/components/LocatorMessageForDuplicate.tsx b/src/features/locators/components/LocatorMessageForDuplicate.tsx index 4989bf40..9daf90c8 100644 --- a/src/features/locators/components/LocatorMessageForDuplicate.tsx +++ b/src/features/locators/components/LocatorMessageForDuplicate.tsx @@ -19,7 +19,7 @@ export const LocatorMessageForDuplicate: React.FC = ({ locatorIds, viewProps const createLocatorsMap = () => { const map: Record = {}; for (let index = 0; index < locators.length; index++) { - map[locators[index].element_id] = locators[index]; + map[locators[index].elementId] = locators[index]; } return map; }; @@ -118,8 +117,8 @@ export const LocatorsTree: React.FC = ({ locatorIds, viewProps const createTree = (_data: LocatorTree[]): TreeNode[] => { const childNodes: TreeNode[] = []; _data.forEach((element, index) => { - const { element_id, children, parent_id, jdnHash, searchState, depth } = element; - const locator = locatorsMap[element_id]; + const { elementId, children, parent_id, jdnHash, searchState, depth } = element; + const locator = locatorsMap[elementId]; const locatorTaskStatus = getTaskStatus( locator.locatorValue.xPathStatus, locator.locatorValue.cssSelectorStatus, @@ -135,7 +134,7 @@ export const LocatorsTree: React.FC = ({ locatorIds, viewProps }); const node: TreeNode = { - key: element_id, + key: elementId, className, title: ( ) { - // ToDo: fix legacy naming - // eslint-disable-next-line @typescript-eslint/naming-convention - const { locatorValue, element_id, locatorType, ...rest } = payload; + const { locatorValue, elementId, locatorType, ...rest } = payload; - const currentLocator = simpleSelectLocatorById(state, element_id); + const currentLocator = simpleSelectLocatorById(state, elementId); if (!currentLocator) return; @@ -118,31 +116,31 @@ const locatorsSlice = createSlice({ { payload }: PayloadAction, ) { const locators = Array.isArray(payload) ? payload : payload.locators; - locatorsAdapter.upsertMany(state, locators.map(({ element_id }) => ({ element_id, active: true })) as ILocator[]); + locatorsAdapter.upsertMany(state, locators.map(({ elementId }) => ({ elementId, active: true })) as ILocator[]); }, elementGroupUnsetActive( state, { payload }: PayloadAction, ) { const locators = Array.isArray(payload) ? payload : payload.locators; - const newValue = locators.map(({ element_id }) => ({ element_id, active: false })); + const newValue = locators.map(({ elementId }) => ({ elementId, active: false })); locatorsAdapter.upsertMany(state, newValue as ILocator[]); }, elementSetActive(state, { payload }: PayloadAction) { - locatorsAdapter.upsertOne(state, { element_id: payload.element_id, active: true } as ILocator); + locatorsAdapter.upsertOne(state, { elementId: payload.elementId, active: true } as ILocator); }, elementUnsetActive(state, { payload }: PayloadAction) { - locatorsAdapter.upsertOne(state, { element_id: payload, active: false } as ILocator); + locatorsAdapter.upsertOne(state, { elementId: payload, active: false } as ILocator); }, failGeneration(state, { payload }: PayloadAction<{ ids: string[]; errorMessage?: string }>) { const { ids, errorMessage } = payload; console.error('NETWORK ERROR: ', errorMessage); if (errorMessage === NETWORK_ERROR) state.generationStatus = LocatorsGenerationStatus.failed; - const newValues = ids.map((element_id) => { - const existingLocator = simpleSelectLocatorById(state, element_id); + const newValues = ids.map((elementId) => { + const existingLocator = simpleSelectLocatorById(state, elementId); if (existingLocator) { return { - element_id, + elementId, locatorValue: { ...existingLocator.locatorValue, xPathStatus: LocatorTaskStatus.FAILURE, @@ -165,22 +163,20 @@ const locatorsSlice = createSlice({ }, setActiveSingle(state, { payload: locator }: PayloadAction) { const newValue = simpleSelectLocatorsByPageObject(state, locator.pageObj).map((_loc) => - _loc.element_id === locator.element_id ? { ..._loc, active: true } : { ..._loc, active: false }, + _loc.elementId === locator.elementId ? { ..._loc, active: true } : { ..._loc, active: false }, ); locatorsAdapter.upsertMany(state, newValue); }, setCalculationPriority( state, - { payload }: PayloadAction<{ element_id?: ElementId; priority: LocatorCalculationPriority; ids?: ElementId[] }>, + { payload }: PayloadAction<{ elementId?: ElementId; priority: LocatorCalculationPriority; ids?: ElementId[] }>, ) { - // ToDo: fix legacy naming - // eslint-disable-next-line @typescript-eslint/naming-convention - const { element_id, ids, priority } = payload; - if (element_id) locatorsAdapter.upsertOne(state, { element_id, priority } as ILocator); + const { elementId, ids, priority } = payload; + if (elementId) locatorsAdapter.upsertOne(state, { elementId, priority } as ILocator); if (ids) { - // ToDo: fix legacy naming - // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-shadow - const newValue: Partial[] = ids.map((element_id) => ({ element_id, priority })); + // TODO: fix legacy naming + // eslint-disable-next-line @typescript-eslint/no-shadow + const newValue: Partial[] = ids.map((elementId) => ({ elementId, priority })); locatorsAdapter.upsertMany(state, newValue as ILocator[]); } }, @@ -191,7 +187,7 @@ const locatorsSlice = createSlice({ const toggleGenerate = (_locator: ILocator) => { if (_locator.children) _locator.children.forEach((childId) => { - newValue.push({ element_id: childId, isGenerated }); + newValue.push({ elementId: childId, isGenerated }); const child = simpleSelectLocatorById(state, childId); if (child && size(child.children)) toggleGenerate(child); }); @@ -205,7 +201,7 @@ const locatorsSlice = createSlice({ const toggleIsChecked = (_locator: ILocator) => { if (_locator.children) _locator.children.forEach((childId) => { - newValue.push({ element_id: childId, isChecked }); + newValue.push({ elementId: childId, isChecked }); const child = simpleSelectLocatorById(state, childId); if (child && size(child.children)) toggleIsChecked(child); }); @@ -215,18 +211,16 @@ const locatorsSlice = createSlice({ }, setElementGroupGeneration(state, { payload }: PayloadAction<{ locators: ILocator[]; isGenerated: boolean }>) { const { locators, isGenerated } = payload; - locatorsAdapter.upsertMany(state, locators.map(({ element_id }) => ({ element_id, isGenerated })) as ILocator[]); + locatorsAdapter.upsertMany(state, locators.map(({ elementId }) => ({ elementId, isGenerated })) as ILocator[]); }, - setJdnHash(state, { payload }: PayloadAction<{ element_id: ElementId; jdnHash: string }>) { - // ToDo: fix legacy naming - // eslint-disable-next-line @typescript-eslint/naming-convention - const { element_id, jdnHash } = payload; - locatorsAdapter.upsertOne(state, { element_id, jdnHash } as ILocator); + setJdnHash(state, { payload }: PayloadAction<{ elementId: ElementId; jdnHash: string }>) { + const { elementId, jdnHash } = payload; + locatorsAdapter.upsertOne(state, { elementId, jdnHash } as ILocator); }, - setScrollToLocator(state, { payload: element_id }: PayloadAction) { - state.scrollToLocator = element_id; + setScrollToLocator(state, { payload: elementId }: PayloadAction) { + state.scrollToLocator = elementId; }, - setValidity(state, { payload }: PayloadAction<{ element_id: ElementId; message: ILocator['message'] }>) { + setValidity(state, { payload }: PayloadAction<{ elementId: ElementId; message: ILocator['message'] }>) { locatorsAdapter.upsertOne(state, payload as ILocator); }, toggleDeleted(state, { payload }: PayloadAction) { @@ -241,9 +235,9 @@ const locatorsSlice = createSlice({ }, toggleDeletedGroup(state, { payload }: PayloadAction) { const newValue: Partial[] = []; - payload.forEach(({ element_id, deleted, isGenerated }) => { + payload.forEach(({ elementId, deleted, isGenerated }) => { // when we delete locator, we uncheck it, when restore - keep isGenerated state as is - newValue.push({ element_id, deleted: !deleted, isGenerated: !deleted ? false : isGenerated }); + newValue.push({ elementId, deleted: !deleted, isGenerated: !deleted ? false : isGenerated }); }); locatorsAdapter.upsertMany(state, newValue as ILocator[]); }, @@ -251,34 +245,31 @@ const locatorsSlice = createSlice({ // ToDo isGenerated refactoring const locator = typeof payload === 'string' ? simpleSelectLocatorById(state, payload) : payload; if (!locator) return; - // ToDo: fix legacy naming - // eslint-disable-next-line @typescript-eslint/naming-convention - const { isGenerated, element_id } = locator; - locatorsAdapter.upsertOne(state, { element_id, isGenerated: !isGenerated } as ILocator); + const { isGenerated, elementId } = locator; + locatorsAdapter.upsertOne(state, { elementId, isGenerated: !isGenerated } as ILocator); }, toggleLocatorIsChecked(state, { payload }: PayloadAction) { const locator = simpleSelectLocatorById(state, payload); if (!locator) return; - // ToDo: fix legacy naming - // eslint-disable-next-line @typescript-eslint/naming-convention - const { isChecked, element_id } = locator; - locatorsAdapter.upsertOne(state, { element_id, isChecked: !isChecked } as ILocator); + + const { isChecked, elementId } = locator; + locatorsAdapter.upsertOne(state, { elementId, isChecked: !isChecked } as ILocator); }, toggleAllLocatorsIsChecked(state, { payload }: PayloadAction<{ locators: ILocator[]; isChecked: boolean }>) { const { locators, isChecked } = payload; - locatorsAdapter.upsertMany(state, locators.map(({ element_id }) => ({ element_id, isChecked })) as ILocator[]); + locatorsAdapter.upsertMany(state, locators.map(({ elementId }) => ({ elementId, isChecked })) as ILocator[]); }, toggleElementGroupIsChecked(state, { payload }: PayloadAction) { const newValue: Partial[] = []; - payload.forEach(({ element_id, isChecked }) => { - newValue.push({ element_id, isChecked: !isChecked }); + payload.forEach(({ elementId, isChecked }) => { + newValue.push({ elementId, isChecked: !isChecked }); }); locatorsAdapter.upsertMany(state, newValue as ILocator[]); }, toggleElementGroupGeneration(state, { payload }: PayloadAction) { const newValue: Partial[] = []; - payload.forEach(({ element_id, isGenerated }) => { - newValue.push({ element_id, isGenerated: !isGenerated }); + payload.forEach(({ elementId, isGenerated }) => { + newValue.push({ elementId, isGenerated: !isGenerated }); }); locatorsAdapter.upsertMany(state, newValue as ILocator[]); }, @@ -292,13 +283,13 @@ const locatorsSlice = createSlice({ }>, ) { const { locators, pageObject } = payload; - const newValue = locators.map(({ element_id, jdnHash, locatorValue }) => { - const existingLocator = element_id - ? simpleSelectLocatorById(state, element_id) + const newValue = locators.map(({ elementId, jdnHash, locatorValue }) => { + const existingLocator = elementId + ? simpleSelectLocatorById(state, elementId) : simpleSelectLocatorByJdnHash(state, jdnHash, pageObject); return ( existingLocator && { - element_id: existingLocator.element_id, + elementId: existingLocator.elementId, locatorValue: { ...existingLocator.locatorValue, ...locatorValue }, } ); diff --git a/src/features/locators/reducers/addCustomLocator.thunk.ts b/src/features/locators/reducers/addCustomLocator.thunk.ts index d61ea0f6..b494d618 100644 --- a/src/features/locators/reducers/addCustomLocator.thunk.ts +++ b/src/features/locators/reducers/addCustomLocator.thunk.ts @@ -29,22 +29,21 @@ export const addCustomLocator = createAsyncThunk( let foundElementText; let originalCssSelector = ''; let fullXpath = ''; - // ToDo: fix legacy naming - // eslint-disable-next-line @typescript-eslint/naming-convention - const element_id = `${generateId()}_${pageObjectId}`; + + const elementId = `${generateId()}_${pageObjectId}`; if (getLocatorValidationStatus(message) === ValidationStatus.SUCCESS) { try { if ((isXPathLocator && locatorValue.xPath) || (isStandardLocator && locatorFormValue)) { const locatorData = await (isXPathLocator && locatorValue.xPath - ? evaluateXpath(locatorValue.xPath, element_id) - : evaluateLocator(locatorFormValue, locatorType, element_id)); + ? evaluateXpath(locatorValue.xPath, elementId) + : evaluateLocator(locatorFormValue, locatorType, elementId)); ({ foundHash, foundElementText } = JSON.parse(locatorData)); } if (!foundHash) { - foundHash = element_id.split('_')[0]; + foundHash = elementId.split('_')[0]; await sendMessage .assignJdnHash({ jdnHash: foundHash, @@ -74,7 +73,7 @@ export const addCustomLocator = createAsyncThunk( const newLocator: ILocator = { ...newLocatorData, - element_id, + elementId, locatorValue: { ...newLocatorData.locatorValue, ...(isStandardLocator ? { xPath: fullXpath } : { cssSelector: originalCssSelector }), @@ -85,9 +84,9 @@ export const addCustomLocator = createAsyncThunk( const dispatch = thunkAPI.dispatch; dispatch(addLocators([newLocator])); - dispatch(addLocatorToPageObj({ pageObjId: pageObjectId, locatorId: newLocator.element_id })); + dispatch(addLocatorToPageObj({ pageObjId: pageObjectId, locatorId: newLocator.elementId })); dispatch(setActiveSingle(newLocator)); - dispatch(setScrollToLocator(newLocator.element_id)); + dispatch(setScrollToLocator(newLocator.elementId)); return newLocator; }, diff --git a/src/features/locators/reducers/changeLocatorElement.thunk.ts b/src/features/locators/reducers/changeLocatorElement.thunk.ts index 9bcf207c..eedbfb9b 100644 --- a/src/features/locators/reducers/changeLocatorElement.thunk.ts +++ b/src/features/locators/reducers/changeLocatorElement.thunk.ts @@ -13,12 +13,10 @@ type ChangeLocatorElementPayload = ChangeLocatorAttributesPayload; export const changeLocatorElement = createAsyncThunk( 'locators/changeLocatorElement', async (payload: ChangeLocatorElementPayload, thunkAPI) => { - // ToDo: fix legacy naming - // eslint-disable-next-line @typescript-eslint/naming-convention - const { locatorValue, element_id, locatorType, ...rest } = payload; + const { locatorValue, elementId, locatorType, ...rest } = payload; const state = thunkAPI.getState() as RootState; - const currentLocator = selectLocatorById(state, element_id); + const currentLocator = selectLocatorById(state, elementId); if (!currentLocator) return; @@ -38,7 +36,11 @@ export const changeLocatorElement = createAsyncThunk( let foundHash, foundElementText, originalCssSelector, fullXpath; - ({ foundHash, foundElementText } = JSON.parse(await await evaluateLocator(locatorValue, locatorType, element_id))); + try { + ({ foundHash, foundElementText } = JSON.parse(await evaluateLocator(locatorValue, locatorType, elementId))); + } catch (error) { + console.error('change locator element error: ', error); + } if (!foundHash) { foundHash = generateId(); diff --git a/src/features/locators/reducers/checkLocatorValidity.thunk.ts b/src/features/locators/reducers/checkLocatorValidity.thunk.ts index 393a11bb..5fbd09a8 100644 --- a/src/features/locators/reducers/checkLocatorValidity.thunk.ts +++ b/src/features/locators/reducers/checkLocatorValidity.thunk.ts @@ -1,10 +1,12 @@ -import { ActionReducerMapBuilder, createAsyncThunk } from '@reduxjs/toolkit'; +import { type ActionReducerMapBuilder, createAsyncThunk } from '@reduxjs/toolkit'; import { RootState } from '../../../app/store/store'; import { locatorsAdapter } from '../selectors/locators.selectors'; import { ILocator, LocatorsState, LocatorValidationErrorType } from '../types/locator.types'; import { validateLocator } from '../utils/locatorValidation'; import { LocatorType } from '../../../common/types/common'; import { selectLocatorsByPageObject } from '../selectors/locatorsByPO.selectors'; +import { useSelector } from 'react-redux'; +import { selectNotShownElementIds } from '../../../services/pageDocument/pageDocument.selectors'; export const checkLocatorsValidity = createAsyncThunk('locators/checkLocatorsValidity', async (payload, thunkAPI) => { const state = thunkAPI.getState(); @@ -12,21 +14,23 @@ export const checkLocatorsValidity = createAsyncThunk('locators/checkLocatorsVal const locators: ILocator[] = selectLocatorsByPageObject(state as RootState); const invalidLocators: Partial[] = []; + const notShownElementIds = useSelector(selectNotShownElementIds); for (const locator of locators) { - const { jdnHash, element_id, locatorValue, locatorType } = locator; + const { jdnHash, elementId, locatorValue, locatorType } = locator; try { const validation = await validateLocator( locatorValue.output ?? '', locatorType || LocatorType.xPath, jdnHash, locators, - element_id, + elementId, + notShownElementIds, ); if (validation.length) - invalidLocators.push({ element_id, message: validation as LocatorValidationErrorType, jdnHash }); + invalidLocators.push({ elementId, message: validation as LocatorValidationErrorType, jdnHash }); } catch (error) { - invalidLocators.push({ element_id, message: error.message as LocatorValidationErrorType, jdnHash }); + invalidLocators.push({ elementId, message: error.message as LocatorValidationErrorType, jdnHash }); } } diff --git a/src/features/locators/reducers/createLocators.thunk.ts b/src/features/locators/reducers/createLocators.thunk.ts index b1706f75..3d36b259 100644 --- a/src/features/locators/reducers/createLocators.thunk.ts +++ b/src/features/locators/reducers/createLocators.thunk.ts @@ -24,7 +24,7 @@ export const createLocators = createAsyncThunk('locators/createLocators', async const locators = await createLocatorAttributes(predictedElements, library, isAutogenerated); thunkAPI.dispatch(addLocators(locators)); - const ids = locators.map(({ element_id }) => element_id); + const ids = locators.map(({ elementId }) => elementId); thunkAPI.dispatch(addLocatorsToPageObj(ids)); return locators; diff --git a/src/features/locators/reducers/identifyElements.thunk.ts b/src/features/locators/reducers/identifyElements.thunk.ts index c358d632..d7193ada 100644 --- a/src/features/locators/reducers/identifyElements.thunk.ts +++ b/src/features/locators/reducers/identifyElements.thunk.ts @@ -56,8 +56,8 @@ export const identifyElements = createAsyncThunk('locators/identifyElements', as .map((el: PredictedEntity) => { return { ...el, - element_id: `${el.element_id}_${pageObj}`, - jdnHash: el.element_id, + elementId: `${el.elementId}_${pageObj}`, + jdnHash: el.elementId, pageObj: pageObj, }; }); @@ -103,7 +103,6 @@ export const onLocatorsCreated: Middleware = (store) => (next) => (action) => { const { generateXpath, generateCssSelector } = selectAutoGeneratingLocatorTypes(state as RootState); // generateCssSelector: false because it's run with attributes generation for performance reasons // ToDo: take generateCssSelector from selectAutoGeneratingLocatorTypes, when backend will be ready - // console.log('generateCssSelector: ', generateCssSelector); // LOG // @ts-ignore store.dispatch(runLocatorsGeneration({ locators, generateXpath, generateCssSelector })); } diff --git a/src/features/locators/reducers/runLocatorsGeneration.thunk.ts b/src/features/locators/reducers/runLocatorsGeneration.thunk.ts index c30932b5..fd48d490 100644 --- a/src/features/locators/reducers/runLocatorsGeneration.thunk.ts +++ b/src/features/locators/reducers/runLocatorsGeneration.thunk.ts @@ -86,8 +86,8 @@ export const runLocatorsGeneration = createAsyncThunk( const taskStatus = getTaskStatus(locator.locatorValue.xPathStatus, locator.locatorValue.cssSelectorStatus); return locator.locatorValue && taskStatus !== LocatorTaskStatus.PENDING; }) - .map(({ element_id, jdnHash }) => ({ - element_id, + .map(({ elementId, jdnHash }) => ({ + elementId, locatorValue: { xPathStatus: LocatorTaskStatus.PENDING }, jdnHash, })); @@ -97,8 +97,8 @@ export const runLocatorsGeneration = createAsyncThunk( const taskStatus = getTaskStatus(locator.locatorValue.xPathStatus, locator.locatorValue.cssSelectorStatus); return locator.locatorValue && taskStatus !== LocatorTaskStatus.PENDING; }) - .map(({ element_id, jdnHash }) => ({ - element_id, + .map(({ elementId, jdnHash }) => ({ + elementId, locatorValue: { cssSelectorStatus: LocatorTaskStatus.PENDING }, jdnHash, })); diff --git a/src/features/locators/reducers/stopGeneration.thunk.ts b/src/features/locators/reducers/stopGeneration.thunk.ts index 2324e6f1..32fe2adb 100644 --- a/src/features/locators/reducers/stopGeneration.thunk.ts +++ b/src/features/locators/reducers/stopGeneration.thunk.ts @@ -5,9 +5,9 @@ import { locatorsAdapter, selectLocatorById, simpleSelectLocatorById } from '../ import { ElementId, ILocator, LocatorsState, LocatorTaskStatus } from '../types/locator.types'; import { locatorGenerationController } from '../utils/LocatorGenerationController'; -export const stopGeneration = createAsyncThunk('locators/stopGeneration', async (element_id: ElementId, thunkAPI) => { +export const stopGeneration = createAsyncThunk('locators/stopGeneration', async (elementId: ElementId, thunkAPI) => { const state = thunkAPI.getState() as RootState; - const jdnHash = selectLocatorById(state, element_id)?.jdnHash; + const jdnHash = selectLocatorById(state, elementId)?.jdnHash; if (!jdnHash) return; return locatorGenerationController.revokeTasks([jdnHash]); }); @@ -23,7 +23,7 @@ export const stopGenerationReducer = (builder: ActionReducerMapBuilder) => { return builder .addCase(stopGenerationGroup.pending, (state, { meta }) => { - const newValue = meta.arg.map(({ element_id, locatorValue }) => { + const newValue = meta.arg.map(({ elementId, locatorValue }) => { return { - element_id, + elementId, locatorValue: { ...locatorValue, xPathStatus: LocatorTaskStatus.REVOKED, diff --git a/src/features/locators/selectors/locators.selectors.ts b/src/features/locators/selectors/locators.selectors.ts index d9e7a5d0..42d1c6f9 100644 --- a/src/features/locators/selectors/locators.selectors.ts +++ b/src/features/locators/selectors/locators.selectors.ts @@ -6,7 +6,7 @@ import { getLocator } from '../utils/locatorOutput'; import { selectCurrentPageObject } from '../../pageObjects/selectors/pageObjects.selectors'; export const locatorsAdapter = createEntityAdapter({ - selectId: (locator) => locator.element_id, + selectId: (locator) => locator.elementId, }); const { selectAll, selectById } = locatorsAdapter.getSelectors((state) => state.locators.present); @@ -50,7 +50,7 @@ export const isLocatorIndeterminate = createSelector( const hasChildToGenerate = (_locator: ILocator) => { const hasSelectedChild = _locator.children && - _locator.children.some((childId) => locators.some((loc) => loc.element_id === childId && loc.isGenerated)); + _locator.children.some((childId) => locators.some((loc) => loc.elementId === childId && loc.isGenerated)); return ( hasSelectedChild || (_locator.children && @@ -71,14 +71,14 @@ export const areChildrenChecked = createSelector( (locators, locator) => locator && Boolean(locator.children?.length) && - locator.children?.every((childId) => locators.some((loc) => loc.element_id === childId && loc.isGenerated)), + locator.children?.every((childId) => locators.some((loc) => loc.elementId === childId && loc.isGenerated)), ); export const selectLocatorByJdnHash = createSelector( (state: RootState, jdnHash: string) => selectLocators(state).filter((loc) => loc.jdnHash === jdnHash), (state: RootState) => selectCurrentPageObject(state)?.locators, (locators, pageObjLocators) => { - return locators.find(({ element_id }) => pageObjLocators?.includes(element_id)); + return locators.find(({ elementId }) => pageObjLocators?.includes(elementId)); }, ); @@ -101,6 +101,6 @@ export const simpleSelectLocatorByJdnHash = createDraftSafeSelector( simpleSelectLocators(state).filter((loc) => loc.jdnHash === jdnHash), (_state: EntityState, _: string, pageObject: PageObject) => pageObject.locators, (locators, pageObjLocators) => { - return locators.find(({ element_id }) => pageObjLocators?.includes(element_id)); + return locators.find(({ elementId }) => pageObjLocators?.includes(elementId)); }, ); diff --git a/src/features/locators/selectors/locatorsByPO.selectors.ts b/src/features/locators/selectors/locatorsByPO.selectors.ts index 5240162d..e5369bb7 100644 --- a/src/features/locators/selectors/locatorsByPO.selectors.ts +++ b/src/features/locators/selectors/locatorsByPO.selectors.ts @@ -34,7 +34,7 @@ export const selectPresentLocatorsByPO = createSelector( (locators, pageObject) => { const locByPageObj = pageObject?.locators || []; return locators - .filter((locator) => locByPageObj.includes(locator.element_id)) + .filter((locator) => locByPageObj.includes(locator.elementId)) .map((locator) => { const annotationType = locator.annotationType || pageObject?.annotationType; const locatorType = locator.locatorType || pageObject?.locatorType || LocatorType.xPath; diff --git a/src/features/locators/types/locator.types.ts b/src/features/locators/types/locator.types.ts index c0604b2a..06e2a2e4 100644 --- a/src/features/locators/types/locator.types.ts +++ b/src/features/locators/types/locator.types.ts @@ -109,13 +109,13 @@ export interface ILocator extends PredictedEntity { } export interface PredictedEntity { - element_id: ElementId; + elementId: ElementId; predicted_label: string; is_shown: boolean; } export interface IPartialLocatorDataForUpdate { - element_id?: ElementId; + elementId?: ElementId; jdnHash: JDNHash; locatorValue: Partial; } diff --git a/src/features/locators/utils/LocatorGenerationController.ts b/src/features/locators/utils/LocatorGenerationController.ts index 218a4612..4de5f3b9 100644 --- a/src/features/locators/utils/LocatorGenerationController.ts +++ b/src/features/locators/utils/LocatorGenerationController.ts @@ -4,6 +4,7 @@ import { webSocketController } from '../../../services/webSocketController'; import { MainState, MaxGenerationTime } from '../../../app/types/mainSlice.types'; import { PageObject } from '../../pageObjects/types/pageObjectSlice.types'; import { GeneralLocatorType } from '../../../common/types/common'; +import { getWebSocketMessages } from './helpers'; export interface IGeneralWebSocketMessage { action: WebSocketMessage; @@ -44,6 +45,7 @@ class LocatorGenerationController { pageDocument: string, pageObject?: PageObject, maxGenerationTime?: MaxGenerationTime, + isLocalServer?: boolean, ) { if (pageObject) this.pageObject = pageObject; this.pageDocument = pageDocument; @@ -75,24 +77,34 @@ class LocatorGenerationController { action: WebSocketMessage.SCHEDULE_MULTIPLE_CSS_SELECTOR_GENERATIONS, payload: { document: this.pageDocument, - // TODO: uncomment when back-end will be ready (issues/1284) 80 line - // id: hashes, - id: [], + // TODO: remove condition ("isLocalServer ?", ": []") when back-end will be ready (issues/1284) + id: isLocalServer ? hashes : [], }, }; - // TODO: uncomment when back-end will be ready (issues/1284) 85-94 line - // const messages = getWebSocketMessages(locatorType, this.xPathGenerationMessage, this.CssSelectorGenerationMessage); - return ( - webSocketController - // .sendSocket(JSON.stringify(messages[0])) - .sendSocket(JSON.stringify(this.xPathGenerationMessage)) - // .then(() => { - // webSocketController.sendSocket(JSON.stringify(messages[1])); - // }) - .then(() => { - webSocketController.startPing(); - }) - ); + + 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); + }); + + return webSocketOperation; } upPriority(ids: JDNHash[]) { @@ -100,7 +112,7 @@ class LocatorGenerationController { webSocketController.sendSocket( JSON.stringify({ action: WebSocketMessage.UP_PRIORITY, - payload: { element_id: id }, + payload: { elementId: id }, }), ); }); @@ -111,7 +123,7 @@ class LocatorGenerationController { webSocketController.sendSocket( JSON.stringify({ action: WebSocketMessage.DOWN_PRIORITY, - payload: { element_id: id }, + payload: { elementId: id }, }), ); }); diff --git a/src/features/locators/utils/constants.ts b/src/features/locators/utils/constants.ts index 64ed946e..a0d28030 100644 --- a/src/features/locators/utils/constants.ts +++ b/src/features/locators/utils/constants.ts @@ -21,7 +21,7 @@ export const newLocatorStub: ILocator = { elemId: '', elemName: '', elemText: '', - element_id: '', + elementId: '', is_shown: true, jdnHash: '', parent_id: '', diff --git a/src/features/locators/utils/locatorValidation.ts b/src/features/locators/utils/locatorValidation.ts index db5f5c6d..3839454b 100644 --- a/src/features/locators/utils/locatorValidation.ts +++ b/src/features/locators/utils/locatorValidation.ts @@ -16,7 +16,8 @@ export const validateLocator = async ( locatorType: LocatorType, jdnHash: JDNHash, locators: ILocator[], - element_id: ElementId, + elementId: ElementId, + notShownElementIds: string[], isCreatingForm?: boolean, ): Promise => { let length; @@ -25,19 +26,24 @@ export const validateLocator = async ( let validatedJdnHash; let validationMessage: LocatorValidationErrorType = ''; - const locatorValue = await evaluateLocator(locatorString, locatorType, element_id, jdnHash); + const locatorValue = await evaluateLocator(locatorString, locatorType, elementId, jdnHash); if (locatorValue === LocatorValidationWarnings.StartsWithDigit) { validationMessage = LocatorValidationWarnings.StartsWithDigit; } else if (locatorValue === LocatorValidationWarnings.NotFound || !locatorValue) { validationMessage = LocatorValidationWarnings.NotFound; //validationStatus: WARNING } else { ({ length, foundHash } = JSON.parse(locatorValue)); - validatedElementId = JSON.parse(locatorValue).element_id || element_id; + validatedElementId = JSON.parse(locatorValue).elementId || elementId; validatedJdnHash = JSON.parse(locatorValue).originJdnHash || jdnHash; + // TODO: remove hardcode, when for Selenium framework support is added to the project (issue/585) + const isSelenium = false; // hardcode + const duplicateErrorCondition = isSelenium ? length > 1 : length > 1 && !notShownElementIds.includes(foundHash); + if (length === 0) { validationMessage = LocatorValidationWarnings.NotFound; //validationStatus: WARNING - } else if (length > 1) { + } else if (duplicateErrorCondition) { + console.log('throw duplicate error'); const err = `${length} ${LocatorValidationErrors.MultipleElements}` as LocatorValidationErrorType; //validationStatus: ERROR; throw new Error(err); } else if (length === 1 && validatedJdnHash !== foundHash) { diff --git a/src/features/locators/utils/locatorValidationRules.ts b/src/features/locators/utils/locatorValidationRules.ts index 5c305a50..59da7ce0 100644 --- a/src/features/locators/utils/locatorValidationRules.ts +++ b/src/features/locators/utils/locatorValidationRules.ts @@ -1,3 +1,4 @@ +import React from 'react'; import { Rule, RuleObject } from 'antd/lib/form'; import { validateLocator } from './locatorValidation'; import { ElementId, ILocator, LocatorValidationErrorType, LocatorValidationWarnings } from '../types/locator.types'; @@ -10,7 +11,8 @@ export const createLocatorValidationRules = ( setValidationErrorOptions: React.Dispatch>, locators: ILocator[], jdnHash: string, - element_id: ElementId, + elementId: ElementId, + notShownElementIds: string[], ): Rule[] => { return [ { @@ -19,14 +21,14 @@ export const createLocatorValidationRules = ( setValidationMessage(LocatorValidationWarnings.EmptyValue); // validationStatus: WARNING return Promise.resolve(); } - try { const validationMessage = await validateLocator( locatorValue, locatorType, jdnHash, locators, - element_id, + elementId, + notShownElementIds, isCreatingForm, ); setValidationMessage(validationMessage as LocatorValidationErrorType); diff --git a/src/features/locators/utils/locatorsTreeUtils.ts b/src/features/locators/utils/locatorsTreeUtils.ts index 60cb334c..5c8af9f7 100644 --- a/src/features/locators/utils/locatorsTreeUtils.ts +++ b/src/features/locators/utils/locatorsTreeUtils.ts @@ -1,5 +1,5 @@ import { cloneDeep, map as mapFunction, size } from 'lodash'; -import { JDNHash, ILocator } from '../../locators/types/locator.types'; +import { ILocator, JDNHash } from '../types/locator.types'; import { SearchState } from '../components/LocatorsTree'; export interface LocatorTree extends Omit { @@ -21,7 +21,7 @@ export const convertToListWithChildren = (_list: ILocator[]) => { const node = list[i]; if (node.parent_id !== '') { const children = list[map[node.parent_id]]?.children; - children && children.push(node.element_id); + children && children.push(node.elementId); } } diff --git a/src/features/locators/utils/runLocatorGeneration.ts b/src/features/locators/utils/runLocatorGeneration.ts index 55d882e3..a842d457 100644 --- a/src/features/locators/utils/runLocatorGeneration.ts +++ b/src/features/locators/utils/runLocatorGeneration.ts @@ -4,6 +4,8 @@ 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, @@ -14,12 +16,18 @@ 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; diff --git a/src/features/locators/utils/sortLocators.tsx b/src/features/locators/utils/sortLocators.tsx index 64e73328..69de439b 100644 --- a/src/features/locators/utils/sortLocators.tsx +++ b/src/features/locators/utils/sortLocators.tsx @@ -5,7 +5,7 @@ export const sortLocatorsWithChildren = (locators: ILocator[]) => { for (const locator of locators) { if (locator.parent_id) { - childrenMap.set(locator.element_id, locator); + childrenMap.set(locator.elementId, locator); } } @@ -16,10 +16,10 @@ export const sortLocatorsWithChildren = (locators: ILocator[]) => { if (typeof locator === 'string') { if (!childrenMap.has(locator)) continue; locator = childrenMap.get(locator) as ILocator; - } else if (locator.parent_id?.length && !childrenMap.has(locator.element_id)) continue; + } else if (locator.parent_id?.length && !childrenMap.has(locator.elementId)) continue; sorted.push(locator); - childrenMap.delete(locator.element_id); + childrenMap.delete(locator.elementId); if (locator.children?.length) addLocators(locator.children); } diff --git a/src/features/locators/utils/utils.ts b/src/features/locators/utils/utils.ts index 5dcae063..9eb6a231 100644 --- a/src/features/locators/utils/utils.ts +++ b/src/features/locators/utils/utils.ts @@ -33,15 +33,16 @@ import { escapeLocatorString } from './escapeLocatorString'; export const isValidJavaVariable = (value: string) => /^[a-zA-Z_$]([a-zA-Z0-9_])*$/.test(value); // wishes for future refactorings: get rid these three functions and call sendMessage<> directly -export const evaluateXpath = (xPath: string, element_id?: ElementId, originJdnHash?: string) => - sendMessage.evaluateXpath({ xPath, element_id, originJdnHash }); +export const evaluateXpath = (xPath: string, elementId?: ElementId, originJdnHash?: string) => { + return sendMessage.evaluateXpath({ xPath, elementId, originJdnHash }); +}; export const evaluateStandardLocator = ( selector: string, locatorType: LocatorType, - element_id?: ElementId, + elementId?: ElementId, originJdnHash?: string, -) => sendMessage.evaluateStandardLocator({ selector, locatorType, element_id, originJdnHash }); +) => sendMessage.evaluateStandardLocator({ selector, locatorType, elementId, originJdnHash }); const prepareLocatorStringForEvaluation = (type: LocatorType, string: string): string => { const escapeString = escapeLocatorString(string); @@ -64,17 +65,17 @@ export const evaluateLocator = async ( return evaluateStandardLocator(preparedValue, locatorType, elementId, jdnHash); }; -export const generateSelectorByHash = (element_id: ElementId, jdnHash: string) => - sendMessage.generateSelectorByHash({ element_id, jdnHash }); +export const generateSelectorByHash = (elementId: ElementId, jdnHash: string) => + sendMessage.generateSelectorByHash({ elementId, jdnHash }); export const isValidLocator = (message?: LocatorValidationErrorType) => { return !message || message === LocatorValidationWarnings.NewElement; }; -export const checkDuplicates = (foundHash: string, locators: ILocator[], element_id: ElementId) => +export const checkDuplicates = (foundHash: string, locators: ILocator[], elementId: ElementId) => locators.filter( - ({ jdnHash, message, element_id: _element_id }) => - jdnHash === foundHash && isValidLocator(message) && _element_id !== element_id, + ({ jdnHash, message, elementId: _elementId }) => + jdnHash === foundHash && isValidLocator(message) && _elementId !== elementId, ); export const createNewName = ( @@ -84,9 +85,7 @@ export const createNewName = ( elements: ILocator[], ): string => { const names = chain(elements).map('name').without(element.name).value(); - const newName = createElementName({ ...element }, library, names, newType); - - return newName; + return createElementName({ ...element }, library, names, newType); }; export const setIndents = (ref: React.RefObject, depth: number) => { @@ -181,7 +180,7 @@ export const getLocatorValidationStatus = (message: LocatorValidationErrorType): export const getLocatorValueOnTypeSwitch = async ( newLocatorType: LocatorType, validationMessage: LocatorValidationErrorType, - element_id: ElementId, + elementId: ElementId, jdnHash: JDNHash, locatorValue: LocatorValue, form: FormInstance, @@ -210,9 +209,9 @@ export const getLocatorValueOnTypeSwitch = async ( if (isStandardLocator) { if (isLocatorLeadsToNewElement || isStandardLocatorValueFalsy) { - const { foundHash } = JSON.parse(await evaluateXpath(form.getFieldValue('locator'), element_id, jdnHash)); + const { foundHash } = JSON.parse(await evaluateXpath(form.getFieldValue('locator'), elementId, jdnHash)); - ({ cssSelector: newLocatorValue } = await generateSelectorByHash(element_id, foundHash)); + ({ cssSelector: newLocatorValue } = await generateSelectorByHash(elementId, foundHash)); } else { if (newLocatorType === LocatorType.cssSelector) newLocatorValue = locatorValue.cssSelector; // а не original ли надо делать? try { @@ -224,7 +223,7 @@ export const getLocatorValueOnTypeSwitch = async ( } else { if (isLocatorLeadsToNewElement || !locatorValue.xPath) { const { foundHash } = JSON.parse( - await evaluateStandardLocator(form.getFieldValue('locator'), newLocatorType, element_id), + await evaluateStandardLocator(form.getFieldValue('locator'), newLocatorType, elementId), ); newLocatorValue = await getElementFullXpath(foundHash); } else { @@ -241,29 +240,29 @@ export const getTaskStatus = ( ): LocatorTaskStatus | null => { if (!xPathStatus && !cssSelectorStatus) return LocatorTaskStatus.NOT_STARTED; - return xPathStatus; + // return xPathStatus; // TODO: uncomment when back-end will be ready (issues/1284) 246-267 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) => diff --git a/src/features/pageObjects/components/PageObjList.tsx b/src/features/pageObjects/components/PageObjList.tsx index 184d3e41..93304d8f 100644 --- a/src/features/pageObjects/components/PageObjList.tsx +++ b/src/features/pageObjects/components/PageObjList.tsx @@ -158,7 +158,7 @@ export const PageObjList: React.FC = ({ jdiTemplate, vividusTemplate }) = return ( ); diff --git a/src/features/pageObjects/selectors/pageObjects.selectors.ts b/src/features/pageObjects/selectors/pageObjects.selectors.ts index c00922c0..655abdc9 100644 --- a/src/features/pageObjects/selectors/pageObjects.selectors.ts +++ b/src/features/pageObjects/selectors/pageObjects.selectors.ts @@ -54,7 +54,6 @@ export const selectAutoGeneratingLocatorTypes = createSelector(selectCurrentPage generateCssSelector: !pageObj.hideUnadded && pageObj.locatorType === LocatorType.cssSelector, generateXpath: !pageObj.hideUnadded && pageObj.locatorType === LocatorType.xPath, }; - // console.log('isAutogenerated: ', isAutogenerated); // LOG return isAutogenerated; }); diff --git a/src/features/pageObjects/utils/pageObject.ts b/src/features/pageObjects/utils/pageObject.ts index 1b39513d..f549346f 100644 --- a/src/features/pageObjects/utils/pageObject.ts +++ b/src/features/pageObjects/utils/pageObject.ts @@ -15,8 +15,8 @@ export const isStringMatchesReservedWord = (string: string) => javaReservedWords // ToDo: uncomment with validation rework, see issue #1176: // export const isStringMatchesReservedWordPerfTest = (string: string) => perfReservedWords.includes(string); -export const isNameUnique = (elements: ILocator[], element_id: ElementId, newName: string) => - !elements.find((elem) => elem.name === newName && elem.element_id !== element_id); +export const isNameUnique = (elements: ILocator[], elementId: ElementId, newName: string) => + !elements.find((elem) => elem.name === newName && elem.elementId !== elementId); export const isPONameUnique = (elements: PageObject[], newName: string) => !elements.find((elem) => toLower(elem.name) === toLower(newName)); diff --git a/src/pageServices/connector.ts b/src/pageServices/connector.ts index 2a84bfa8..fa80429b 100644 --- a/src/pageServices/connector.ts +++ b/src/pageServices/connector.ts @@ -176,17 +176,15 @@ export const sendMessage = { checkSession: (payload: null, onResponse?: () => void): Promise<{ message: string; tabId: number }[]> => connector.sendMessageToAllTabs(ScriptMsg.CheckSession, payload, onResponse), defineTabId: (payload: number) => connector.sendMessage(ScriptMsg.DefineTabId, payload), - evaluateXpath: ( - payload: { xPath: string; element_id?: ElementId; originJdnHash?: string }, - onResponse?: () => void, - ) => connector.sendMessage(ScriptMsg.EvaluateXpath, payload, onResponse), + evaluateXpath: (payload: { xPath: string; elementId?: ElementId; originJdnHash?: string }, onResponse?: () => void) => + connector.sendMessage(ScriptMsg.EvaluateXpath, payload, onResponse), evaluateStandardLocator: ( - payload: { selector: string; locatorType: LocatorType; element_id?: ElementId; originJdnHash?: string }, + payload: { selector: string; locatorType: LocatorType; elementId?: ElementId; originJdnHash?: string }, onResponse?: () => void, ) => connector.sendMessage(ScriptMsg.EvaluateStandardLocator, payload, onResponse), getPageData: (payload?: {}, onResponse?: () => void) => connector.sendMessage(ScriptMsg.GetPageData, payload, onResponse), - generateSelectorByHash: (payload: { element_id: string; jdnHash: string }, onResponse?: () => void) => + generateSelectorByHash: (payload: { elementId: string; jdnHash: string }, onResponse?: () => void) => connector.sendMessage(ScriptMsg.GenerateSelectorByHash, payload, onResponse), generateSelectorGroupByHash: ( payload: { elements: ILocator[]; fireCallbackMessage?: boolean }, diff --git a/src/pageServices/contentScripts/findBySelectors.ts b/src/pageServices/contentScripts/findBySelectors.ts index 2bdef90b..4e1a00c4 100644 --- a/src/pageServices/contentScripts/findBySelectors.ts +++ b/src/pageServices/contentScripts/findBySelectors.ts @@ -69,7 +69,7 @@ export const findBySelectors = () => { removeConflictedClasses(document.querySelectorAll(`[${JDN_LABEL}]`), selectorsMap), selectorsMap, ).map((_elem) => ({ - element_id: _elem.getAttribute(JDN_HASH), + elementId: _elem.getAttribute(JDN_HASH), predicted_label: _elem.getAttribute(JDN_LABEL), })), ); diff --git a/src/pageServices/contentScripts/generationData.js b/src/pageServices/contentScripts/generationData.js index e1f4e82c..3866f997 100644 --- a/src/pageServices/contentScripts/generationData.js +++ b/src/pageServices/contentScripts/generationData.js @@ -91,10 +91,10 @@ export const getGenerationAttributes = () => { }; const generateSelectorGroupByHash = (elements) => { - return elements.map(({ element_id, jdnHash }) => { + return elements.map(({ elementId, jdnHash }) => { const element = document.querySelector(`[jdn-hash='${jdnHash}']`); return { - element_id, + elementId, locatorValue: { cssSelector: element ? getUniqueCssSelector(element) : null, }, @@ -102,9 +102,9 @@ export const getGenerationAttributes = () => { }); }; - const generateSelectorByHash = ({ element_id, jdnHash }) => { + const generateSelectorByHash = ({ elementId, jdnHash }) => { const element = document.querySelector(`[jdn-hash='${jdnHash}']`); - return element ? { element_id, cssSelector: getUniqueCssSelector(element) } : null; + return element ? { elementId, cssSelector: getUniqueCssSelector(element) } : null; }; /* diff --git a/src/pageServices/contentScripts/highlight.js b/src/pageServices/contentScripts/highlight.js index 88b4c512..bf364190 100644 --- a/src/pageServices/contentScripts/highlight.js +++ b/src/pageServices/contentScripts/highlight.js @@ -86,7 +86,7 @@ export const highlightOnPage = () => { const updateElement = (element) => { if (!predictedElements) return null; - const i = predictedElements.findIndex((e) => e.element_id === element.element_id); + const i = predictedElements.findIndex((e) => e.elementId === element.elementId); predictedElements[i] = { ...predictedElements[i], ...element }; const div = document.getElementById(predictedElements[i].jdnHash); return div; @@ -116,7 +116,7 @@ export const highlightOnPage = () => { }; const removeElement = (element) => { - const j = predictedElements.findIndex((e) => e.element_id === element?.element_id); + const j = predictedElements.findIndex((e) => e.elementId === element?.elementId); if (j === -1) return; predictedElements.splice(j, 1); @@ -137,7 +137,7 @@ export const highlightOnPage = () => { const updateTooltipXpath = (element) => { const taskStatus = getTaskStatus(element.locatorValue.xPathStatus, element.locatorValue.cssSelectorStatus); - if (taskStatus === LocatorTaskStatus.SUCCESS && tooltip.getAttribute('jdn-element-hash') === element.element_id) { + if (taskStatus === LocatorTaskStatus.SUCCESS && tooltip.getAttribute('jdn-element-hash') === element.elementId) { tooltip.querySelector('.jdn-tooltip-xpath').innerHTML = element.locatorValue.xPath; } }; @@ -162,7 +162,7 @@ export const highlightOnPage = () => { }; const drawRectangle = (elementRect, predictedElement) => { - const { element_id, jdnHash } = predictedElement; + const { elementId, jdnHash } = predictedElement; const getDivPosition = (elementRect) => { const { top, left, height, width } = elementRect || {}; @@ -230,10 +230,10 @@ export const highlightOnPage = () => { const { x, y } = event; const { style, classNames } = tooltipDefaultStyle({ x, y }); Object.assign(tooltip.style, style); - const el = predictedElements.find((e) => e.element_id === element_id); + const el = predictedElements.find((e) => e.elementId === elementId); tooltip.innerHTML = tooltipInnerHTML(el); tooltip.className = classNames.join(' '); - tooltip.setAttribute('jdn-element-hash', el.element_id); + tooltip.setAttribute('jdn-element-hash', el.elementId); }; const predictedElementTaskStatus = getTaskStatus( diff --git a/src/pageServices/contentScripts/pageData.js b/src/pageServices/contentScripts/pageData.js index 11298445..3bbbfcfc 100644 --- a/src/pageServices/contentScripts/pageData.js +++ b/src/pageServices/contentScripts/pageData.js @@ -41,6 +41,7 @@ export const pageData = () => { const _height = el.getBoundingClientRect().height; const _displayed = (_x < 0) | (_y < 0) | (_width <= 1) | (_height <= 1); + // prepare an object as payload for the predict endpoint on the backend return { tag_name: el.tagName, element_id: el.getAttribute(hashAttribute), diff --git a/src/pageServices/contentScripts/utils.ts b/src/pageServices/contentScripts/utils.ts index e05a6dc5..921f0464 100644 --- a/src/pageServices/contentScripts/utils.ts +++ b/src/pageServices/contentScripts/utils.ts @@ -2,14 +2,14 @@ import { ElementAttributes, LocatorType } from '../../common/types/common'; import { LocatorTaskStatus, LocatorValidationWarnings } from '../../features/locators/types/locator.types'; import { ScriptMsg } from '../scriptMsg.constants'; -export const evaluateXpath = ({ xPath, element_id, originJdnHash }: Record) => { +export const evaluateXpath = ({ xPath, elementId, originJdnHash }: Record) => { try { const nodeSnapshot = document.evaluate(xPath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); const length = nodeSnapshot.snapshotLength; const foundElement = nodeSnapshot.snapshotItem(0) as Element; const foundHash = foundElement && foundElement.getAttribute('jdn-hash'); const foundElementText = foundElement && foundElement.textContent; - return JSON.stringify({ length, foundHash, element_id, foundElementText, originJdnHash }); + return JSON.stringify({ length, foundHash, elementId, foundElementText, originJdnHash }); } catch (error) { return LocatorValidationWarnings.NotFound; } diff --git a/src/pageServices/pageDataHandlers.ts b/src/pageServices/pageDataHandlers.ts index 3dd43f3b..7d5842b3 100644 --- a/src/pageServices/pageDataHandlers.ts +++ b/src/pageServices/pageDataHandlers.ts @@ -36,6 +36,22 @@ const sendToModel = async (payload: { elements: string; document: string }, endp type PredictElementsType = Promise<{ data?: PredictedEntity[]; pageData?: string; error?: string }>; +interface PredictEndpointData { + element_id: string; + predicted_label: string; + childs: string[] | null; + displayed: boolean; + is_shown: boolean; +} + +interface PreparedResponseData { + elementId: string; + predicted_label: string; + children: string[] | null; + displayed: boolean; + is_shown: boolean; +} + /* First, plugin collects necessary data from the page. And then tha data is sent to endpoint, according to selected library. Function returns predicted elements. */ @@ -46,12 +62,20 @@ export const predictElements = (endpoint: HttpEndpoint): PredictElementsType => return Promise.all([sendMessage.getPageData(), getFullDocumentWithStyles()]) .then(([pageDataResult, documentResult]) => { pageData = pageDataResult[0]; - return sendToModel({ elements: pageData, document: documentResult }, endpoint); + const payload = { elements: pageData, document: documentResult }; + return sendToModel(payload, endpoint); }) .then( - (response) => { + (response: PredictEndpointData[]) => { removeOverlay(); - return { data: response, pageData }; + const preparedResponse: PreparedResponseData[] = response.map((item) => ({ + elementId: item.element_id, + predicted_label: item.predicted_label, + children: item.childs, + displayed: item.displayed, + is_shown: item.is_shown, + })); + return { data: preparedResponse, pageData }; }, (error) => { removeOverlay(); diff --git a/src/pageServices/scriptMessageHandler.ts b/src/pageServices/scriptMessageHandler.ts index 54af1a68..3ec048d3 100644 --- a/src/pageServices/scriptMessageHandler.ts +++ b/src/pageServices/scriptMessageHandler.ts @@ -57,7 +57,7 @@ export const updateMessageHandler = ( [ScriptMsg.ElementGroupSetActive]: (payload) => { const locators = payload.map((jdnHash: string) => selectLocatorByJdnHash(state, jdnHash)); dispatch(elementGroupSetActive({ locators, fromScript: true })); - dispatch(setScrollToLocator(locators[0].element_id)); + dispatch(setScrollToLocator(locators[0].elementId)); }, [ScriptMsg.ElementGroupUnsetActive]: (payload) => { const locators = payload.map((jdnHash: string) => selectLocatorByJdnHash(state, jdnHash)) as ILocator[]; @@ -71,9 +71,9 @@ export const updateMessageHandler = ( }, [ScriptMsg.RemoveElement]: (payload) => dispatch(toggleDeletedGroup(payload)), [ScriptMsg.ResponseCssSelectors]: (payload) => { - const locators = payload.map(({ element_id, locatorValue }: ILocator) => { + const locators = payload.map(({ elementId, locatorValue }: ILocator) => { return { - element_id, + elementId, locatorValue: { ...locatorValue, cssSelectorStatus: LocatorTaskStatus.SUCCESS }, }; }); @@ -93,7 +93,7 @@ export const updateMessageHandler = ( [ScriptMsg.StopGroupGeneration]: (payload) => dispatch(stopGenerationGroup(payload)), [ScriptMsg.ToggleElement]: (payload) => { dispatch(toggleElementGeneration(payload[0])); - dispatch(setScrollToLocator(payload[0].element_id)); + dispatch(setScrollToLocator(payload[0].elementId)); }, [ScriptMsg.ToggleElementGroup]: (payload) => { dispatch(toggleElementGroupGeneration(payload)); diff --git a/src/pageServices/scriptNotifier.ts b/src/pageServices/scriptNotifier.ts index f3bed6a1..b7c63156 100644 --- a/src/pageServices/scriptNotifier.ts +++ b/src/pageServices/scriptNotifier.ts @@ -52,9 +52,9 @@ const notify = (state: RootState, action: any, prevState: RootState) => { } case 'locators/changeLocatorAttributes': case 'locators/changeLocatorElement/fulfilled': { - const { element_id, message, type: elementType, name } = payload; - const prevValue = selectLocatorById(prevState, element_id); - const newValue = selectLocatorById(state, element_id); + const { elementId, message, type: elementType, name } = payload; + const prevValue = selectLocatorById(prevState, elementId); + const newValue = selectLocatorById(state, elementId); if (!prevValue) return; @@ -92,27 +92,27 @@ const notify = (state: RootState, action: any, prevState: RootState) => { case 'locators/stopGenerationGroup/fulfilled': { const _arr: ILocator[] = compact(payload); _arr.forEach((element) => { - const { element_id } = element; - const locator = selectLocatorById(state, element_id); + const { elementId } = element; + const locator = selectLocatorById(state, elementId); locator && sendMessage.changeStatus(locator); }); break; } case 'locators/toggleElementGeneration': // ToDo isGenerated refactoring case 'locators/toggleLocatorIsChecked': { - const element = selectLocatorById(state, typeof payload === 'string' ? payload : payload.element_id); + const element = selectLocatorById(state, typeof payload === 'string' ? payload : payload.elementId); element && sendMessage.toggle({ element }); break; } case 'locators/toggleElementGroupGeneration': payload.forEach((element: ILocator) => { - const locator = selectLocatorById(state, element.element_id); + const locator = selectLocatorById(state, element.elementId); locator && sendMessage.toggle({ element: locator, skipScroll: true }); }); break; case 'locators/toggleElementGroupIsChecked': payload.forEach((element: ILocator) => { - const locator = selectLocatorById(state, element.element_id); + const locator = selectLocatorById(state, element.elementId); locator && sendMessage.toggle({ element: locator, skipScroll: true }); }); break; @@ -132,7 +132,7 @@ const notify = (state: RootState, action: any, prevState: RootState) => { } case 'locators/setElementGroupGeneration': payload.locators.forEach((_loc: ILocator) => { - const element = selectLocatorById(state, _loc.element_id); + const element = selectLocatorById(state, _loc.elementId); element && sendMessage.toggle({ element, skipScroll: true }); }); break; @@ -143,22 +143,22 @@ const notify = (state: RootState, action: any, prevState: RootState) => { } case 'locators/toggleDeletedGroup': payload.forEach((element: ILocator) => { - const locator = selectLocatorById(state, element.element_id); + const locator = selectLocatorById(state, element.elementId); locator && sendMessage.toggleDeleted(locator); }); break; case 'locators/updateLocatorGroup': - payload.locators.forEach(({ element_id, jdnHash }: ILocator) => { - const locator = element_id ? selectLocatorById(state, element_id) : selectLocatorByJdnHash(state, jdnHash); + payload.locators.forEach(({ elementId, jdnHash }: ILocator) => { + const locator = elementId ? selectLocatorById(state, elementId) : selectLocatorByJdnHash(state, jdnHash); locator && sendMessage.changeStatus(locator); }); break; case 'locators/failGeneration': { const { ids } = payload; - const elements = ids.map((element_id: string) => { - const jdnHash = selectLocatorById(state, element_id)?.jdnHash; + const elements = ids.map((elementId: string) => { + const jdnHash = selectLocatorById(state, elementId)?.jdnHash; return { - element_id, + elementId, jdnHash, locatorValue: { xPathStatus: LocatorTaskStatus.FAILURE, cssSelectorStatus: LocatorTaskStatus.FAILURE }, } as ILocator; diff --git a/src/services/pageDocument/pageDocument.reducers.ts b/src/services/pageDocument/pageDocument.reducers.ts index 42440343..9fac04c1 100644 --- a/src/services/pageDocument/pageDocument.reducers.ts +++ b/src/services/pageDocument/pageDocument.reducers.ts @@ -10,7 +10,9 @@ export const pageDocumentReducers = { const notShownElementIds = action.payload .filter((el: PredictedEntity) => !el.is_shown) - .map((el: PredictedEntity) => el.element_id); + .map((el: PredictedEntity) => el.elementId); + + state.notShownElementIds = notShownElementIds; /* set cleaned Html String into pageDocumentForRobula: */ state.pageDocumentForRobula = removeNodesByAttribute(documentContent, 'jdn-hash', notShownElementIds); @@ -18,4 +20,7 @@ export const pageDocumentReducers = { console.error('Document content is not available.'); } }, + setNotShownElementsIds(state: PageDocumentState, action: PayloadAction) { + state.notShownElementIds = action.payload; + }, }; diff --git a/src/services/pageDocument/pageDocument.selectors.ts b/src/services/pageDocument/pageDocument.selectors.ts index 43d5dfdc..0c3354f3 100644 --- a/src/services/pageDocument/pageDocument.selectors.ts +++ b/src/services/pageDocument/pageDocument.selectors.ts @@ -8,3 +8,4 @@ export const selectPageDocumentForRobula = createSelector( selectPageDocumentState, (state) => state.pageDocumentForRobula, ); +export const selectNotShownElementIds = createSelector(selectPageDocumentState, (state) => state.notShownElementIds); diff --git a/src/services/pageDocument/pageDocument.slice.ts b/src/services/pageDocument/pageDocument.slice.ts index cf5167f7..dede64bd 100644 --- a/src/services/pageDocument/pageDocument.slice.ts +++ b/src/services/pageDocument/pageDocument.slice.ts @@ -1,5 +1,4 @@ import { createSlice } from '@reduxjs/toolkit'; - import { pageDocumentReducers } from './pageDocument.reducers'; import { pageDocumentExtraReducers } from './fetchPageDocument.thunk'; @@ -10,11 +9,13 @@ export interface PageDocumentState { error?: string; }; pageDocumentForRobula: null | string; + notShownElementIds: string[]; } export const initialState: PageDocumentState = { pageDocument: { content: null, isLoading: false }, pageDocumentForRobula: null, + notShownElementIds: [], }; const pageDocumentSlice = createSlice({ @@ -24,6 +25,6 @@ const pageDocumentSlice = createSlice({ extraReducers: pageDocumentExtraReducers, }); -export const { createDocumentForRobula } = pageDocumentSlice.actions; +export const { createDocumentForRobula, setNotShownElementsIds } = pageDocumentSlice.actions; export default pageDocumentSlice.reducer; diff --git a/src/services/webSocketMessageHandler.ts b/src/services/webSocketMessageHandler.ts index 0b06dd7e..bc24eac2 100644 --- a/src/services/webSocketMessageHandler.ts +++ b/src/services/webSocketMessageHandler.ts @@ -20,6 +20,9 @@ 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 ( @@ -40,7 +43,7 @@ export const updateSocketMessageHandler = (dispatch: any, state: any) => { const messageHandler = (event: WebSocketMessageEvent | typeof NETWORK_ERROR) => { if (event === NETWORK_ERROR) { const inProgress = selectInProgressByPageObj(state); - const failedIds = inProgress.map(({ element_id }: ILocator) => element_id); + const failedIds = inProgress.map(({ elementId }: ILocator) => elementId); dispatch(failGeneration({ ids: failedIds, errorMessage: NETWORK_ERROR })); return; } @@ -57,7 +60,7 @@ export const updateSocketMessageHandler = (dispatch: any, state: any) => { if (errorMessage === NO_ELEMENT_IN_DOCUMENT) { if (reScheduledTasks.has(jdnHash)) { reScheduledTasks.delete(jdnHash); - dispatch(failGeneration({ ids: [element.element_id], errorMessage })); + dispatch(failGeneration({ ids: [element.elementId], errorMessage })); } else { reScheduledTasks.add(jdnHash); const rescheduleTask = async () => { @@ -72,10 +75,17 @@ 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();