@alepot55/chessboardjs 2.2.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chessboard.cjs.js +1477 -382
- package/dist/chessboard.css +22 -7
- package/dist/chessboard.esm.js +1477 -382
- package/dist/chessboard.iife.js +1477 -382
- package/dist/chessboard.umd.js +1477 -382
- package/package.json +18 -3
- package/src/components/Piece.js +509 -26
- package/src/components/Square.js +3 -3
- package/src/core/Chessboard.js +625 -218
- package/src/core/ChessboardConfig.js +257 -8
- package/src/services/MoveService.js +37 -99
- package/src/services/PieceService.js +51 -24
- package/src/styles/board.css +22 -3
- package/.eslintrc.json +0 -227
- package/chessboard.bundle.js +0 -4072
- package/config/.babelrc +0 -4
- package/config/jest.config.js +0 -15
- package/config/rollup.config.js +0 -36
- package/jest.config.js +0 -2
- package/rollup.config.js +0 -2
- package/tests/unit/chessboard-config-animations.test.js +0 -106
- package/tests/unit/chessboard-robust.test.js +0 -163
- package/tests/unit/chessboard.test.js +0 -183
package/config/.babelrc
DELETED
package/config/jest.config.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
testEnvironment: 'jsdom',
|
|
3
|
-
rootDir: '../',
|
|
4
|
-
testMatch: [
|
|
5
|
-
'<rootDir>/tests/unit/**/*.test.js',
|
|
6
|
-
'<rootDir>/tests/integration/**/*.test.js'
|
|
7
|
-
],
|
|
8
|
-
collectCoverageFrom: [
|
|
9
|
-
'<rootDir>/src/**/*.js',
|
|
10
|
-
'!<rootDir>/src/**/*.test.js'
|
|
11
|
-
],
|
|
12
|
-
transform: {
|
|
13
|
-
"^.+\\.js$": ["babel-jest", { "presets": [["@babel/preset-env", { "targets": { "node": "current" } }]] }]
|
|
14
|
-
}
|
|
15
|
-
};
|
package/config/rollup.config.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
-
import replace from '@rollup/plugin-replace';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
input: 'src/index.js', // nuovo entry point
|
|
6
|
-
output: [
|
|
7
|
-
{
|
|
8
|
-
file: 'dist/chessboard.esm.js', // ES modules
|
|
9
|
-
format: 'esm'
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
file: 'dist/chessboard.cjs.js', // CommonJS
|
|
13
|
-
format: 'cjs'
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
file: 'dist/chessboard.umd.js', // UMD
|
|
17
|
-
format: 'umd',
|
|
18
|
-
name: 'Chessboard'
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
file: 'dist/chessboard.iife.js', // IIFE per browser
|
|
22
|
-
format: 'iife',
|
|
23
|
-
name: 'ChessboardLib',
|
|
24
|
-
footer: 'var Chessboard = ChessboardLib.default; if (typeof window !== "undefined") { window.Chessboard = Chessboard; Object.keys(ChessboardLib).forEach(key => { if (key !== "default") Chessboard[key] = ChessboardLib[key]; }); }'
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
plugins: [
|
|
28
|
-
replace({
|
|
29
|
-
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
30
|
-
'process.env.BUILD_NUMBER': JSON.stringify(''),
|
|
31
|
-
'process.env.BUILD_DATE': JSON.stringify(''),
|
|
32
|
-
preventAssignment: true
|
|
33
|
-
}),
|
|
34
|
-
resolve()
|
|
35
|
-
]
|
|
36
|
-
};
|
package/jest.config.js
DELETED
package/rollup.config.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { ChessboardConfig } from '../../src/core/ChessboardConfig.js';
|
|
2
|
-
|
|
3
|
-
describe('ChessboardConfig Animation & Drag Properties', () => {
|
|
4
|
-
const baseConfig = { id: 'test-board' };
|
|
5
|
-
|
|
6
|
-
test('should handle boolean moveAnimation values', () => {
|
|
7
|
-
expect(() => {
|
|
8
|
-
new ChessboardConfig({ ...baseConfig, moveAnimation: true });
|
|
9
|
-
}).not.toThrow();
|
|
10
|
-
expect(() => {
|
|
11
|
-
new ChessboardConfig({ ...baseConfig, moveAnimation: false });
|
|
12
|
-
}).not.toThrow();
|
|
13
|
-
// Check resulting property
|
|
14
|
-
expect(new ChessboardConfig({ ...baseConfig, moveAnimation: true }).moveAnimation).toBe('ease');
|
|
15
|
-
expect(new ChessboardConfig({ ...baseConfig, moveAnimation: false }).moveAnimation).toBe(null);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('should handle boolean snapbackAnimation values', () => {
|
|
19
|
-
expect(() => {
|
|
20
|
-
new ChessboardConfig({ ...baseConfig, snapbackAnimation: true });
|
|
21
|
-
}).not.toThrow();
|
|
22
|
-
expect(() => {
|
|
23
|
-
new ChessboardConfig({ ...baseConfig, snapbackAnimation: false });
|
|
24
|
-
}).not.toThrow();
|
|
25
|
-
expect(new ChessboardConfig({ ...baseConfig, snapbackAnimation: true }).snapbackAnimation).toBe('ease');
|
|
26
|
-
expect(new ChessboardConfig({ ...baseConfig, snapbackAnimation: false }).snapbackAnimation).toBe(null);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('should handle boolean fadeAnimation values', () => {
|
|
30
|
-
expect(() => {
|
|
31
|
-
new ChessboardConfig({ ...baseConfig, fadeAnimation: true });
|
|
32
|
-
}).not.toThrow();
|
|
33
|
-
expect(() => {
|
|
34
|
-
new ChessboardConfig({ ...baseConfig, fadeAnimation: false });
|
|
35
|
-
}).not.toThrow();
|
|
36
|
-
expect(new ChessboardConfig({ ...baseConfig, fadeAnimation: true }).fadeAnimation).toBe('ease');
|
|
37
|
-
expect(new ChessboardConfig({ ...baseConfig, fadeAnimation: false }).fadeAnimation).toBe(null);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('should handle string animation values', () => {
|
|
41
|
-
expect(() => {
|
|
42
|
-
new ChessboardConfig({
|
|
43
|
-
...baseConfig,
|
|
44
|
-
moveAnimation: 'ease-in-out',
|
|
45
|
-
snapbackAnimation: 'linear',
|
|
46
|
-
fadeAnimation: 'ease'
|
|
47
|
-
});
|
|
48
|
-
}).not.toThrow();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('should handle none animation values', () => {
|
|
52
|
-
expect(() => {
|
|
53
|
-
new ChessboardConfig({
|
|
54
|
-
...baseConfig,
|
|
55
|
-
moveAnimation: 'none',
|
|
56
|
-
snapbackAnimation: 'none',
|
|
57
|
-
fadeAnimation: 'none'
|
|
58
|
-
});
|
|
59
|
-
}).not.toThrow();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('should throw error for invalid animation values', () => {
|
|
63
|
-
expect(() => {
|
|
64
|
-
new ChessboardConfig({ ...baseConfig, moveAnimation: 'invalid-animation' });
|
|
65
|
-
}).toThrow('Invalid transition function');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// --- DRAGGABLE ---
|
|
69
|
-
test('should handle draggable true/false', () => {
|
|
70
|
-
expect(() => new ChessboardConfig({ ...baseConfig, draggable: true })).not.toThrow();
|
|
71
|
-
expect(() => new ChessboardConfig({ ...baseConfig, draggable: false })).not.toThrow();
|
|
72
|
-
});
|
|
73
|
-
test('should default draggable to true', () => {
|
|
74
|
-
const config = new ChessboardConfig(baseConfig);
|
|
75
|
-
expect(config.draggable).toBe(true);
|
|
76
|
-
});
|
|
77
|
-
test('should throw error for invalid draggable value', () => {
|
|
78
|
-
expect(() => new ChessboardConfig({ ...baseConfig, draggable: 'maybe' })).toThrow();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// --- DROP OFF BOARD ---
|
|
82
|
-
test('should accept valid dropOffBoard values', () => {
|
|
83
|
-
expect(() => new ChessboardConfig({ ...baseConfig, dropOffBoard: 'snapback' })).not.toThrow();
|
|
84
|
-
expect(() => new ChessboardConfig({ ...baseConfig, dropOffBoard: 'trash' })).not.toThrow();
|
|
85
|
-
});
|
|
86
|
-
test('should throw error for invalid dropOffBoard value', () => {
|
|
87
|
-
expect(() => new ChessboardConfig({ ...baseConfig, dropOffBoard: 'invalid' })).toThrow();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// --- ANIMATION STYLE ---
|
|
91
|
-
test('should accept valid animationStyle values', () => {
|
|
92
|
-
expect(() => new ChessboardConfig({ ...baseConfig, animationStyle: 'simultaneous' })).not.toThrow();
|
|
93
|
-
expect(() => new ChessboardConfig({ ...baseConfig, animationStyle: 'sequential' })).not.toThrow();
|
|
94
|
-
});
|
|
95
|
-
test('should throw error for invalid animationStyle value', () => {
|
|
96
|
-
expect(() => new ChessboardConfig({ ...baseConfig, animationStyle: 'crazy' })).toThrow();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// --- EDGE CASES ---
|
|
100
|
-
test('should throw error if id/id_div is missing', () => {
|
|
101
|
-
expect(() => new ChessboardConfig({})).toThrow();
|
|
102
|
-
});
|
|
103
|
-
test('should throw error for non-object config', () => {
|
|
104
|
-
expect(() => new ChessboardConfig('not-an-object')).toThrow();
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import Chessboard from '../../src/index.js';
|
|
2
|
-
|
|
3
|
-
describe('Chessboard Robustness & Edge Cases', () => {
|
|
4
|
-
let chessboard;
|
|
5
|
-
let config = { id_div: 'board', size: 400, position: 'start', orientation: 'w' };
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
document.body.innerHTML = '<div id="board"></div>';
|
|
9
|
-
chessboard = new Chessboard(config);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
describe('Piece Insertion', () => {
|
|
13
|
-
test('insert valid string piece', () => {
|
|
14
|
-
expect(() => chessboard.putPiece('wq', 'e4')).not.toThrow();
|
|
15
|
-
expect(chessboard.getPiece('e4')).toBe('wq');
|
|
16
|
-
});
|
|
17
|
-
test('insert valid object piece', () => {
|
|
18
|
-
expect(() => chessboard.putPiece({ type: 'q', color: 'w' }, 'd5')).not.toThrow();
|
|
19
|
-
expect(chessboard.getPiece('d5')).toBe('wq');
|
|
20
|
-
});
|
|
21
|
-
test('insert invalid string piece', () => {
|
|
22
|
-
expect(() => chessboard.putPiece('xx', 'e4')).toThrow();
|
|
23
|
-
});
|
|
24
|
-
test('insert invalid object piece', () => {
|
|
25
|
-
expect(() => chessboard.putPiece({ type: 'z', color: 'w' }, 'e4')).toThrow();
|
|
26
|
-
});
|
|
27
|
-
test('insert null/undefined piece', () => {
|
|
28
|
-
expect(() => chessboard.putPiece(null, 'e4')).toThrow();
|
|
29
|
-
expect(() => chessboard.putPiece(undefined, 'e4')).toThrow();
|
|
30
|
-
});
|
|
31
|
-
test('insert on invalid square', () => {
|
|
32
|
-
expect(() => chessboard.putPiece('wq', 'z9')).toThrow();
|
|
33
|
-
});
|
|
34
|
-
test('insert on already occupied square', () => {
|
|
35
|
-
chessboard.putPiece('wq', 'e4');
|
|
36
|
-
expect(() => chessboard.putPiece('bq', 'e4')).not.toThrow();
|
|
37
|
-
expect(chessboard.getPiece('e4')).toBe('bq');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('Piece Removal', () => {
|
|
42
|
-
test('remove from empty square', () => {
|
|
43
|
-
expect(chessboard.getPiece('e5')).toBeNull();
|
|
44
|
-
expect(() => chessboard.removePiece('e5')).not.toThrow();
|
|
45
|
-
});
|
|
46
|
-
test('remove from occupied square', () => {
|
|
47
|
-
chessboard.putPiece('wq', 'e4');
|
|
48
|
-
expect(() => chessboard.removePiece('e4')).not.toThrow();
|
|
49
|
-
expect(chessboard.getPiece('e4')).toBeNull();
|
|
50
|
-
});
|
|
51
|
-
test('remove from invalid square', () => {
|
|
52
|
-
expect(() => chessboard.removePiece('z9')).toThrow();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('FEN Handling', () => {
|
|
57
|
-
test('set valid FEN', () => {
|
|
58
|
-
const fen = '8/8/8/8/8/8/8/8 w - - 0 1';
|
|
59
|
-
expect(() => chessboard.setPosition(fen)).toThrow(); // ora deve lanciare
|
|
60
|
-
});
|
|
61
|
-
test('set invalid FEN', () => {
|
|
62
|
-
expect(() => chessboard.setPosition('invalid-fen')).toThrow();
|
|
63
|
-
});
|
|
64
|
-
test('set FEN with pawns on first/last rank', () => {
|
|
65
|
-
expect(() => chessboard.setPosition('8/8/8/8/8/8/8/P7 w - - 0 1')).toThrow();
|
|
66
|
-
});
|
|
67
|
-
test('set FEN with too many kings', () => {
|
|
68
|
-
expect(() => chessboard.setPosition('8/8/8/8/8/8/8/KK6 w - - 0 1')).toThrow();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('Game Over & Rules', () => {
|
|
73
|
-
test('checkmate detection', () => {
|
|
74
|
-
chessboard.setPosition('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
|
|
75
|
-
chessboard.movePiece('f2f3');
|
|
76
|
-
chessboard.movePiece('e7e5');
|
|
77
|
-
chessboard.movePiece('g2g4');
|
|
78
|
-
chessboard.movePiece('d8h4');
|
|
79
|
-
expect(chessboard.isGameOver()).toBe(true);
|
|
80
|
-
});
|
|
81
|
-
test('stalemate detection', () => {
|
|
82
|
-
chessboard.setPosition('7k/5Q2/6K1/8/8/8/8/8 b - - 0 1');
|
|
83
|
-
expect(chessboard.isGameOver()).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
test('insufficient material', () => {
|
|
86
|
-
chessboard.setPosition('8/8/8/8/8/8/2k5/3K4 w - - 0 1');
|
|
87
|
-
expect(chessboard.isGameOver()).toBe(true);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('Undo/Redo & History', () => {
|
|
92
|
-
test('undo/redo after moves', async () => {
|
|
93
|
-
chessboard.movePiece('e2e4');
|
|
94
|
-
chessboard.movePiece('e7e5');
|
|
95
|
-
chessboard.undoMove();
|
|
96
|
-
expect(chessboard.getPiece('e5')).toBeNull();
|
|
97
|
-
chessboard.redoMove();
|
|
98
|
-
chessboard.forceSync();
|
|
99
|
-
await new Promise(r => setTimeout(r, 10));
|
|
100
|
-
expect(chessboard.getPiece('e5')).toBe('pb');
|
|
101
|
-
});
|
|
102
|
-
test('undo/redo after clear', () => {
|
|
103
|
-
chessboard.movePiece('e2e4');
|
|
104
|
-
chessboard.clear();
|
|
105
|
-
expect(() => chessboard.undoMove()).not.toThrow();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('Config & Animation', () => {
|
|
110
|
-
test('set invalid config', () => {
|
|
111
|
-
expect(() => new Chessboard({})).toThrow();
|
|
112
|
-
});
|
|
113
|
-
test('set extreme resize', () => {
|
|
114
|
-
expect(() => chessboard.resizeBoard(50)).not.toThrow();
|
|
115
|
-
expect(() => chessboard.resizeBoard(2000)).not.toThrow();
|
|
116
|
-
});
|
|
117
|
-
test('set invalid resize', () => {
|
|
118
|
-
expect(() => chessboard.resizeBoard(-1)).toThrow();
|
|
119
|
-
});
|
|
120
|
-
test('change animation at runtime', () => {
|
|
121
|
-
expect(() => chessboard.config.moveAnimation = 'linear').not.toThrow();
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe('Alias & Deprecated', () => {
|
|
126
|
-
test('alias insert', () => {
|
|
127
|
-
expect(() => chessboard.insert('e4', 'wq')).not.toThrow();
|
|
128
|
-
expect(chessboard.getPiece('e4')).toBe('wq');
|
|
129
|
-
});
|
|
130
|
-
test('alias get', async () => {
|
|
131
|
-
chessboard.forceSync();
|
|
132
|
-
await new Promise(r => setTimeout(r, 10));
|
|
133
|
-
expect(chessboard.get('e2')).toBe('pw');
|
|
134
|
-
});
|
|
135
|
-
test('alias piece', async () => {
|
|
136
|
-
chessboard.forceSync();
|
|
137
|
-
await new Promise(r => setTimeout(r, 10));
|
|
138
|
-
expect(chessboard.piece('e2')).toBe('pw');
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe('Drag & Drop', () => {
|
|
143
|
-
test('draggable false disables drag', () => {
|
|
144
|
-
chessboard = new Chessboard({ ...config, draggable: false });
|
|
145
|
-
expect(chessboard.config.draggable).toBe(false);
|
|
146
|
-
});
|
|
147
|
-
test('draggable true enables drag', () => {
|
|
148
|
-
chessboard = new Chessboard({ ...config, draggable: true });
|
|
149
|
-
expect(chessboard.config.draggable).toBe(true);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe('Resize & Flip Edge Cases', () => {
|
|
154
|
-
test('multiple flips', () => {
|
|
155
|
-
chessboard.flipBoard();
|
|
156
|
-
chessboard.flipBoard();
|
|
157
|
-
expect(chessboard.getOrientation()).toBe('w');
|
|
158
|
-
});
|
|
159
|
-
test('resize to auto', () => {
|
|
160
|
-
expect(() => chessboard.resizeBoard('auto')).not.toThrow();
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
});
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import Chessboard from '../../src/index.js';
|
|
2
|
-
|
|
3
|
-
describe('Chessboard User Functions', () => {
|
|
4
|
-
let chessboard;
|
|
5
|
-
let config = { id_div: 'board', size: 400, position: 'start', orientation: 'w' };
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
document.body.innerHTML = '<div id="board"></div>';
|
|
9
|
-
chessboard = new Chessboard(config);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('turn() should return the current turn', () => {
|
|
13
|
-
expect(chessboard.turn()).toBe('w');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('getOrientation() should return the current orientation', () => {
|
|
17
|
-
expect(chessboard.getOrientation()).toBe('w');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('fen() should return the current FEN string', () => {
|
|
21
|
-
expect(chessboard.fen()).toBe('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// lastMove() is not part of the new API, so this test is commented out or should be adapted
|
|
25
|
-
// test('lastMove() should return the last move made', () => {
|
|
26
|
-
// chessboard.movePiece('e2e4');
|
|
27
|
-
// expect(chessboard.lastMove().san).toBe('e4');
|
|
28
|
-
// });
|
|
29
|
-
|
|
30
|
-
test('getHistory() should return the history of moves', () => {
|
|
31
|
-
chessboard.movePiece('e2e4');
|
|
32
|
-
chessboard.movePiece('e7e5');
|
|
33
|
-
expect(chessboard.getHistory().length).toBe(2);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('getPiece() should return the piece on the given square', () => {
|
|
37
|
-
expect(chessboard.getPiece('e2')).toBe('pw');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('setPosition() should set the board to the given position', () => {
|
|
41
|
-
chessboard.setPosition('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
|
|
42
|
-
expect(chessboard.fen()).toBe('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('flipBoard() should flip the board orientation', () => {
|
|
46
|
-
chessboard.flipBoard();
|
|
47
|
-
expect(chessboard.getOrientation()).toBe('b');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('rebuild() should rebuild the board', () => {
|
|
51
|
-
chessboard.rebuild();
|
|
52
|
-
expect(chessboard.fen()).toBe('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('clear() should clear the board', () => {
|
|
56
|
-
chessboard.clear();
|
|
57
|
-
expect(chessboard.fen()).toBe('8/8/8/8/8/8/8/8 w - - 0 1');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('putPiece() should insert a piece on the given square', () => {
|
|
61
|
-
chessboard.putPiece('qw', 'e4');
|
|
62
|
-
expect(chessboard.getPiece('e4')).toBe('qw');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// isGameOver() returns boolean, not 'w', so adapt the test
|
|
66
|
-
test('isGameOver() should return the game over status', () => {
|
|
67
|
-
chessboard.setPosition('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
|
|
68
|
-
chessboard.movePiece('e2e4');
|
|
69
|
-
chessboard.movePiece('e7e5');
|
|
70
|
-
chessboard.movePiece('d1h5');
|
|
71
|
-
chessboard.movePiece('b8c6');
|
|
72
|
-
chessboard.movePiece('f1c4');
|
|
73
|
-
chessboard.movePiece('g8f6');
|
|
74
|
-
chessboard.movePiece('h5f7');
|
|
75
|
-
expect(chessboard.isGameOver()).toBe(true);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('setOrientation() should set the board orientation', () => {
|
|
79
|
-
chessboard.setOrientation('b');
|
|
80
|
-
expect(chessboard.getOrientation()).toBe('b');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('resizeBoard() should resize the board', () => {
|
|
84
|
-
chessboard.resizeBoard(500);
|
|
85
|
-
expect(document.documentElement.style.getPropertyValue('--dimBoard')).toBe('500px');
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test('destroy() should destroy the board', () => {
|
|
89
|
-
chessboard.destroy();
|
|
90
|
-
// Adapt this test to check for DOM cleanup or internal state
|
|
91
|
-
// For now, just check that calling destroy does not throw
|
|
92
|
-
expect(() => chessboard.destroy()).not.toThrow();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('removePiece() should remove a piece from the given square', () => {
|
|
96
|
-
chessboard.removePiece('e2');
|
|
97
|
-
expect(chessboard.getPiece('e2')).toBeNull();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// piece() is deprecated, use getPiece()
|
|
101
|
-
test('getPiece() alias should return the piece on the given square', () => {
|
|
102
|
-
expect(chessboard.getPiece('e2')).toBe('pw');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// highlight/dehighlight tests depend on implementation details
|
|
106
|
-
// Here we check that the methods exist and can be called
|
|
107
|
-
test('highlight() should not throw for a valid square', () => {
|
|
108
|
-
expect(() => chessboard.highlight('e2')).not.toThrow();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('dehighlight() should not throw for a valid square', () => {
|
|
112
|
-
expect(() => chessboard.dehighlight('e2')).not.toThrow();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// The following tests are for features not present in the new API or require internal access
|
|
116
|
-
// test('playerTurn() should return true if it is the player turn', () => {
|
|
117
|
-
// expect(chessboard.playerTurn()).toBe(true);
|
|
118
|
-
// });
|
|
119
|
-
|
|
120
|
-
// test('isWhiteOriented() should return true if the board is oriented for white', () => {
|
|
121
|
-
// expect(chessboard.isWhiteOriented()).toBe(true);
|
|
122
|
-
// });
|
|
123
|
-
|
|
124
|
-
// test('getSquareID() should return the correct square ID', () => {
|
|
125
|
-
// expect(chessboard.getSquareID(0, 0)).toBe('a8');
|
|
126
|
-
// expect(chessboard.getSquareID(7, 7)).toBe('h1');
|
|
127
|
-
// });
|
|
128
|
-
|
|
129
|
-
// test('removeSquares() should remove all squares from the board', () => {
|
|
130
|
-
// chessboard.removeSquares();
|
|
131
|
-
// expect(Object.keys(chessboard.squares).length).toBe(0);
|
|
132
|
-
// });
|
|
133
|
-
|
|
134
|
-
// --- DRAG & ANIMATION TESTS ---
|
|
135
|
-
describe('Drag and Animation', () => {
|
|
136
|
-
test('should respect draggable: false', () => {
|
|
137
|
-
chessboard.destroy();
|
|
138
|
-
chessboard = new Chessboard({ ...config, draggable: false });
|
|
139
|
-
// Simulate drag attempt (mock event)
|
|
140
|
-
const dragStart = () => chessboard.config.draggable;
|
|
141
|
-
expect(dragStart()).toBe(false);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test('should allow drag when draggable: true', () => {
|
|
145
|
-
chessboard.destroy();
|
|
146
|
-
chessboard = new Chessboard({ ...config, draggable: true });
|
|
147
|
-
// Simulate drag attempt (mock event)
|
|
148
|
-
const dragStart = () => chessboard.config.draggable;
|
|
149
|
-
expect(dragStart()).toBe(true);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test('moveAnimation config should be respected', () => {
|
|
153
|
-
chessboard.destroy();
|
|
154
|
-
chessboard = new Chessboard({ ...config, moveAnimation: 'ease-in-out' });
|
|
155
|
-
expect(chessboard.config.moveAnimation).toBe('ease-in-out');
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test('snapbackAnimation config should be respected', () => {
|
|
159
|
-
chessboard.destroy();
|
|
160
|
-
chessboard = new Chessboard({ ...config, snapbackAnimation: 'linear' });
|
|
161
|
-
expect(chessboard.config.snapbackAnimation).toBe('linear');
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test('fadeAnimation config should be respected', () => {
|
|
165
|
-
chessboard.destroy();
|
|
166
|
-
chessboard = new Chessboard({ ...config, fadeAnimation: 'ease' });
|
|
167
|
-
expect(chessboard.config.fadeAnimation).toBe('ease');
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
test('should not animate if moveAnimation is false', () => {
|
|
171
|
-
chessboard.destroy();
|
|
172
|
-
chessboard = new Chessboard({ ...config, moveAnimation: false });
|
|
173
|
-
expect(chessboard.config.moveAnimation).toBe(null);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// NOTE: DOM animation/drag event simulation is limited in Jest/JSDOM
|
|
177
|
-
// These tests check config and method presence, not actual browser animation
|
|
178
|
-
test('should have highlight and dehighlight methods for drag/hover', () => {
|
|
179
|
-
expect(typeof chessboard.highlight).toBe('function');
|
|
180
|
-
expect(typeof chessboard.dehighlight).toBe('function');
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
});
|