-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Motivation adds test for hooks also sets up workflows for PRs ## Issues closed closes #22
- Loading branch information
Showing
16 changed files
with
396 additions
and
142 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 @@ | ||
name: Client Tests | ||
|
||
on: | ||
push: | ||
branches: [ alpha, beta, rc, main ] | ||
pull_request: | ||
types: [ opened, synchronize ] | ||
branches: [ alpha, beta, rc, main ] | ||
|
||
jobs: | ||
test-client: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Run Client tests | ||
run: npm run test:client |
This file contains 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 @@ | ||
name: e2e Tests | ||
|
||
on: | ||
push: | ||
branches: [ alpha, beta, rc, main ] | ||
pull_request: | ||
types: [opened, synchronize] | ||
branches: [ alpha, beta, rc, main ] | ||
|
||
jobs: | ||
test-e2e: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Run e2e tests | ||
run: npm run test:e2e |
This file contains 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 @@ | ||
name: Electron Tests | ||
|
||
on: | ||
push: | ||
branches: [ alpha, beta, rc, main ] | ||
pull_request: | ||
types: [opened, synchronize] | ||
branches: [ alpha, beta, rc, main ] | ||
|
||
jobs: | ||
test-electron: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Run Electron tests | ||
run: npm run test:electron |
This file contains 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 |
---|---|---|
|
@@ -27,3 +27,4 @@ live-canvas-generate-image-output.png.tmp.png | |
|
||
# test | ||
coverage | ||
playwright-report |
This file contains 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,41 @@ | ||
import { defaults } from "jest-config"; | ||
|
||
// Adjust the import path to your tsconfig.json file | ||
|
||
const jestConfig = { | ||
...defaults, | ||
roots: ["<rootDir>/src/client"], | ||
testMatch: ["**/?(*.)test.ts?(x)"], | ||
transform: { | ||
"^.+\\.(t|j)sx?$": [ | ||
"@swc/jest", | ||
{ | ||
jsc: { | ||
transform: { | ||
react: { | ||
runtime: "automatic", | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
moduleNameMapper: { | ||
"@/(.*)": "<rootDir>/src/client/$1", | ||
"#/(.*)": "<rootDir>/src/shared/$1", | ||
}, | ||
collectCoverage: true, | ||
coverageDirectory: "./coverage", | ||
coverageProvider: "v8", | ||
coverageReporters: ["lcov", "text", "json"], | ||
coverageThreshold: { | ||
global: { | ||
lines: 80, | ||
}, | ||
}, | ||
testEnvironment: "jsdom", | ||
transformIgnorePatterns: ["/node_modules/"], | ||
extensionsToTreatAsEsm: [".ts", ".tsx"], | ||
}; | ||
|
||
export default jestConfig; |
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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 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,38 @@ | ||
import type { Mode } from "@mui/system/cssVars/useCurrentColorScheme"; | ||
import { renderHook, act } from "@testing-library/react"; | ||
|
||
import { useSsrColorScheme } from "../color-scheme"; | ||
|
||
function createMockUseColorScheme(initialMode = "system") { | ||
let internalMode = initialMode; | ||
|
||
return jest.fn().mockImplementation(() => ({ | ||
mode: internalMode, | ||
setMode(newMode: Mode) { | ||
internalMode = newMode; | ||
}, | ||
})); | ||
} | ||
|
||
jest.mock("@mui/joy/styles", () => ({ | ||
useColorScheme: createMockUseColorScheme(), | ||
})); | ||
|
||
describe("useSsrColorScheme", () => { | ||
it("should set initial mode to 'system'", () => { | ||
const { result } = renderHook(() => useSsrColorScheme()); | ||
expect(result.current.mode).toBe("system"); | ||
}); | ||
|
||
it("should change mode when setMode is called", () => { | ||
const { result, rerender } = renderHook(() => useSsrColorScheme()); // Get the rerender function | ||
|
||
act(() => { | ||
result.current.setMode("light"); | ||
}); | ||
|
||
rerender(); | ||
|
||
expect(result.current.mode).toBe("light"); | ||
}); | ||
}); |
This file contains 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,30 @@ | ||
// UseColumns.test.tsx | ||
import { extendTheme, ThemeProvider } from "@mui/joy/styles"; | ||
import { render } from "@testing-library/react"; | ||
import React from "react"; | ||
import "@testing-library/jest-dom"; | ||
|
||
import { useColumns } from "../columns"; // Adjust the import path as necessary | ||
|
||
// Mock component to utilize the useColumns hook | ||
function MockComponent({ xs, sm, md, lg }: { xs: number; sm: number; md: number; lg: number }) { | ||
const columns = useColumns({ xs, sm, md, lg }); | ||
return <div data-testid="column-count">{columns}</div>; | ||
} | ||
|
||
describe("useColumns", () => { | ||
const theme = extendTheme(); // Use your custom theme if you have one | ||
|
||
function renderWithTheme(properties: { xs: number; sm: number; md: number; lg: number }) { | ||
return render( | ||
<ThemeProvider theme={theme}> | ||
<MockComponent {...properties} /> | ||
</ThemeProvider> | ||
); | ||
} | ||
|
||
it("should return xs value for initial render", () => { | ||
const { getByTestId } = renderWithTheme({ xs: 2, sm: 4, md: 6, lg: 8 }); | ||
expect(getByTestId("column-count")).toHaveTextContent("2"); | ||
}); | ||
}); |
Oops, something went wrong.