diff --git a/playwright.config.ts b/playwright.config.ts index 1ffe725..7b6856f 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,20 +1,20 @@ -import { defineConfig, devices } from '@playwright/test'; +import { defineConfig, devices } from "@playwright/test"; /** * Read environment variables from file. * https://github.com/motdotla/dotenv */ -import dotenv from 'dotenv'; -import path from 'path'; -dotenv.config({ path: path.resolve(__dirname, '.env') }); +import dotenv from "dotenv"; +import path from "path"; +dotenv.config({ path: path.resolve(__dirname, ".env") }); /** * See https://playwright.dev/docs/test-configuration. */ export default defineConfig({ - globalSetup: require.resolve('./test_util/global-setup'), - globalTeardown: require.resolve('./test_util/global-teardown'), - testDir: './tests', + globalSetup: require.resolve("./tests/global-setup"), + globalTeardown: require.resolve("./tests/global-teardown"), + testDir: "./tests", /* Run tests in files in parallel */ fullyParallel: true, /* Fail the build on CI if you accidentally left test.only in the source code. */ @@ -24,37 +24,41 @@ export default defineConfig({ /* Opt out of parallel tests on CI. */ workers: process.env.CI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: 'html', + reporter: "html", /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ baseURL: process.env.BASE_URL, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: 'on-first-retry', - storageState: './storageState.json', + trace: "on-first-retry", + storageState: "./storageState.json", ignoreHTTPSErrors: true, }, /* Configure projects for major browsers */ projects: [ + // Setup project for authentication { - name: 'chromium', - use: { ...devices['Desktop Chrome'], - }, + name: "setup", + testMatch: /.*\.setup\.ts/, // Only run setup files for this project + }, + { + name: "chromium", + use: { ...devices["Desktop Chrome"], storageState: "./storageState.json" }, + dependencies: ["setup"], // Ensure 'setup' runs before this project }, { - name: 'firefox', - use: { ...devices['Desktop Firefox'], - storageState:"./storageState.json", - }, + name: "firefox", + use: { ...devices["Desktop Firefox"], storageState: "./storageState.json" }, + dependencies: ["setup"], // Ensure 'setup' runs before this project }, { - name: 'webkit', - use: { ...devices['Desktop Safari'] , - }, + name: "webkit", + use: { ...devices["Desktop Safari"], storageState: "./storageState.json" }, + dependencies: ["setup"], // Ensure 'setup' runs before this project }, /* Test against mobile viewports. */ @@ -80,8 +84,8 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { - command: 'npm run dev', - url: 'http://127.0.0.1:3000', + command: "npm run dev", + url: "http://127.0.0.1:3000", reuseExistingServer: !process.env.CI, }, }); diff --git a/test_util/getUser.ts b/test_util/getUser.ts index e7211b2..2d5e24a 100644 --- a/test_util/getUser.ts +++ b/test_util/getUser.ts @@ -28,8 +28,8 @@ export async function getUserUidByEmail(email: string): Promise<{ data: string | return { data: null, error: error }; } - console.log(`Retrieve UID successfully.`); - return { data: data[0].id, error: error }; + console.log(`Retrieve UID successfully.`, data); + return { data, error: error }; } catch (error) { console.error(`Error retrive user with email: ${email}`, error); throw error; diff --git a/test_util/global-setup.ts b/test_util/global-setup.ts deleted file mode 100644 index c9679fa..0000000 --- a/test_util/global-setup.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { firefox, FullConfig } from '@playwright/test'; - -async function globalSetup(config: FullConfig) { - const { baseURL, storageState } = config.projects[0].use; - console.log('globalizing...'); - const email = process.env.NEXT_PUBLIC_TEST_USER_EMAIL; - const password = process.env.NEXT_PUBLIC_TEST_USER_PASSWORD; - - if (!email || !password) { - throw new Error('NEXT_PUBLIC_TEST_USER_EMAIL and NEXT_PUBLIC_TEST_USER_PASSWORD must be set'); - } - - const browser = await firefox.launch(); - const page = await browser.newPage(); - - console.log('signing up user...'); - await page.goto(baseURL + '/auth/signup'); - await page.fill('id=email', email); - await page.fill('id=password', password); - await page.fill('id=confirmPassword', password); - await page.click('id=signup') - - await page.context().storageState({ path: storageState as string }); - await browser.close(); -} - -export default globalSetup; \ No newline at end of file diff --git a/test_util/global-teardown.ts b/test_util/global-teardown.ts deleted file mode 100644 index d12158e..0000000 --- a/test_util/global-teardown.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { deleteUserByEmail } from './deleteUser'; - -async function globalTeardown() { - const email = process.env.NEXT_PUBLIC_TEST_USER_EMAIL; - - if (!email) { - throw new Error('NEXT_PUBLIC_TEST_USER_EMAIL must be set'); - } - console.log('deleting user...'); - await deleteUserByEmail(email); -} - -export default globalTeardown; \ No newline at end of file diff --git a/tests/authenticated-page.setup.ts b/tests/authenticated-page.setup.ts new file mode 100644 index 0000000..d901c71 --- /dev/null +++ b/tests/authenticated-page.setup.ts @@ -0,0 +1,24 @@ +import { test } from "@playwright/test"; + +const AUTH_USER_FILE = "./storageState.json"; +const USER_EMAIL = process.env.NEXT_PUBLIC_TEST_USER_EMAIL!; +const USER_PASSWORD = process.env.NEXT_PUBLIC_TEST_USER_PASSWORD!; + +test("Setup: Authenticate via login page and store session", async ({ page }) => { + if (!USER_EMAIL || !USER_PASSWORD) { + throw new Error("NEXT_PUBLIC_TEST_USER_EMAIL and NEXT_PUBLIC_TEST_USER_PASSWORD must be set"); + } + + await page.goto("http://localhost:3000/auth"); + // fill input with id = email + await page.fill('input[id="email"]', USER_EMAIL); + await page.fill('input[id="password"]', USER_PASSWORD); + await page.click('button[id="login"]'); + + await page.waitForURL("http://localhost:3000/"); + console.log("Login successful!"); + + await page.context().storageState({ path: AUTH_USER_FILE }); + + console.log("Storage state saved to:", AUTH_USER_FILE); +}); diff --git a/tests/deprecated/test-depre-admin-approve-business.spec.ts b/tests/deprecated/test-depre-admin-approve-business.spec.ts new file mode 100644 index 0000000..ffae873 --- /dev/null +++ b/tests/deprecated/test-depre-admin-approve-business.spec.ts @@ -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); +// }); diff --git a/tests/test-businesses.spec.ts b/tests/deprecated/test-depre-businesses.spec.ts similarity index 98% rename from tests/test-businesses.spec.ts rename to tests/deprecated/test-depre-businesses.spec.ts index 39919ce..bf2816f 100644 --- a/tests/test-businesses.spec.ts +++ b/tests/deprecated/test-depre-businesses.spec.ts @@ -1,22 +1,22 @@ // import { test, expect } from "@playwright/test"; -// + // test.use({ // storageState: "./storageState.json", // }); -// + // test("Test search businesses", async ({ page }) => { // await page.goto("http://127.0.0.1:3000/"); // await page.getByLabel("Main").getByRole("img").click(); -// + // const businessInput = page.getByPlaceholder("Enter business name..."); // await expect(businessInput).toBeVisible(); // await businessInput.fill("Project Blackwell"); // await businessInput.press("Enter"); -// + // const heading = page.getByRole("heading", { name: "Project Blackwell" }); // await expect(heading).toBeVisible(); // await heading.click(); -// + // const fundSection = page.locator("div").filter({ hasText: /^Project Blackwell$/ }); // await expect(fundSection).toBeVisible(); // await fundSection.click(); diff --git a/tests/deprecated/test-depre-project-apply.spec.ts b/tests/deprecated/test-depre-project-apply.spec.ts new file mode 100644 index 0000000..71ae563 --- /dev/null +++ b/tests/deprecated/test-depre-project-apply.spec.ts @@ -0,0 +1,39 @@ +// import { test } from "@playwright/test"; +// import { selectFirstOption } from "./helpers/dropdownUtils"; +// import path from "path"; + +// test.use({ +// storageState: "./storageState.json", +// }); + +// test("test", async ({ page }) => { +// await page.goto("http://localhost:3000/"); +// await page.getByRole("button", { name: "Projects" }).hover(); +// await page.getByRole("link", { name: "Projects Start your new" }).click(); + +// const projectName = page.locator("#projectName"); +// await projectName.pressSequentially("DummyTester"); +// await projectName.click(); + +// const img = path.join(__dirname, "mockup", "1x1.png"); +// await page.locator("#projectLogo").click(); +// await page.locator("#projectLogo").setInputFiles(img); +// await page.locator("#projectPhotos").click(); +// await page.locator("#projectPhotos").setInputFiles(img); + +// const projectTypeButton = page.locator("button").filter({ hasText: "Select a Project type" }); +// await selectFirstOption(page, projectTypeButton); + +// await page.locator("#shortDescription").fill("0123456789"); +// await page.getByPlaceholder("https:// ").fill("https://www.test.md"); +// await page.getByPlaceholder("$ 500").fill("499"); +// await page.getByPlaceholder("$ 1,000,000").fill("99999999"); +// await page.locator("#deadline").fill("2024-11-29T21:19"); + +// const tag = page.getByRole("combobox").nth(1); +// await selectFirstOption(page, tag); + +// await projectName.pressSequentially("1234"); + +// await page.getByRole("button", { name: "Submit application" }).click(); +// }); diff --git a/tests/global-setup.ts b/tests/global-setup.ts new file mode 100644 index 0000000..3944f6c --- /dev/null +++ b/tests/global-setup.ts @@ -0,0 +1,53 @@ +import { FullConfig } from "@playwright/test"; +import { createClient } from "@supabase/supabase-js"; + +async function globalSetup(config: FullConfig) { + // eslint-disable-next-line no-unused-vars + const { baseURL, storageState } = config.projects[0].use; + console.log("setting up..."); + const email = process.env.NEXT_PUBLIC_TEST_USER_EMAIL; + const password = process.env.NEXT_PUBLIC_TEST_USER_PASSWORD; + const project_url = process.env.NEXT_PUBLIC_SUPABASE_URL; + const service_role_key = process.env.SUPABASE_SERVICE_ROLE_KEY; + + if (!email || !password) { + throw new Error("NEXT_PUBLIC_TEST_USER_EMAIL and NEXT_PUBLIC_TEST_USER_PASSWORD must be set"); + } + + if (!project_url || !service_role_key) { + throw new Error("NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY must be set"); + } + + const supabase = createClient(project_url, service_role_key); + const { error } = await supabase.auth.admin.createUser({ + email, + password, + email_confirm: true, + }); + + if (error != null) { + console.error("Error details:", error); + throw new Error(`Sign-up failed: ${error.message}`); + } + + console.log("User signed up successfully"); + + // const browser = await firefox.launch(); + // const page = await browser.newPage(); + + // await page.goto(baseURL + "/auth"); + // await page.fill("id=email", email); + // await page.fill("id=password", password); + // await page.click("id=login"); + + // await page.context().storageState({ path: storageState as string }); + // // show the storage state and context + // const storage = await page.context().storageState(); + // console.log("storage", storage); + // const context = page.context(); + // console.log("context", context); + // console.log("setup done"); + // await browser.close(); +} + +export default globalSetup; diff --git a/tests/global-teardown.ts b/tests/global-teardown.ts new file mode 100644 index 0000000..bede903 --- /dev/null +++ b/tests/global-teardown.ts @@ -0,0 +1,13 @@ +import { deleteUserByEmail } from "../test_util/deleteUser"; + +async function globalTeardown() { + const email = process.env.NEXT_PUBLIC_TEST_USER_EMAIL; + + if (!email) { + throw new Error("NEXT_PUBLIC_TEST_USER_EMAIL must be set"); + } + console.log("deleting user..."); + await deleteUserByEmail(email); +} + +export default globalTeardown; diff --git a/tests/test-01-business-apply.spec.ts b/tests/test-01-business-apply.spec.ts index 25908c4..b844d11 100644 --- a/tests/test-01-business-apply.spec.ts +++ b/tests/test-01-business-apply.spec.ts @@ -1,27 +1,91 @@ +// import { expect, test } from "@playwright/test"; +// import { selectFirstOption } from "./helpers/dropdownUtils"; +// import mockData from "./assets/mockData.json"; +// import { searchBusiness } from "./helpers/searchUtils"; +// import fs from "fs"; + +// const AUTH_USER_FILE = "./storageState.json"; +// const SUPABASE_APP_ID = process.env.PROJECT_ID!; + +// test("Submit a business application and search for it", async ({ page, context }) => { +// const session = JSON.parse(fs.readFileSync(AUTH_USER_FILE, "utf-8")); + +// await context.addInitScript( +// (data) => { +// localStorage.setItem(`sb-${data.appId}-auth-token`, JSON.stringify(data.session)); +// }, +// { session, appId: SUPABASE_APP_ID } +// ); + +// await page.goto("http://localhost:3000/"); + +// 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(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(mockData.company.url); +// await selectFirstOption(page, page.locator("button").filter({ hasText: "Select" })); +// 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); +// }); + 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"; +import fs from "fs"; -test("test", async ({ page }) => { - await loginUtils(page, "user"); - await page.getByRole("button", { name: "Businesses" }).hover(); - await page.getByRole("link", { name: "Business Apply to raise on on" }).click(); +const AUTH_USER_FILE = "./storageState.json"; +const SUPABASE_APP_ID = process.env.PROJECT_ID!; - 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(mockData.company.raised); +test("Check visibility of elements on the business application page", async ({ page, context }) => { + const session = JSON.parse(fs.readFileSync(AUTH_USER_FILE, "utf-8")); + + await context.addInitScript( + (data) => { + localStorage.setItem(`sb-${data.appId}-auth-token`, JSON.stringify(data.session)); + }, + { session, appId: SUPABASE_APP_ID } + ); + + await page.goto("http://localhost:3000/business/apply"); + + await expect(page.locator('button:has-text("Select an industry")')).toBeVisible(); + await page.locator("#companyName").click(); + + await expect(page.locator('button:has-text("Select a country")')).toBeVisible(); + await expect(page.getByPlaceholder("$")).toBeVisible(); + await expect(page.getByRole("button", { name: "Yes" }).first()).toBeVisible(); + await expect(page.getByPlaceholder("https:// ")).toBeVisible(); + await expect(page.locator("#companyName")).toBeVisible(); + await expect(page.getByRole("button", { name: "Submit application" })).toBeVisible(); + + await page.locator("#companyName").fill("Hello Company"); + await page.locator("button").filter({ hasText: "Select a country" }).click(); + await page.getByLabel("Afghanistan").getByText("Afghanistan").click(); + await page.locator("button").filter({ hasText: "Select an industry" }).click(); + await page.getByLabel("LLC").getByText("LLC").click(); + await page.getByPlaceholder("$").click(); + await page.getByPlaceholder("$").fill("1000000"); 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(mockData.company.url); - await selectFirstOption(page, page.locator("button").filter({ hasText: "Select" })); - 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 page.getByPlaceholder("https:// ").click(); + await page.getByPlaceholder("https:// ").fill("https://example.com.md"); + await page.locator("button").filter({ hasText: "Select" }).click(); + await page.getByLabel("N/A").click(); - await searchBusiness(page, mockData.company.name); + await page.getByRole("button", { name: "Submit application" }).click(); + + const successLabel = page.getByLabel("success"); + await expect(successLabel).toBeVisible(); + await successLabel.click(); }); diff --git a/tests/test-02-admin-approve-business.spec.ts b/tests/test-02-admin-approve-business.spec.ts deleted file mode 100644 index 2df819e..0000000 --- a/tests/test-02-admin-approve-business.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -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); -}); diff --git a/tests/test-filter-with-tags.spec.ts b/tests/test-02-filter-with-tags.spec.ts similarity index 62% rename from tests/test-filter-with-tags.spec.ts rename to tests/test-02-filter-with-tags.spec.ts index 82a4170..dd7bf69 100644 --- a/tests/test-filter-with-tags.spec.ts +++ b/tests/test-02-filter-with-tags.spec.ts @@ -1,42 +1,68 @@ // import { test, expect } from '@playwright/test'; -// + // test.use({ // storageState: './storageState.json' // }); -// + // test('Test filter with tags', async ({ page }) => { // await page.goto('http://127.0.0.1:3000/'); -// + // // Start Investing // await page.getByRole('button', { name: 'Start Investing' }).click(); -// + // // Filter by AI tag // await page.locator('button').filter({ hasText: 'Tags' }).click(); // await page.getByLabel('AI', { exact: true }).click(); // const aiTag = page.locator('span#tag', { hasText: 'AI' }); // await expect(aiTag).toBeVisible(); -// + // // Filter by Technology tag // await page.locator('button').filter({ hasText: 'AI' }).click(); // await page.getByLabel('Technology').click(); // const techTag = page.locator('span#tag', { hasText: 'Technology' }); // await expect(techTag).toBeVisible(); -// + // // Filter by Consumer Electronics tag // await page.locator('button').filter({ hasText: 'Technology' }).click(); // await page.getByLabel('Consumer Electronics').click(); // const consumerElectronicsTag = page.locator('span#tag', { hasText: 'Consumer Electronics' }); // await expect(consumerElectronicsTag).toBeVisible(); -// + // // Filter by Software tag // await page.locator('button').filter({ hasText: 'Consumer Electronics' }).click(); // await page.getByLabel('Software').click(); // const softwareTag = page.locator('span#tag', { hasText: 'Software' }); // await expect(softwareTag).toBeVisible(); -// + // // Filter by Internet tag // await page.locator('button').filter({ hasText: 'Software' }).click(); // await page.getByLabel('Internet').click(); // const internetTag = page.locator('span#tag', { hasText: 'Internet' }); // await expect(internetTag).toBeVisible(); // }); + +import { test, expect } from "@playwright/test"; + +test.use({ + storageState: "./storageState.json", +}); + +test("Test filter with tags", async ({ page }) => { + await page.goto("http://localhost:3000/"); + await page.getByRole("link", { name: "View all" }).click(); + await page.getByPlaceholder("Search projects").fill("Chat"); + await page.getByPlaceholder("Search projects").press("Enter"); + + const chatGPTCard = page.getByRole("link", { name: "Card image ChatGPT ChatGPT is" }); + await expect(chatGPTCard).toBeVisible(); + + await page.locator("button").filter({ hasText: "All Types" }).click(); + await page.getByLabel("All Types").getByText("All Types").click(); + + await page.locator("button").filter({ hasText: "All Statuses" }).click(); + await page.getByLabel("All Statuses").getByText("All Statuses").click(); + + await page.locator("button").filter({ hasText: "All Tags" }).click(); + await page.getByLabel("All Tags").getByText("All Tags").click(); + await page.getByPlaceholder("Search projects").click(); +}); diff --git a/tests/test-Investment-process .spec.ts b/tests/test-03-Investment-process .spec.ts similarity index 74% rename from tests/test-Investment-process .spec.ts rename to tests/test-03-Investment-process .spec.ts index 9407590..e0bd14d 100644 --- a/tests/test-Investment-process .spec.ts +++ b/tests/test-03-Investment-process .spec.ts @@ -104,4 +104,43 @@ // async function closeErrorDialog(page: Page): Promise { // await page.getByRole('button', { name: 'Close' }).first().click(); // } -// }); \ No newline at end of file +// }); + +import { test, expect } from "@playwright/test"; + +test.use({ + storageState: "./storageState.json", +}); + +test("Investment process test", async ({ page }) => { + await page.goto("http://localhost:3000/"); + + await page.getByRole("link", { name: "Card image Project Blackwell" }).click(); + await page.getByRole("link", { name: "Invest in Project Blackwell" }).click(); + + await page.getByPlaceholder("min $").click(); + await page.getByPlaceholder("min $").fill("99"); + + await page.getByRole("checkbox").first().check(); + await page + .locator("div") + .filter({ hasText: /^I have read and accept the terms of investment\.$/ }) + .getByRole("checkbox") + .check(); + await page.getByRole("button", { name: "Proceed to Payment" }).click(); + + const paymentInfo = page.getByLabel("Payment Information"); + await expect(paymentInfo).toBeVisible(); + + const cardNumber = page.getByText("Card Number"); + await expect(cardNumber).toBeVisible(); + + const expirationDate = page.getByText("Expiration Date"); + await expect(expirationDate).toBeVisible(); + + const cvc = page.getByText("CVC"); + await expect(cvc).toBeVisible(); + + const cancelButton = page.getByRole("button", { name: "Cancel" }); + await expect(cancelButton).toBeVisible(); +}); diff --git a/tests/test-03-project-apply.spec.ts b/tests/test-03-project-apply.spec.ts deleted file mode 100644 index e8653a6..0000000 --- a/tests/test-03-project-apply.spec.ts +++ /dev/null @@ -1,36 +0,0 @@ -// import { test } from '@playwright/test'; -// import { selectFirstOption } from './helpers/dropdownUtils'; -// import { login } from './helpers/login'; -// import path from 'path'; -// -// test('test', async ({ page }) => { -// await login(page,'user') -// await page.getByRole('button', { name: 'Projects' }).hover(); -// await page.getByRole('link', { name: 'Projects Start your new' }).click(); -// -// const projectName = page.locator('#projectName') -// await projectName.pressSequentially('DummyTester'); -// await projectName.click(); -// -// const img = path.join(__dirname, 'mockup', '1x1.png'); -// await page.locator('#projectLogo').click(); -// await page.locator('#projectLogo').setInputFiles(img); -// await page.locator('#projectPhotos').click(); -// await page.locator('#projectPhotos').setInputFiles(img); -// -// const projectTypeButton = page.locator('button').filter({ hasText: 'Select a Project type' }); -// await selectFirstOption(page, projectTypeButton); -// -// await page.locator('#shortDescription').fill('0123456789'); -// await page.getByPlaceholder('https:// ').fill('https://www.test.md'); -// await page.getByPlaceholder('$ 500').fill('499'); -// await page.getByPlaceholder('$ 1,000,000').fill('99999999'); -// await page.locator('#deadline').fill('2024-11-29T21:19'); -// -// const tag = page.getByRole('combobox').nth(1); -// await selectFirstOption(page, tag); -// -// await projectName.pressSequentially('1234'); -// -// await page.getByRole('button', { name: 'Submit application' }).click(); -// }); diff --git a/tests/test-04-admin-page.spec.ts b/tests/test-04-admin-page.spec.ts new file mode 100644 index 0000000..136d86f --- /dev/null +++ b/tests/test-04-admin-page.spec.ts @@ -0,0 +1,34 @@ +import { test, expect } from "@playwright/test"; + +const ADMIN_USERNAME = process.env.NEXT_PUBLIC_ADMIN_EMAIL!; +const ADMIN_PASSWORD = process.env.NEXT_PUBLIC_ADMIN_PASSWORD!; + +test("Test admin page funtionality", async ({ page }) => { + if (!ADMIN_USERNAME || !ADMIN_PASSWORD) { + throw new Error("NEXT_PUBLIC_TEST_USER_EMAIL and NEXT_PUBLIC_TEST_USER_PASSWORD must be set"); + } + + await page.goto("http://localhost:3000/"); + await page.getByRole("button", { name: "profile" }).click(); + await page.getByRole("button", { name: "Logout" }).click(); + await page.getByRole("button", { name: "Login" }).click(); + await page.reload(); + + const emailInput = page.locator('input[id="email"]'); + const passwordInput = page.locator('input[id="password"]'); + const loginButton = page.locator('button[id="login"]'); + + await emailInput.fill(ADMIN_USERNAME); + await passwordInput.fill(ADMIN_PASSWORD); + await loginButton.click(); + + await expect(page.getByRole("button", { name: "profile" })).toBeVisible(); + await page.getByRole("button", { name: "profile" }).click(); + await expect(page.getByRole("link", { name: "Admin" })).toBeVisible(); + await page.getByRole("link", { name: "Admin" }).click(); + await page.locator("html").click(); + await page.getByRole("button", { name: "Go to Business Application" }).click(); + + await expect(page.getByText("Admin Page")).toBeVisible(); + await expect(page.getByRole("cell", { name: "Hello Company" })).toBeVisible(); +}); diff --git a/tests/test-dashboard-visibility.spec.ts b/tests/test-dashboard-visibility.spec.ts deleted file mode 100644 index bea54fa..0000000 --- a/tests/test-dashboard-visibility.spec.ts +++ /dev/null @@ -1,26 +0,0 @@ -// import { test, expect } from '@playwright/test'; -// test.use({ -// storageState: './storageState.json' -// }); -// -// test('Test dashboard visibility', async ({ page }) => { -// await page.goto('http://127.0.0.1:3000/dashboard'); -// -// const dashboardHeading = page.locator('h2', { hasText: 'Dashboard' }); -// await expect(dashboardHeading).toBeVisible(); -// -// const profileViewHeading = page.locator('h3', { hasText: 'Profile Views' }); -// await expect(profileViewHeading).toBeVisible(); -// -// const totalFollowerHeading = page.locator('h3', { hasText: 'Total Followers' }); -// await expect(totalFollowerHeading).toBeVisible(); -// -// const fundsRaisedHeading = page.locator('h3', { hasText: 'Total Funds Raised' }); -// await expect(fundsRaisedHeading).toBeVisible(); -// -// const overviewHeading = page.locator('h3', { hasText: 'Overview' }); -// await expect(overviewHeading).toBeVisible(); -// -// const recentFundHeading = page.locator('h3', { hasText: 'Recent Funds' }); -// await expect(recentFundHeading).toBeVisible(); -// }); diff --git a/tests/test-depre-dashboard-visibility.spec.ts b/tests/test-depre-dashboard-visibility.spec.ts new file mode 100644 index 0000000..8c367bb --- /dev/null +++ b/tests/test-depre-dashboard-visibility.spec.ts @@ -0,0 +1,26 @@ +// import { test, expect } from "@playwright/test"; +// test.use({ +// storageState: "./storageState.json", +// }); + +// test("Test dashboard visibility", async ({ page }) => { +// await page.goto("http://127.0.0.1:3000/dashboard"); + +// const dashboardHeading = page.locator("h2", { hasText: "Dashboard" }); +// await expect(dashboardHeading).toBeVisible(); + +// const profileViewHeading = page.locator("h3", { hasText: "Profile Views" }); +// await expect(profileViewHeading).toBeVisible(); + +// const totalFollowerHeading = page.locator("h3", { hasText: "Total Followers" }); +// await expect(totalFollowerHeading).toBeVisible(); + +// const fundsRaisedHeading = page.locator("h3", { hasText: "Total Funds Raised" }); +// await expect(fundsRaisedHeading).toBeVisible(); + +// const overviewHeading = page.locator("h3", { hasText: "Overview" }); +// await expect(overviewHeading).toBeVisible(); + +// const recentFundHeading = page.locator("h3", { hasText: "Recent Funds" }); +// await expect(recentFundHeading).toBeVisible(); +// });