mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 18:56:01 +00:00
Merge pull request #406 from DmitryPopov/feat/jest-test-setup-getState
chore: Add Jest testing for getState util
This commit is contained in:
14
assets/jest.config.js
Normal file
14
assets/jest.config.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
module.exports = {
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'jsdom',
|
||||||
|
roots: ['<rootDir>'],
|
||||||
|
moduleDirectories: ['node_modules', 'js'],
|
||||||
|
moduleNameMapper: {
|
||||||
|
'^@/(.*)$': '<rootDir>/js/$1',
|
||||||
|
'\.scss$': 'identity-obj-proxy', // Mock SCSS files
|
||||||
|
},
|
||||||
|
transform: {
|
||||||
|
'^.+\.(ts|tsx)$': 'ts-jest',
|
||||||
|
'^.+\.(js|jsx)$': 'babel-jest', // Add babel-jest for JS/JSX files if needed
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { getState } from './getState';
|
||||||
|
import { UNKNOWN_SIGNATURE_NAME } from '@/hooks/Mapper/helpers';
|
||||||
|
import { SignatureGroup, SystemSignature } from '@/hooks/Mapper/types';
|
||||||
|
|
||||||
|
describe('getState', () => {
|
||||||
|
const mockSignaturesMatch: string[] = []; // This parameter is not used in the function
|
||||||
|
|
||||||
|
it('should return 0 if group is undefined', () => {
|
||||||
|
const newSig: SystemSignature = { id: '1', name: 'Test Sig', group: undefined } as SystemSignature;
|
||||||
|
expect(getState(mockSignaturesMatch, newSig)).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 0 if group is CosmicSignature', () => {
|
||||||
|
const newSig: SystemSignature = { id: '1', name: 'Test Sig', group: SignatureGroup.CosmicSignature } as SystemSignature;
|
||||||
|
expect(getState(mockSignaturesMatch, newSig)).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 1 if group is not CosmicSignature and name is undefined', () => {
|
||||||
|
const newSig: SystemSignature = { id: '1', name: undefined, group: SignatureGroup.Wormhole } as SystemSignature;
|
||||||
|
expect(getState(mockSignaturesMatch, newSig)).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 1 if group is not CosmicSignature and name is empty', () => {
|
||||||
|
const newSig: SystemSignature = { id: '1', name: '', group: SignatureGroup.Wormhole } as SystemSignature;
|
||||||
|
expect(getState(mockSignaturesMatch, newSig)).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 1 if group is not CosmicSignature and name is UNKNOWN_SIGNATURE_NAME', () => {
|
||||||
|
const newSig: SystemSignature = { id: '1', name: UNKNOWN_SIGNATURE_NAME, group: SignatureGroup.Wormhole } as SystemSignature;
|
||||||
|
expect(getState(mockSignaturesMatch, newSig)).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return 2 if group is not CosmicSignature and name is a non-empty string', () => {
|
||||||
|
const newSig: SystemSignature = { id: '1', name: 'Custom Name', group: SignatureGroup.Wormhole } as SystemSignature;
|
||||||
|
expect(getState(mockSignaturesMatch, newSig)).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
// According to the current implementation, state = -1 is unreachable
|
||||||
|
// because the conditions for 0, 1, and 2 cover all possibilities for the given inputs.
|
||||||
|
// If the logic of getState were to change to make -1 possible, a test case should be added here.
|
||||||
|
// For now, we can test a scenario that should lead to one of the valid states,
|
||||||
|
// for example, if group is something other than CosmicSignature and name is valid.
|
||||||
|
it('should handle other valid signature groups correctly, leading to state 2 with a valid name', () => {
|
||||||
|
const newSig: SystemSignature = { id: '1', name: 'Combat Site', group: SignatureGroup.CombatSite } as SystemSignature;
|
||||||
|
expect(getState(mockSignaturesMatch, newSig)).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle other valid signature groups correctly, leading to state 1 with an empty name', () => {
|
||||||
|
const newSig: SystemSignature = { id: '1', name: '', group: SignatureGroup.DataSite } as SystemSignature;
|
||||||
|
expect(getState(mockSignaturesMatch, newSig)).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "vite build --emptyOutDir false",
|
"build": "vite build --emptyOutDir false",
|
||||||
"watch": "vite build --watch --minify false --emptyOutDir false --clearScreen true --mode development",
|
"watch": "vite build --watch --minify false --emptyOutDir false --clearScreen true --mode development",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 18.0.0"
|
"node": ">= 18.0.0"
|
||||||
@@ -50,6 +50,7 @@
|
|||||||
"@tailwindcss/aspect-ratio": "^0.4.2",
|
"@tailwindcss/aspect-ratio": "^0.4.2",
|
||||||
"@tailwindcss/forms": "^0.5.7",
|
"@tailwindcss/forms": "^0.5.7",
|
||||||
"@tailwindcss/typography": "^0.5.13",
|
"@tailwindcss/typography": "^0.5.13",
|
||||||
|
"@types/jest": "^29.5.12",
|
||||||
"@types/lodash.debounce": "^4.0.9",
|
"@types/lodash.debounce": "^4.0.9",
|
||||||
"@types/lodash.isequal": "^4.5.8",
|
"@types/lodash.isequal": "^4.5.8",
|
||||||
"@types/react": "^18.3.12",
|
"@types/react": "^18.3.12",
|
||||||
@@ -59,6 +60,7 @@
|
|||||||
"@vitejs/plugin-react": "^4.3.3",
|
"@vitejs/plugin-react": "^4.3.3",
|
||||||
"@vitejs/plugin-react-refresh": "^1.3.6",
|
"@vitejs/plugin-react-refresh": "^1.3.6",
|
||||||
"autoprefixer": "^10.4.19",
|
"autoprefixer": "^10.4.19",
|
||||||
|
"babel-jest": "^29.7.0",
|
||||||
"child_process": "^1.0.2",
|
"child_process": "^1.0.2",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-config-prettier": "^9.1.0",
|
"eslint-config-prettier": "^9.1.0",
|
||||||
@@ -67,6 +69,7 @@
|
|||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.6",
|
"eslint-plugin-react-refresh": "^0.4.6",
|
||||||
"heroicons": "^2.0.18",
|
"heroicons": "^2.0.18",
|
||||||
|
"jest": "^29.7.0",
|
||||||
"merge-options": "^3.0.4",
|
"merge-options": "^3.0.4",
|
||||||
"postcss": "^8.4.38",
|
"postcss": "^8.4.38",
|
||||||
"postcss-cli": "^11.0.0",
|
"postcss-cli": "^11.0.0",
|
||||||
@@ -74,6 +77,7 @@
|
|||||||
"prettier": "^3.2.5",
|
"prettier": "^3.2.5",
|
||||||
"sass": "^1.77.2",
|
"sass": "^1.77.2",
|
||||||
"sass-loader": "^14.2.1",
|
"sass-loader": "^14.2.1",
|
||||||
|
"ts-jest": "^29.1.2",
|
||||||
"typescript": "^5.2.2",
|
"typescript": "^5.2.2",
|
||||||
"vite": "^5.0.5",
|
"vite": "^5.0.5",
|
||||||
"vite-plugin-cdn-import": "^1.0.1"
|
"vite-plugin-cdn-import": "^1.0.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user