-
-
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.
devops: github actions for linting and unit tests
- Loading branch information
Linus Bolls
authored and
Linus Bolls
committed
May 31, 2024
1 parent
ec7a543
commit beca93e
Showing
8 changed files
with
2,235 additions
and
79 deletions.
There are no files selected for viewing
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,32 @@ | ||
name: Check Linting | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
pull_request: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run tests | ||
run: npm run lint-all |
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,32 @@ | ||
name: Run Unit Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run linting | ||
run: npm run test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
import useQuizState from './useQuizState'; | ||
|
||
describe('useQuizState', () => { | ||
it('initializes state correctly', () => { | ||
const chapterId = 1; // assuming chapter ID 1 exists | ||
const { result } = renderHook(() => useQuizState(chapterId)); | ||
|
||
expect(result.current.questionIdx).toBe(0); | ||
expect(result.current.selectedOptionId).toBeNull(); | ||
expect(result.current.showSolution).toBe(false); | ||
expect(result.current.checkAnswer).toBe(false); | ||
expect(result.current.showStartScreen).toBe(true); | ||
expect(result.current.showEndScreen).toBe(false); | ||
expect(result.current.numOfCorrectQuestions).toBe(0); | ||
// expect(Array.isArray(result.current.questionOrder)).toBe(true); | ||
// expect(result.current.questionOrder.length).toBeGreaterThan(0); // Assumes there are questions | ||
}); | ||
}); | ||
|
||
describe('Navigation between questions', () => { | ||
it('increments the question index by 1 on handleNextQuestion call', () => { | ||
const chapterId = 1; | ||
const { result } = renderHook(() => useQuizState(chapterId)); | ||
|
||
act(() => { | ||
result.current.handleNextQuestion(); | ||
}); | ||
|
||
expect(result.current.questionIdx).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('Option selection and scoring', () => { | ||
it('selects an option and increments score if the answer is correct', () => { | ||
const chapterId = 1; | ||
const { result } = renderHook(() => useQuizState(chapterId)); | ||
|
||
// Mocking the correct answer ID and the selection process | ||
const correctOptionId = 0; | ||
act(() => { | ||
result.current.selectOption(correctOptionId); | ||
result.current.incrementScore(correctOptionId, correctOptionId); | ||
}); | ||
|
||
expect(result.current.selectedOptionId).toBe(correctOptionId); | ||
expect(result.current.numOfCorrectQuestions).toBe(1); | ||
}); | ||
}); |
Oops, something went wrong.