Created
March 11, 2024 07:24
-
-
Save mandemeskel/2b8e81df0a7602650633c7d19268e451 to your computer and use it in GitHub Desktop.
Retool, Create User Testing API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Page, expect } from '@playwright/test' | |
import { User } from '@/types/user_types' | |
export class CreateUserTapi { | |
constructor(protected user: User, public page: Page) { | |
this.page = page | |
} | |
async fillContactPhone() { | |
await this.page.locator("#phone_in--0").first().fill(this.user.contact_info.phone) | |
} | |
async fillContactName() { | |
await this.page.locator("#name_in--0").first().fill(this.user.contact_info.name) | |
} | |
async fillContactEmail() { | |
await this.page.locator("#email_in--0").first().fill(this.user.contact_info.email) | |
} | |
async fillPublicId() { | |
await this.page.locator("#public_id--0").first().fill(this.user.public_id) | |
} | |
async clickSumbitButton() { | |
await this.page.getByRole("button").getByText("Submit").click() | |
} | |
async clickSubmitConfirmation() { | |
await this.page.getByRole("button").getByText("Ok").click() | |
} | |
async clickAndConfirmUser() { | |
await this.clickSumbitButton() | |
await this.clickSubmitConfirmation() | |
} | |
async setActiveStatus() { | |
if (this.user.is_active) { | |
await this.activateUser() | |
} else { | |
await this.deactivateUser() | |
} | |
} | |
async activateUser() { | |
await this.page.locator("#is_active--0").first().check() | |
} | |
async deactivateUser() { | |
await this.page.locator("#is_active--0").first().uncheck() | |
} | |
//Matchers | |
async expectWarningToBeShown() { | |
await expect(await this.page.getByText("This field is required.").first()).toBeDefined | |
} | |
async expectUserToBeActivated() { | |
await expect(await this.page.locator("#is_active--0").first().check()).toBeTruthy | |
} | |
async expectUserToBeDeactivated() { | |
await expect(await this.page.locator("#is_active--0").first().uncheck()).toBeTruthy | |
} | |
async expectContactNameToBeFilled() { | |
await expect(await this.page.locator("#name_in--0").first()).toHaveValue(this.user.contact_info.name) | |
} | |
async expectContactEmailToBeFilled() { | |
await expect(await this.page.locator("#email_in--0").first()).toHaveValue(this.user.contact_info.email) | |
} | |
async expectContactPhoneToBeFilled() { | |
await expect(await this.page.locator("#phone_in--0").first()).toHaveValue(this.user.contact_info.phone) | |
} | |
async expectGenerateIDToBeClicked() { | |
await expect(await this.page.getByText("Query ran sucessfully").first()).toBeVisible | |
} | |
async expectPublicIdToBeFilled() { | |
await expect(await this.page.locator("#public_id--0").first()).toHaveValue(this.user.public_id) | |
} | |
async expectUserToBeInTable() { | |
await expect(await this.page.locator("#users_table--0").getByText(this.user.contact_info.name)).toBeDefined | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment