Skip to content

Commit

Permalink
devops: github actions for linting and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Linus Bolls authored and Linus Bolls committed May 31, 2024
1 parent ec7a543 commit beca93e
Show file tree
Hide file tree
Showing 8 changed files with 2,235 additions and 79 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/check-linting.yml
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
32 changes: 32 additions & 0 deletions .github/workflows/run-unit-tests.yml
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Logicola Mascot](/malikpiara/logicola/public/mascot.png)
![Logicola Mascot](public/mascot.png)

LogiCola is an instructional program that goes with Gensler's Introduction to Logic (Routledge Press). Since Harry Gensler, the original creator has passed away, I decided to create a new version to preserve an important learning resource and honour his legacy.

Expand Down
35 changes: 0 additions & 35 deletions app/informal/definitions/[...exercise]/page.tsx

This file was deleted.

50 changes: 50 additions & 0 deletions components/quiz/useQuizState.test.ts
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);
});
});
Loading

0 comments on commit beca93e

Please sign in to comment.