9ad9ec1a46
* Initial Push
Inititial project state
* Static demo version
* static demo site - added variables
a
* first_implementation
* Updated UI, Improved Style to be more "Reactly", added Functionality
* add parsing functions
* change folder
* Import/Export Prototype
* Adding "reactjs-popup" to package,json
* Adding GLPK source
* Rough implementation of solver + example
* Show solution in output
* example 2 + popup lib
* removing import button
This feature won't be needed in this state of the project and might come back later. Right now it serves no functional purpose.
* Removing "Popout" button
This feature won't be needed in this state of the project and might come back later. Right now it serves no functional purpose.
* Updating Logs
Now the site displays all logs created with customLog(STRING). Logs can be cleared with customLogClear();
* Adding walltime
Can be called using:
Start:
function walltimeStart() {
returns Date.now();
Stop:
function walltimeStopAndPrint(startpoint: number) {
Add startpoint as argument.
It prints the elapsed time using customLog()
* Adding duals ouput
* Adding glpk.js package
required dependency
* adding LP format export and fixing a few errors
* fixing further errors
* adding automatic build
* Moving files to correct folders
* Update nextjs.yml
* Updating README and .gitignore
README:
- added installation instructions
- added troubleshooting
gitignore:
- skipping Writerside and .idea folders
* Update LICENCE.txt
We are required to use the same license. See https://github.com/hgourvest/node-glpk/blob/master/LICENSE
* Updating icon
* Adding RegEx input checks and updating text box explanations
* Update README.md
Updating license info
Signed-off-by: SinusFox <61253950+SinusFox@users.noreply.github.com>
* Deleting license to recreate proper license
* Update layout.tsx
fixing typo
Signed-off-by: SinusFox <61253950+SinusFox@users.noreply.github.com>
* Fixing word issue
English has some false friends... like the German "Enter" is actually return in English.
* Updatint License
* Fixing design issue and updating license link
* Fixing typo in log
* Fixing white mode
* adding translations 1/2
UI Translations
Coming in 2/2: Output translations
* adding output translations
* adding minimize button
* adding unit test for rendering home page
* fixing maxmin on lp export
* Update .gitignore
* Update .gitignore
* Update scripts.ts
* Update scripts.ts
* Update README.md
* adding tests
---------
Signed-off-by: SinusFox <61253950+SinusFox@users.noreply.github.com>
Co-authored-by: moebiusl <lucas.moebius@icloud.com>
Co-authored-by: Marcel Pöppe <marcel.poeppe@gmail.com>
105 lines
3.7 KiB
JavaScript
105 lines
3.7 KiB
JavaScript
import { render, fireEvent, screen } from '@testing-library/react';
|
|
import {
|
|
customLog,
|
|
customLogClear,
|
|
getTranslation,
|
|
isInputValidRegex,
|
|
isInputFilled,
|
|
downloadLPFormatting,
|
|
downloadLP,
|
|
calculate_click
|
|
} from '../src/app/scripts';
|
|
import Home from '../src/app/page'
|
|
import text from '../src/app/lang';
|
|
|
|
// Mocking GLPKAPI and console log
|
|
jest.mock('../src/solver/glpk.min.js', () => ({
|
|
LPF_ECOND: 2,
|
|
}));
|
|
|
|
// Mocking console.log
|
|
const consoleLogMock = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
|
|
beforeEach(() => {
|
|
document.body.innerHTML = `
|
|
<div>
|
|
<select id="language_current">
|
|
<option value="eng">English</option>
|
|
</select>
|
|
<textarea id="objective"></textarea>
|
|
<textarea id="subject"></textarea>
|
|
<textarea id="bounds"></textarea>
|
|
<textarea id="vars"></textarea>
|
|
<select id="maxminswitch">
|
|
<option value="maximize">Maximize</option>
|
|
<option value="minimize">Minimize</option>
|
|
</select>
|
|
<div id="out"></div>
|
|
</div>
|
|
`;
|
|
jest.clearAllMocks(); // Clear any previous mocks
|
|
});
|
|
|
|
test('customLog should append message to output box', () => {
|
|
const message = 'Test message';
|
|
customLog(message);
|
|
const outputElement = document.getElementById('out');
|
|
expect(outputElement.innerHTML).toContain(message);
|
|
});
|
|
|
|
test('customLogClear should clear the output box', () => {
|
|
const message = 'Test message';
|
|
customLog(message);
|
|
customLogClear();
|
|
const outputElement = document.getElementById('out');
|
|
expect(outputElement.innerHTML).toBe('');
|
|
});
|
|
|
|
test('getTranslation should return translation based on selected language', () => {
|
|
const result = getTranslation('header_title');
|
|
expect(result).toBe(text('eng', 'header_title')); // Assuming text function provides correct translation
|
|
});
|
|
|
|
test('isInputValidRegex should validate input regex correctly', () => {
|
|
expect(isInputValidRegex("x + y", "+1 x + 2 y <= 15\n+3 x + 1 y <= 20", "x >= 0\ny >= 0", "x\ny")).toBe(true);
|
|
expect(isInputValidRegex("x + y", "+1 x + 2 y <= 15\n+3 x + 1 y <= 20", "x >= 0\ny >= 0", "")).toBe(false); // Invalid objective
|
|
});
|
|
|
|
test('isInputFilled should check for filled inputs', () => {
|
|
expect(isInputFilled('3x + 5y', 'x + y <= 10', 'x <= 5', 'x\ny')).toBe(true);
|
|
expect(isInputFilled('', 'x + y <= 10', 'x <= 5', 'x\ny')).toBe(false); // Objective empty
|
|
});
|
|
|
|
test('downloadLPFormatting should format LP correctly', () => {
|
|
const formattedLP = downloadLPFormatting('3x + 5y', 'x + y <= 10', 'x <= 5');
|
|
expect(formattedLP).toContain('obj: 3x + 5y');
|
|
expect(formattedLP).toContain('Subject To');
|
|
expect(formattedLP).toContain('Bounds');
|
|
});
|
|
|
|
test('calculate_click should display "Calculating" in the output box', () => {
|
|
render(<Home />);
|
|
|
|
// Spy on customLog and customLogClear to prevent actual logging and check the calls
|
|
const mockClear = jest.spyOn({ customLogClear }, 'customLogClear').mockImplementation();
|
|
const mockLog = jest.spyOn({ customLog }, 'customLog').mockImplementation();
|
|
|
|
// Set valid inputs
|
|
document.getElementById('objective').value = '3x + 5y';
|
|
document.getElementById('subject').value = 'x + y <= 10';
|
|
document.getElementById('bounds').value = 'x <= 5';
|
|
document.getElementById('vars').value = 'x\ny';
|
|
|
|
// Simuliere den Button-Klick, der die Berechnung startet
|
|
fireEvent.click(screen.getByText('Calculate'));
|
|
|
|
// Check the contents of out box
|
|
const outputElement = document.getElementById('out');
|
|
expect(outputElement.innerHTML).toContain('Calculating');
|
|
|
|
// Clear mock
|
|
mockClear.mockRestore();
|
|
mockLog.mockRestore();
|
|
});
|
|
|