New to Cypress so sorry if this is a basic question.
I have an app that allows the creation of 'datasets' of varying types. I'm trying to create a method that will create a dataset for each available type displayed within a dropdown.
So, to begin with, I have this method that will create a specific dataset (based on the baseType that's passed in).
createBasicDatasetAndVerifyCreation(baseType){
const newDatasetTitle = createDatasetName() //Creating a title
cy.get(':nth-child(1) > .col-sm-6 > .v-input').type(newDatasetTitle) //Typing the title
cy.get(':nth-child(2) > .col-lg-4 > .v-input').click() //Trigger the dropdown
cy.get('[class="v-list v-select-list v-sheet theme--light theme--light"]').then( datasetDropdownList => {
cy.wait(500)
cy.wrap(datasetDropdownList).contains(baseType).click()
})
cy.contains('Save').click()
cy.get('.v-toolbar__content > .text-none').should('contain', 'Datasets') //Checking user is redirected
//Checking table to see if it's saved correctly
cy.get('tbody').contains('tr', newDatasetTitle).then( tableRow => {
cy.wrap(tableRow).should('contain', newDatasetTitle)
cy.wrap(tableRow).should('contain', 'Custom')
})
}
I'm now trying to repeat the above for each item within the datasetDropdownList. So far, I've stored the contents of the dropdown as an array using this function-
function getAvailableDatasets(){
const array = []
cy.get('[class="v-list v-select-list v-sheet theme--light theme--light"]').each(($option, index )=> {
array.push(Cypress.$($option).text())
console.log(array[index]);
})
return array}
and implemented it here-
createOneOfEachAvailableDataset(){
const newDatasetTitle = createDatasetName() //Creating a title
cy.get(':nth-child(1) > .col-sm-6 > .v-input').type(newDatasetTitle) //Typing the title
cy.get(':nth-child(2) > .col-lg-4 > .v-input').click() //Trigger the dropdown
cy.wait(500)
const arrayOfDatasets = getAvailableDatasets()
}
I'm now unsure how to loop through the array, creating a new dataset for each type in the array.