adding unit test for rendering site and fixing LP export issue #46
@@ -0,0 +1,26 @@
|
|||||||
|
name: Run Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["main"]
|
||||||
|
workflow_dispatch:
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm install
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: npm run test:ci
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||||
|
import '@testing-library/jest-dom';
|
||||||
|
import Home from "../src/app/page";
|
||||||
|
|
||||||
|
jest.mock('../src/app/scripts', () => ({
|
||||||
|
customLog: jest.fn(),
|
||||||
|
customLogClear: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock('../src/solver/glpk.min.js', () => ({
|
||||||
|
LPF_ECOND: 2,
|
||||||
|
}));
|
||||||
|
|
||||||
|
test('render home page', () => {
|
||||||
|
// render website
|
||||||
|
render(<Home />);
|
||||||
|
|
||||||
|
// check if text is in document
|
||||||
|
const headingElement = screen.getByText(/OR-Tool/i); // text search in document
|
||||||
|
expect(headingElement).toBeInTheDocument();
|
||||||
|
});
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
const nextJest = require('next/jest');
|
||||||
|
|
||||||
|
const createJestConfig = nextJest({
|
||||||
|
dir: './',
|
||||||
|
});
|
||||||
|
|
||||||
|
const customJestConfig = {
|
||||||
|
testEnvironment: 'jest-environment-jsdom',
|
||||||
|
moduleNameMapper: {
|
||||||
|
'^@/(.*)$': '<rootDir>/src/$1',
|
||||||
|
},
|
||||||
|
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = createJestConfig(customJestConfig);
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
import '@testing-library/jest-dom';
|
||||||
Generated
+4277
-22
File diff suppressed because it is too large
Load Diff
+8
-1
@@ -6,13 +6,16 @@
|
|||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint"
|
"lint": "next lint",
|
||||||
|
"test": "jest --watchAll",
|
||||||
|
"test:ci": "jest --ci --coverage"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"glpk.js": "^4.0.2",
|
"glpk.js": "^4.0.2",
|
||||||
"i18n": "^0.15.1",
|
"i18n": "^0.15.1",
|
||||||
"i18next": "^23.15.2",
|
"i18next": "^23.15.2",
|
||||||
"i18next-browser-languagedetector": "^8.0.0",
|
"i18next-browser-languagedetector": "^8.0.0",
|
||||||
|
"jest-environment-jsdom": "^29.7.0",
|
||||||
"next": "14.2.11",
|
"next": "14.2.11",
|
||||||
"next-i18next": "^15.3.1",
|
"next-i18next": "^15.3.1",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
@@ -22,11 +25,15 @@
|
|||||||
"reactjs-popup": "^2.0.6"
|
"reactjs-popup": "^2.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@testing-library/jest-dom": "^6.5.0",
|
||||||
|
"@testing-library/react": "^16.0.1",
|
||||||
|
"@testing-library/user-event": "^14.5.2",
|
||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/react": "^18",
|
"@types/react": "^18",
|
||||||
"@types/react-dom": "^18",
|
"@types/react-dom": "^18",
|
||||||
"eslint": "^8",
|
"eslint": "^8",
|
||||||
"eslint-config-next": "14.2.11",
|
"eslint-config-next": "14.2.11",
|
||||||
|
"jest": "^29.7.0",
|
||||||
"postcss": "^8",
|
"postcss": "^8",
|
||||||
"tailwindcss": "^3.4.1",
|
"tailwindcss": "^3.4.1",
|
||||||
"typescript": "^5"
|
"typescript": "^5"
|
||||||
|
|||||||
+3
-3
@@ -8,7 +8,7 @@ import { start } from "repl";
|
|||||||
import text from "./lang"
|
import text from "./lang"
|
||||||
|
|
||||||
// custom log so we can append the output dynamically
|
// custom log so we can append the output dynamically
|
||||||
function customLog(input: string) {
|
export function customLog(input: string) {
|
||||||
// get language
|
// get language
|
||||||
const lang = (document.getElementById('language_current') as HTMLSelectElement)?.value;
|
const lang = (document.getElementById('language_current') as HTMLSelectElement)?.value;
|
||||||
|
|
||||||
@@ -25,14 +25,14 @@ function customLog(input: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function customLogClear() {
|
export function customLogClear() {
|
||||||
const outElement = document.getElementById('out');
|
const outElement = document.getElementById('out');
|
||||||
if (outElement) {
|
if (outElement) {
|
||||||
outElement.innerHTML = "";
|
outElement.innerHTML = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTranslation(input: string) {
|
export function getTranslation(input: string) {
|
||||||
// get language
|
// get language
|
||||||
const lang = (document.getElementById('language_current') as HTMLSelectElement)?.value;
|
const lang = (document.getElementById('language_current') as HTMLSelectElement)?.value;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user