Solution: Create an Order

Review the solution for writing a test to complete the create order flow.

Challenge solution

Let's review the code for the challenge exercise.

Form component

The solution for the ​​form.js is provided below:

Press + to interact
class Form {
get nameInput() {
return $('[name="name"]')
}
get emailInput() {
return $('[name="email"]')
}
get phoneInput() {
return $('[name="phone"]')
}
get categorySelect() {
return $("[aria-label='category selector']")
}
get descriptionInput() {
return $('[name="description"]')
}
get submitButton() {
return $('button=Submit')
}
updateField(field) {
return $(`[name="${field}"]`)
}
/**
* Updates a field in the form
* @param {*} field ex. name, email, phone, category, description
* @param {*} value
*/
async updateOrder(field, value) {
await this.updateField(field).setValue(value)
await this.submitButton.click()
}
async enterOrder(name, email, category, phone, description) {
await this.nameInput.setValue(name)
await this.emailInput.setValue(email)
await this.categorySelect.click()
await $(`[name='${category}']`).click()
await this.phoneInput.setValue(phone)
await this.descriptionInput.setValue(description)
await this.submitButton.click()
}
}
export default new Form()

Let's explain the code above:

  • In line 11, we select the phone field by its name attribute.

  • In line 15, we select the category select by ...

Access this course and 1400+ top-rated courses and projects.