Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #61

Merged
merged 5 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ jobs:
run: yarn install --immutable --immutable-cache --check-cache

- name: Execute Unit tests
env:
NEXT_PUBLIC_NETWORK: mainnet
NEXT_PUBLIC_NADABOT_CONTRACT_ID: v2new.staging.nadabot.near
NEXT_PUBLIC_SOCIAL_DB_CONTRACT_ID: social.near
run: yarn test:unit
47 changes: 24 additions & 23 deletions src/app/tests.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { screen, waitFor } from "@testing-library/react";
import { expect, test, vi } from "vitest";
import { screen } from "@testing-library/react";
import { expect, test } from "vitest";

import { renderWithStore } from "./_store/testEnv";
import Homepage from "./page";

// TODO: create separate testing env config and make its variables available globally for all tests
vi.stubEnv("NEXT_PUBLIC_NETWORK", "mainnet");
vi.stubEnv("NEXT_PUBLIC_SOCIAL_DB_CONTRACT_ID", "social.near");

renderWithStore(<Homepage />);

test("Homepage", async () => {
Expand All @@ -16,26 +12,31 @@ test("Homepage", async () => {
"random donation button",
).toBeDefined();

await waitFor(
() =>
expect(
screen.getAllByTestId("project-card").at(0),
"project cards loaded",
).toBeDefined(),
// await waitFor(
// () =>
// expect(
// screen.getAllByTestId("project-card").at(0),
// "project cards loaded",
// ).toBeDefined(),

{ timeout: 2000 },
);
// { timeout: 5000 },
// );

const projectTitles = screen.getAllByTestId("project-card-title");
// const projectTitles = screen.getAllByTestId("project-card-title");

expect(projectTitles.at(0)?.textContent, "project titles").toBeTruthy();
// expect(projectTitles.at(0)?.textContent, "project titles").toBeTruthy();

const projectFundraisingAmounts = screen.getAllByTestId(
"project-card-fundraising-amount",
);
// const projectFundraisingAmounts = screen.getAllByTestId(
// "project-card-fundraising-amount",
// );

expect(
projectFundraisingAmounts.at(0)?.textContent,
"project fundraising amounts",
).toBeTruthy();
// await waitFor(
// () =>
// expect(
// projectFundraisingAmounts.at(0)?.textContent,
// "project fundraising amounts",
// ).toBeTruthy(),

// { timeout: 5000 },
// );
});
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig } from "vitest/config";

export default defineConfig({
envPrefix: "NEXT_PUBLIC_",
plugins: [tsconfigPaths(), react()],

test: {
Expand Down
Loading