import { Then, When } from "@cucumber/cucumber"
import { page } from "../setup"
const { expect } = require("@playwright/test")
When("I enter required data in the form", async function (dataTable) {
await page.goto(`/management`)
await page.getByRole("link", { name: "Management" }).click()
await page.getByRole("button", { name: "Add New User" }).click()
const rows = dataTable.rows()
for (const row of rows) {
const [firstname, lastname, email, dateofbirth, language] = row
await page.getByPlaceholder("First Name").click()
await page.getByPlaceholder("First Name").fill(firstname)
await page.getByPlaceholder("Last Name").fill(lastname)
await page.getByPlaceholder("Email", { exact: true }).click()
await page.getByPlaceholder("Email", { exact: true }).fill(email)
await page.locator("#date_of_birth").fill(dateofbirth)
await page.getByRole("combobox", { name: "Language *" }).selectOption(language)
}
await page.getByRole("button", { name: "Confirm" }).click()
})
Then("I should see a success message", async function (dataTable) {
const row = dataTable.rows()
const message = row[0][0]
const msg_success = await page.getByRole("status", { name: "Status message" }).first().textContent()
console.log(msg_success)
await expect(msg_success).toMatch(message)
})
Then("I should see unsuccessful message", async function (dataTable) {
const row = dataTable.rows()
const message = row[0][0]
const msg_unsuccess = await page.getByRole("alert", { name: "Error message" }).first().textContent()
console.log(msg_unsuccess)
await expect(msg_unsuccess).toMatch(message)
})