I am trying to create reusable function for login scenario where the user is given an option to select the choice of their department to curate the content. Only one option can be selected per one registration. I have created a file for just the locators and using cypress to return the first indexed item. I am calling the test in the main spec. This login function has multiple options to choose from and I have added all the options in Json file in teamSelector.js. How do I make this teamSelector.js reusable fun? I don't want to specify the index in this file but call in my loginTest.js file with an ability to call all the available ID's from Json file.
loginTest.js file code below
import emailSignup from './emailsignup'
import teamSelector from './teamSelector'
{/* <reference types = "cypress" /> */}
const {commands} = require('../support/commands')
const { Input } = require("@angular/core")
const { wrap } = require("module")
const { isExportSpecifier } = require("typescript")
describe('our first suite', () => {
const signup = new emailSignup()
const signindepartment = new teamSelector()
it('first test', () => {
cy.visit('/')
signup.signupforfreelink().click()
// cy.get('a[data-tracking-name="Sign up for free"]').click()
cy.get('.flex').should('contain',"Create your free account")
cy.get('[for="emailSignup"]').should('contain',"Work email")
signup.email()
signup.continuebtn()
signup.firstandlastname()
signup.password()
signup.signInButton()
signup.alertsignup()
signup.closealert()
signindepartment.loginselectors()
})
})
teamSelector.js
class teamSelector {
loginselectors() { return cy.get('.flex').find('[type="checkbox"]').then(userselection => {
// const department = {
// "mar": "Marketing",
// "prod": "Product & Design",
// "eng": "Engineering",
// "supp": "IT & Support",
// "oper": "Operations",
// "acctmgnt": "Sales & Account Mgmt.",
// "hr": "HR & Legal",
// "creative": "Creative Production",
// "customerservice": "Customer Service",
// "fin": "Finance",
// "manfact":"Manufacturing",
// "other": "Other / Personal"
// }
cy.wrap(userselection)
.first()
.check({force:true})
.should('be.checked')
})
}
}
export default teamSelector