Hello. I'm just learning to program and can't find a solution to this problem.

There is a function

export const creatingSQLQuery = (queryName, sourceName, baseName, schemeName, tableName, groupName = false) => { cy.clickOnButton(buttons.sqlList); cy.clickOnButton(buttons.createSQLQuery); cy.addTitleForSQLMDXFields(queryName); if (groupName) { cy.groupSelection(groupName); } cy.sourceSelection(sourceName); cy.baseSelection(baseName); cy.schemeSelection(schemeName); cy.tableSelection(tableName); cy.chooseSearchAndReturnField('Поля поиска', 'Brand', 'Model' ); cy.chooseSearchAndReturnField('Возвращаемое поле', 'Brand', 'Model', 'ProdYear', 'CountryRu'); cy.clickOnButton(buttons.forwardButton); cy.clickOnButton(buttons.forwardButton); cy.clickOnButton(buttons.forwardButton); cy.dialogMessagesValidation(dialogMessages.sqlSaved); }; 

As you can see. In it, I need to pass a bunch of parameters and use each parameter also in its function. In my case, this decision is not beautiful and not correct. Because:

  1. Parameters passed are subject to change.

  2. I do not always pass such a number of parameters. Sometimes I will need to call this function. Without the GroupName parameter and sometimes with it. I would not like to duplicate the code and write a function where I do not use groupName

Question:

How do I pass a certain array of objects to a function? Where the set of parameters necessary for me will be assembled. So that I could just create an object with the data set I need and pass it to this function. Where each subfunction accessed its object. To get something like:

An object with the data set I need

 import {baseNames} from "./SQLQuery/baseNames"; import {schemeNames} from "./SQLQuery/schemeNames"; import {sourceNames} from "./SQLQuery/sourceNames"; import {tableNames} from "./SQLQuery/tableNames"; export const someObject = { fieldsForSelection: [sourceNames.MSSQL ,baseNames.AutostatDW, schemeNames.vin, tableNames.vVin ] }; 

Approximate type of function which I would like to write

 export const creatingSQLQuery = (someObject, groupName = false) => { cy.clickOnButton(buttons.sqlList); cy.clickOnButton(buttons.createSQLQuery); cy.addTitleForSQLMDXFields(queryName); if (groupName) { cy.groupSelection(groupName); } cy.sourceSelection(someObject); cy.baseSelection(someObject); cy.schemeSelection(someObject); cy.tableSelection(someObject); cy.chooseSearchAndReturnField('Поля поиска', 'Brand', 'Model' ); cy.chooseSearchAndReturnField('Возвращаемое поле', 'Brand', 'Model', 'ProdYear', 'CountryRu'); cy.clickOnButton(buttons.forwardButton); cy.clickOnButton(buttons.forwardButton); cy.clickOnButton(buttons.forwardButton); cy.dialogMessagesValidation(dialogMessages.sqlSaved); }; 

But I myself can not implement this idea. Because I do not know how to write it syntactically. and I would also not like to manually assign an object for each subfunction like this (someObject.MSSQL, someObject.Vvin и т.д) Because then I will have to duplicate this function again and specify different objects for each.

Please write your ideas.

  • what's stopping you from simply rewriting to the kind that you want? Actually you have already rewrote the question - Grundy

0