|
24 | 24 |
|
25 | 25 | import { render } from '@testing-library/react' |
26 | 26 | import { IDER } from './ider' |
| 27 | +import { |
| 28 | + AMTRedirector, |
| 29 | + AMTIDER |
| 30 | +} from '@device-management-toolkit/ui-toolkit/core' |
27 | 31 |
|
28 | 32 | /** |
29 | 33 | * Mock the ui-toolkit/core dependencies |
@@ -263,4 +267,119 @@ describe('IDER', () => { |
263 | 267 |
|
264 | 268 | expect(container.firstChild).toBeNull() |
265 | 269 | }) |
| 270 | + |
| 271 | + /** |
| 272 | + * Sector stats tracks floppy read operations |
| 273 | + * |
| 274 | + * When the IDER session is active and data is read from the |
| 275 | + * virtual floppy device, the sector stats should be tracked. |
| 276 | + */ |
| 277 | + it('should track floppy read in sector stats', () => { |
| 278 | + const mockFile = new File(['test'], 'test.iso', { |
| 279 | + type: 'application/octet-stream' |
| 280 | + }) |
| 281 | + const { rerender } = render( |
| 282 | + <IDER {...defaultProps} cdrom={mockFile} iderState={0} /> |
| 283 | + ) |
| 284 | + |
| 285 | + // Start IDER |
| 286 | + rerender(<IDER {...defaultProps} cdrom={mockFile} iderState={1} />) |
| 287 | + |
| 288 | + // Get the AMTIDER instance created during startIder |
| 289 | + const iderInstance = (AMTIDER as unknown as jest.Mock).mock.results[0]?.value |
| 290 | + if (iderInstance?.sectorStats) { |
| 291 | + iderInstance.sectorStats(1, 0, 100, 0, 10) // mode=read, dev=floppy |
| 292 | + expect(iderInstance.floppyRead).toBe(10 * 512) |
| 293 | + } |
| 294 | + }) |
| 295 | + |
| 296 | + /** |
| 297 | + * Sector stats tracks CD-ROM read operations |
| 298 | + * |
| 299 | + * CD-ROM read operations use a larger sector size (2048 bytes) |
| 300 | + * compared to floppy (512 bytes). |
| 301 | + */ |
| 302 | + it('should track cdrom read in sector stats', () => { |
| 303 | + const mockFile = new File(['test'], 'test.iso', { |
| 304 | + type: 'application/octet-stream' |
| 305 | + }) |
| 306 | + const { rerender } = render( |
| 307 | + <IDER {...defaultProps} cdrom={mockFile} iderState={0} /> |
| 308 | + ) |
| 309 | + |
| 310 | + rerender(<IDER {...defaultProps} cdrom={mockFile} iderState={1} />) |
| 311 | + |
| 312 | + const iderInstance = (AMTIDER as unknown as jest.Mock).mock.results[0]?.value |
| 313 | + if (iderInstance?.sectorStats) { |
| 314 | + iderInstance.sectorStats(1, 1, 100, 0, 5) // mode=read, dev=cdrom |
| 315 | + expect(iderInstance.cdromRead).toBe(5 * 2048) |
| 316 | + } |
| 317 | + }) |
| 318 | + |
| 319 | + /** |
| 320 | + * Sector stats tracks floppy write operations |
| 321 | + */ |
| 322 | + it('should track floppy write in sector stats', () => { |
| 323 | + const mockFile = new File(['test'], 'test.iso', { |
| 324 | + type: 'application/octet-stream' |
| 325 | + }) |
| 326 | + const { rerender } = render( |
| 327 | + <IDER {...defaultProps} cdrom={mockFile} iderState={0} /> |
| 328 | + ) |
| 329 | + |
| 330 | + rerender(<IDER {...defaultProps} cdrom={mockFile} iderState={1} />) |
| 331 | + |
| 332 | + const iderInstance = (AMTIDER as unknown as jest.Mock).mock.results[0]?.value |
| 333 | + if (iderInstance?.sectorStats) { |
| 334 | + iderInstance.sectorStats(0, 0, 100, 0, 8) // mode=write, dev=floppy |
| 335 | + expect(iderInstance.floppyWrite).toBe(8 * 512) |
| 336 | + } |
| 337 | + }) |
| 338 | + |
| 339 | + /** |
| 340 | + * Sector stats tracks CD-ROM write operations |
| 341 | + */ |
| 342 | + it('should track cdrom write in sector stats', () => { |
| 343 | + const mockFile = new File(['test'], 'test.iso', { |
| 344 | + type: 'application/octet-stream' |
| 345 | + }) |
| 346 | + const { rerender } = render( |
| 347 | + <IDER {...defaultProps} cdrom={mockFile} iderState={0} /> |
| 348 | + ) |
| 349 | + |
| 350 | + rerender(<IDER {...defaultProps} cdrom={mockFile} iderState={1} />) |
| 351 | + |
| 352 | + const iderInstance = (AMTIDER as unknown as jest.Mock).mock.results[0]?.value |
| 353 | + if (iderInstance?.sectorStats) { |
| 354 | + iderInstance.sectorStats(0, 1, 100, 0, 3) // mode=write, dev=cdrom |
| 355 | + expect(iderInstance.cdromWrite).toBe(3 * 2048) |
| 356 | + } |
| 357 | + }) |
| 358 | + |
| 359 | + /** |
| 360 | + * Connection state change callback is invoked |
| 361 | + * |
| 362 | + * When the WebSocket connection state changes, the onConnectionStateChange |
| 363 | + * callback should be fired. This is set up during startIder. |
| 364 | + */ |
| 365 | + it('should handle connection state change callback', () => { |
| 366 | + const mockFile = new File(['test'], 'test.iso', { |
| 367 | + type: 'application/octet-stream' |
| 368 | + }) |
| 369 | + const { rerender } = render( |
| 370 | + <IDER {...defaultProps} cdrom={mockFile} iderState={0} /> |
| 371 | + ) |
| 372 | + |
| 373 | + rerender(<IDER {...defaultProps} cdrom={mockFile} iderState={1} />) |
| 374 | + |
| 375 | + // Get the redirector instance |
| 376 | + const redirectorInstance = (AMTRedirector as unknown as jest.Mock).mock |
| 377 | + .results[0]?.value |
| 378 | + if (redirectorInstance?.onStateChanged) { |
| 379 | + // Should not throw when invoked |
| 380 | + expect(() => { |
| 381 | + redirectorInstance.onStateChanged(redirectorInstance, 2) |
| 382 | + }).not.toThrow() |
| 383 | + } |
| 384 | + }) |
266 | 385 | }) |
0 commit comments