Skip to content

Commit

Permalink
added tests for organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrov93 committed Apr 16, 2024
1 parent ed0e094 commit 5615375
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/views/Organizations/OrganizationsAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const isFormValid = async () => {
const postOrg = async (data) => {
try {
await store.dispatch("organizations/postOrg", data);
snackbarProvider.showSuccessSnackbar("Successfully sold the product!");
snackbarProvider.showSuccessSnackbar("Successfully created an organization!");
router.push("/organizations");
} catch (error) {
snackbarProvider.showErrorSnackbar(error?.response?.data?.error);
Expand Down
74 changes: 74 additions & 0 deletions tests/Organizations/create-org.spec.js
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");
});
13 changes: 13 additions & 0 deletions tests/utils/orgUtils.js
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" });
};

0 comments on commit 5615375

Please sign in to comment.