-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed0e094
commit 5615375
Showing
3 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { test, expect } from "@playwright/test"; | ||
import { appLogin, navigateToPage } from "tests/utils/functions"; | ||
import { getRandomString } from "tests/utils/getRandomNumberOrString"; | ||
import { createGlobalVariables, myContext } from "tests/utils/orgUtils"; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await appLogin(page); | ||
await navigateToPage(page, expect, "organizations"); | ||
await expect(page).toHaveURL("/organizations"); | ||
await expect(page.getByText("NEW ORGANIZATION")).toBeVisible(); | ||
createGlobalVariables(page); | ||
const { createBtn } = myContext; | ||
await createBtn.click(); | ||
}); | ||
|
||
test.afterEach(async ({ page }) => { | ||
await page.close(); | ||
}); | ||
|
||
const verifyInputs = async (page) => { | ||
const { nameInput, addressInput, noteInput } = myContext; | ||
|
||
await expect(page).toHaveURL("/organizations/add"); | ||
|
||
await expect(nameInput).toBeVisible(); | ||
await expect(nameInput).toBeEmpty(); | ||
await expect(addressInput).toBeVisible(); | ||
await expect(addressInput).toBeEmpty(); | ||
await expect(noteInput).toBeVisible(); | ||
await expect(noteInput).toBeEmpty(); | ||
}; | ||
|
||
test("Create org", async ({ page }) => { | ||
const { nameInput, addressInput, noteInput, submitButton } = myContext; | ||
await verifyInputs(page); | ||
|
||
await nameInput.fill(getRandomString(5)); | ||
await addressInput.fill(getRandomString(5)); | ||
await noteInput.fill(getRandomString(10)); | ||
|
||
await submitButton.click(); | ||
await expect( | ||
page.getByText("Successfully created an organization!") | ||
).toBeVisible(); | ||
}); | ||
|
||
test("Submit throws validation when inputs are empty", async ({ page }) => { | ||
const { submitButton } = myContext; | ||
await verifyInputs(page); | ||
await submitButton.click(); | ||
|
||
await expect(page.getByText("Input field is required").first()).toBeVisible(); | ||
await expect(page.getByText("Input field is required").nth(1)).toBeVisible(); | ||
await expect(page.getByText("Input field is required").nth(2)).toBeVisible(); | ||
}); | ||
|
||
test("Reset button works", async ({ page }) => { | ||
const { nameInput, addressInput, noteInput, resetButton } = myContext; | ||
await verifyInputs(page); | ||
|
||
await nameInput.fill(getRandomString(5)); | ||
await addressInput.fill(getRandomString(5)); | ||
await noteInput.fill(getRandomString(10)); | ||
|
||
await resetButton.click(); | ||
await verifyInputs(page); | ||
}); | ||
|
||
test("Go back button works", async ({ page }) => { | ||
const { goBackButton } = myContext; | ||
await verifyInputs(page); | ||
await goBackButton.click(); | ||
await expect(page).toHaveURL("/organizations"); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const myContext = {}; | ||
|
||
export const createGlobalVariables = async (page) => { | ||
myContext.createBtn = page.getByRole("link", { name: "New Organization" }); | ||
|
||
myContext.nameInput = page.getByLabel("Name"); | ||
myContext.addressInput = page.getByLabel("Address"); | ||
myContext.noteInput = page.getByLabel("Note"); | ||
|
||
myContext.submitButton = page.getByRole("button", { name: "Submit" }); | ||
myContext.resetButton = page.getByRole("button", { name: "Reset" }); | ||
myContext.goBackButton = page.getByRole("button", { name: "Go Back" }); | ||
}; |