-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] Tests and corresponding GitHub action. #15
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
Open
muzam1l
wants to merge
4
commits into
main
Choose a base branch
from
tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,17 @@ | ||
| name: Test | ||
|
|
||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - uses: actions/setup-node@v2 | ||
| with: | ||
| node-version: 16 | ||
| - name: Install packages | ||
| run: | | ||
| yarn | ||
| - name: Run Test | ||
| run: yarn run test |
This file contains hidden or 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,61 @@ | ||
| import { customRender as render, screen } from "../test-utils"; | ||
| import Footer from "../components/Footer"; | ||
| import { RouterContext } from "next/dist/shared/lib/router-context"; | ||
|
|
||
| const mockRouter: any = { | ||
| basePath: "", | ||
| pathname: "/", | ||
| route: "/", | ||
| asPath: "/", | ||
| query: {}, | ||
| push: jest.fn(), | ||
| replace: jest.fn(), | ||
| reload: jest.fn(), | ||
| back: jest.fn(), | ||
| prefetch: jest.fn().mockResolvedValue(undefined), | ||
| beforePopState: jest.fn(), | ||
| events: { | ||
| on: jest.fn(), | ||
| off: jest.fn(), | ||
| emit: jest.fn(), | ||
| }, | ||
| isFallback: false, | ||
| }; | ||
|
|
||
| it("renders footer links", () => { | ||
| render( | ||
| <RouterContext.Provider value={mockRouter}> | ||
| <Footer /> | ||
| </RouterContext.Provider> | ||
| ); | ||
|
|
||
| const erc20Link = screen.getByRole("link", { | ||
| name: /\$VNL ERC-20 Contract on Etherscan/i, | ||
| }); | ||
| expect(erc20Link).toBeInTheDocument(); | ||
|
|
||
| const routerScanLink = screen.getByRole("link", { | ||
| name: /Vanilla Router on Etherscan/i, | ||
| }); | ||
| expect(routerScanLink).toBeInTheDocument(); | ||
|
|
||
| const daoScanLink = screen.getByRole("link", { | ||
| name: /VanillaDAO on Etherscan/i, | ||
| }); | ||
| expect(daoScanLink).toBeInTheDocument(); | ||
|
|
||
| const bountyLink = screen.getByRole("link", { | ||
| name: /Bug bounty/i, | ||
| }); | ||
| expect(bountyLink).toBeInTheDocument(); | ||
|
|
||
| const termsLink = screen.getByRole("link", { | ||
| name: /Terms of use/i, | ||
| }); | ||
| expect(termsLink).toBeInTheDocument(); | ||
|
|
||
| const privacyLink = screen.getByRole("link", { | ||
| name: /Privacy Policy/i, | ||
| }); | ||
| expect(privacyLink).toBeInTheDocument(); | ||
| }); |
This file contains hidden or 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,69 @@ | ||
| import { customRender as render, screen } from "../test-utils"; | ||
| import Home from "../pages/index"; | ||
|
|
||
| it("renders tag lines and links", () => { | ||
| render(<Home />); | ||
|
|
||
| const heading = screen.getByRole("heading", { | ||
| name: /Decentralized Asset Manager for Web3/i, | ||
| }); | ||
| expect(heading).toBeInTheDocument(); | ||
|
|
||
| const intro1 = screen.getByText( | ||
| "Vanilla is an on-chain investment pool managed by the best investors." | ||
| ); | ||
| expect(intro1).toBeInTheDocument(); | ||
|
|
||
| const earnLink = screen.getByRole("link", { | ||
| name: "Stake $JUICE to earn rewards", | ||
| }); | ||
| expect(earnLink).toBeInTheDocument(); | ||
|
|
||
| const investLink = screen.getByRole("link", { | ||
| name: "Invest in Vanilla Pool", | ||
| }); | ||
| expect(investLink).toBeInTheDocument(); | ||
|
|
||
| const getInformedHeading = screen.getByRole("heading", { | ||
| name: "GET INFORMED, WIN $JUICE", | ||
| level: 3, | ||
| }); | ||
| expect(getInformedHeading).toBeInTheDocument(); | ||
| // skipping sub-lines | ||
|
|
||
| const howItWorks = screen.getByRole("heading", { | ||
| name: "HOW VANILLA WORKS", | ||
| level: 3, | ||
| }); | ||
| expect(howItWorks).toBeInTheDocument(); | ||
|
|
||
| const faqLink = screen.getByRole("link", { | ||
| name: "Read the FAQ", | ||
| }); | ||
| expect(faqLink).toBeInTheDocument(); | ||
|
|
||
| // skipping stake and invest headlines | ||
| const stakingLink = screen.getByRole("link", { | ||
| name: "Start staking", | ||
| }); | ||
| expect(stakingLink).toBeInTheDocument(); | ||
|
|
||
| const investLink2 = screen.getByRole("link", { | ||
| name: "Invest in pool", | ||
| }); | ||
| expect(investLink2).toBeInTheDocument(); | ||
|
|
||
| const joinCommunity = screen.getByTestId("join-community"); | ||
| // .getByText("JOIN THE COMMUNITY"); | ||
| expect(joinCommunity).toHaveTextContent(/JOIN\s?THE COMMUNITY/); | ||
|
|
||
| const joinDiscussionLink = screen.getByRole("link", { | ||
| name: "Join the discussion", | ||
| }); | ||
| expect(joinDiscussionLink).toBeInTheDocument(); | ||
|
|
||
| const daoLink = screen.getByRole("link", { | ||
| name: "Read about VanillaDAO", | ||
| }); | ||
| expect(daoLink).toBeInTheDocument(); | ||
| }); |
This file contains hidden or 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,17 @@ | ||
| const nextJest = require("next/jest"); | ||
|
|
||
| const createJestConfig = nextJest({ | ||
| // Provide the path to your Next.js app to load next.config.js and .env files in your test environment | ||
| dir: "./", | ||
| }); | ||
|
|
||
| // Add any custom config to be passed to Jest | ||
| const customJestConfig = { | ||
| setupFilesAfterEnv: ["<rootDir>/jest.setup.js"], | ||
| // if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work | ||
| moduleDirectories: ["node_modules", "<rootDir>/"], | ||
| testEnvironment: "jest-environment-jsdom", | ||
| }; | ||
|
|
||
| // createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async | ||
| module.exports = createJestConfig(customJestConfig); |
This file contains hidden or 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 @@ | ||
| import "@testing-library/jest-dom/extend-expect"; |
This file contains hidden or 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 hidden or 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 hidden or 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,34 @@ | ||
| import React, { FC, ReactElement } from "react"; | ||
| import { render, RenderOptions } from "@testing-library/react"; | ||
| // import { Provider } from "urql"; | ||
| import { ThemeProvider } from "next-themes"; | ||
| import { darkTheme } from "../stitches.config"; | ||
| import "./mocks"; | ||
| import "@testing-library/jest-dom"; | ||
| // import { fetchingState } from "./urql-states"; | ||
|
|
||
| export const AllTheProviders: FC = ({ children }) => { | ||
| return ( | ||
| // <Provider value={fetchingState as any}> | ||
| <ThemeProvider | ||
| attribute="class" | ||
| defaultTheme="dark" | ||
| enableSystem={false} | ||
| value={{ | ||
| dark: darkTheme.className, | ||
| light: "light", | ||
| }} | ||
| > | ||
| {children} | ||
| </ThemeProvider> | ||
| // </Provider> | ||
| ); | ||
| }; | ||
|
|
||
| const customRender = ( | ||
| ui: ReactElement, | ||
| options?: Omit<RenderOptions, "wrapper"> | ||
| ) => render(ui, { wrapper: AllTheProviders, ...options }); | ||
|
|
||
| export { customRender }; | ||
| export * from "@testing-library/react"; |
This file contains hidden or 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,24 @@ | ||
| import { loadEnvConfig } from "@next/env"; | ||
|
|
||
| const setupEnv = async () => { | ||
| const projectDir = process.cwd(); | ||
| loadEnvConfig(projectDir); | ||
| }; | ||
|
|
||
| setupEnv() | ||
|
|
||
| Object.defineProperty(window, "matchMedia", { | ||
| writable: true, | ||
| value: jest.fn().mockImplementation((query) => ({ | ||
| matches: false, | ||
| media: query, | ||
| onchange: null, | ||
| addListener: jest.fn(), // deprecated | ||
| removeListener: jest.fn(), // deprecated | ||
| addEventListener: jest.fn(), | ||
| removeEventListener: jest.fn(), | ||
| dispatchEvent: jest.fn(), | ||
| })), | ||
| }); | ||
|
|
||
| export const mocked = true; |
This file contains hidden or 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,26 @@ | ||
| import { CombinedError } from "urql"; | ||
| import { never, fromValue } from "wonka"; | ||
|
|
||
| export const fetchingState = { | ||
| executeQuery: () => never, | ||
| }; | ||
| export const responseState = { | ||
| executeQuery: () => | ||
| fromValue({ | ||
| data: { | ||
| posts: [ | ||
| { id: 1, title: "Post title", content: "This is a post" }, | ||
| { id: 3, title: "Final post", content: "Final post here" }, | ||
| ], | ||
| }, | ||
| }), | ||
| }; | ||
|
|
||
| export const errorState = { | ||
| executeQuery: () => | ||
| fromValue({ | ||
| error: new CombinedError({ | ||
| networkError: Error("something went wrong!"), | ||
| }), | ||
| }), | ||
| }; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not utils?