| import { state, resetState } from '@/js/state'; |
| import { describe, it, expect, beforeEach } from 'vitest'; |
|
|
| describe('State Management', () => { |
| |
| describe('Initial State', () => { |
| it('should have the correct initial values', () => { |
| expect(state.activeTool).toBeNull(); |
| expect(state.files).toEqual([]); |
| expect(state.pdfDoc).toBeNull(); |
| expect(state.pdfPages).toEqual([]); |
| expect(state.currentPdfUrl).toBeNull(); |
| }); |
| }); |
|
|
| |
| describe('resetState function', () => { |
| |
| |
| beforeEach(() => { |
| |
| state.activeTool = 'merge'; |
| state.files = [{ name: 'dummy.pdf', size: 1234 } as File]; |
| state.pdfDoc = { numPages: 5 }; |
| state.pdfPages = [{}, {}]; |
| state.currentPdfUrl = 'blob:http://localhost/some-uuid'; |
|
|
| |
| |
| document.body.innerHTML = |
| '<div id="tool-content">Some old tool content</div>'; |
| }); |
|
|
| it('should reset all state properties to their initial values', () => { |
| |
| resetState(); |
|
|
| |
| expect(state.activeTool).toBeNull(); |
| expect(state.files).toEqual([]); |
| expect(state.pdfDoc).toBeNull(); |
| expect(state.pdfPages).toEqual([]); |
| expect(state.currentPdfUrl).toBeNull(); |
| }); |
|
|
| it('should clear the innerHTML of the #tool-content element', () => { |
| const toolContentElement = document.getElementById('tool-content'); |
|
|
| |
| expect(toolContentElement?.innerHTML).toBe('Some old tool content'); |
|
|
| |
| resetState(); |
|
|
| |
| expect(toolContentElement?.innerHTML).toBe(''); |
| }); |
| }); |
| }); |
|
|