GSA / px-benefit-finder

1 stars 1 forks source link

Reduce dot notation chaining in cypress tests #1919

Open scottqueen-bixal opened 2 weeks ago

scottqueen-bixal commented 2 weeks ago

Description

we have lengthy dot notation assignments due to nested data,

for example:

current

const relationshipId =
  EN_DOLO_MOCK_DATA.data.lifeEventForm.sectionsEligibilityCriteria[0].section
    .fieldsets[1].fieldset.inputs[0].inputCriteria.id
const relationshipValue =
  EN_DOLO_MOCK_DATA.data.lifeEventForm.sectionsEligibilityCriteria[0].section
    .fieldsets[1].fieldset.inputs[0].inputCriteria.values[1].value

lets explore ways to reduce this with functional programing,


const getInputCriteria = (data, criteriaLocation: { fieldSetsIndex, inputIndex }) => {
 ...
 return value
}

// getInputCriteria(data[<sectionIndex>], criteriaLocation: { fieldSetsIndex, inputIndex });

const data = EN_DOLO_MOCK_DATA.data.lifeEventForm.sectionsEligibilityCriteria

const relationshipCriteria =  getInputCriteria(data[0], criteriaLocation: {
        fieldSetsIndex: 1,
        inputIndex: 0,
})

// And then when we want to call dot notations we can call it from the criteria, ie.

console.log(relationshipCriteria.id);
console.log(relationshipCriteria.values[1].value);

User Story

No response

Acceptance Criteria

No response