mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-18 05:24:06 +01:00
Update test 02
This commit is contained in:
parent
b84dde1044
commit
1ca19f0e49
2
.github/workflows/playwright.yml
vendored
2
.github/workflows/playwright.yml
vendored
@ -39,7 +39,7 @@ jobs:
|
||||
if: steps.playwright-cache.outputs.cache-hit != 'true'
|
||||
|
||||
- name: Run Playwright tests
|
||||
run: npx playwright test
|
||||
run: npx playwright test --workers=1
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: ${{ !cancelled() }}
|
||||
|
||||
|
Before Width: | Height: | Size: 95 B After Width: | Height: | Size: 95 B |
16
tests/assets/mockData.json
Normal file
16
tests/assets/mockData.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"company": {
|
||||
"name": "Kasetsart",
|
||||
"raised": "1000000",
|
||||
"url": "https://www.test.md"
|
||||
},
|
||||
"project": {
|
||||
"name": "DummyTester",
|
||||
"description": "0123456789",
|
||||
"url": "https://www.test.md",
|
||||
"budgetLow": "500",
|
||||
"budgetHigh": "100000000",
|
||||
"deadline": "2026-01-01T00:00"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Page } from '@playwright/test';
|
||||
|
||||
export const login = async (page: Page, role: 'user' | 'admin') => {
|
||||
export const loginUtils = async (page: Page, role: 'user' | 'admin') => {
|
||||
const email = role === 'user' ? process.env.NEXT_PUBLIC_TEST_USER_EMAIL : process.env.NEXT_PUBLIC_ADMIN_EMAIL;
|
||||
const password = role === 'user' ? process.env.NEXT_PUBLIC_TEST_USER_PASSWORD : process.env.NEXT_PUBLIC_ADMIN_PASSWORD;
|
||||
|
||||
@ -9,13 +9,11 @@ export const login = async (page: Page, role: 'user' | 'admin') => {
|
||||
}
|
||||
|
||||
await page.goto('/');
|
||||
const isLoginPage = await page.locator('id=login').isVisible();
|
||||
const isLoginPage = await page.getByRole('button', { name: 'Login' }).isVisible();
|
||||
if (!isLoginPage) {
|
||||
console.log(`Logging out current session...`);
|
||||
await page.evaluate(() => {
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
});
|
||||
await page.getByRole('button', { name: 'profile' }).click();
|
||||
await page.getByRole('menuitem', { name: 'Logout' }).click();
|
||||
}
|
||||
|
||||
console.log(`Logging in as ${role}...`);
|
||||
11
tests/helpers/searchUtils.ts
Normal file
11
tests/helpers/searchUtils.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Page, expect } from "@playwright/test";
|
||||
|
||||
export const searchBusiness = async (page: Page, business: string) => {
|
||||
console.log("search for " + business);
|
||||
await page.locator("li").nth(3).click();
|
||||
await page.getByPlaceholder("Enter business name...").fill(business);
|
||||
await page.getByPlaceholder("Enter business name...").press("Enter");
|
||||
// await page.waitForURL("http://127.0.0.1:3000/find?query=" + business);
|
||||
await expect(page.getByRole("link", { name: "Business logo " + business })).toBeHidden();
|
||||
console.log("found" + business);
|
||||
};
|
||||
@ -1,20 +1,27 @@
|
||||
import { test } from "@playwright/test";
|
||||
import { login } from "./helpers/login";
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { loginUtils } from "./helpers/loginUtils";
|
||||
import { selectFirstOption } from "./helpers/dropdownUtils";
|
||||
import mockData from "./assets/mockData.json";
|
||||
import { searchBusiness } from "./helpers/searchUtils";
|
||||
|
||||
test("test", async ({ page }) => {
|
||||
await login(page, "user");
|
||||
await page.getByRole('button', { name: 'Businesses' }).hover();
|
||||
await loginUtils(page, "user");
|
||||
await page.getByRole("button", { name: "Businesses" }).hover();
|
||||
await page.getByRole("link", { name: "Business Apply to raise on on" }).click();
|
||||
|
||||
await selectFirstOption(page, page.locator("button").filter({ hasText: "Select an industry" }));
|
||||
await selectFirstOption(page, page.locator("button").filter({ hasText: "Select a country" }));
|
||||
await page.getByPlaceholder("$").fill("999998");
|
||||
await page.getByPlaceholder("$").fill(mockData.company.raised);
|
||||
await page.getByRole("button", { name: "Yes" }).first().click();
|
||||
await page.getByRole("button", { name: "Yes" }).nth(1).click();
|
||||
await page.getByRole("button", { name: "Yes" }).nth(2).click();
|
||||
await page.getByPlaceholder('https:// ').fill('https://www.test.md');
|
||||
await page.getByPlaceholder("https:// ").fill(mockData.company.url);
|
||||
await selectFirstOption(page, page.locator("button").filter({ hasText: "Select" }));
|
||||
await page.locator("#companyName").fill("kasetsart");
|
||||
await page.getByRole('button', { name: 'Submit application' }).click();
|
||||
await page.locator("#companyName").fill(mockData.company.name);
|
||||
await page.getByRole("button", { name: "Submit application" }).click();
|
||||
const okButton = page.getByRole("button", { name: "OK" });
|
||||
await expect(okButton).toBeVisible();
|
||||
await okButton.click();
|
||||
|
||||
await searchBusiness(page, mockData.company.name);
|
||||
});
|
||||
|
||||
25
tests/test-02-admin-approve-business.spec.ts
Normal file
25
tests/test-02-admin-approve-business.spec.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { loginUtils } from "./helpers/loginUtils";
|
||||
import mockData from "./assets/mockData.json";
|
||||
import { searchBusiness } from "./helpers/searchUtils";
|
||||
|
||||
test("test", async ({ page }) => {
|
||||
await loginUtils(page, "admin");
|
||||
await page.getByRole("button", { name: "profile" }).click();
|
||||
await page.getByRole("link", { name: "Admin" }).click();
|
||||
await page.locator("html").click();
|
||||
await page.getByRole("button", { name: "Go to Business Application" }).click();
|
||||
|
||||
// if test 01 click no 'yes' use .first, or 'yes' n time use nth(n)
|
||||
console.log('approving');
|
||||
await page
|
||||
.getByRole("row", { name: mockData.company.name + " " + mockData.company.url })
|
||||
.getByRole("img")
|
||||
.nth(3)
|
||||
.click();
|
||||
const approveButton = page.getByRole("button", { name: "Approve" });
|
||||
await expect(approveButton).toBeVisible();
|
||||
await approveButton.click();
|
||||
|
||||
await searchBusiness(page, mockData.company.name);
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user