quintodrome/ui/src/reducers/activityReducer.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

149 lines
3.7 KiB
JavaScript
Raw Normal View History

feat(ui): add scan progress and error reporting to UI (#4094) * feat(scanner): add LastScanError tracking to scanner status - Introduced LastScanErrorKey constant for error tracking. - Updated StatusInfo struct to include LastError field. - Modified scanner logic to store and retrieve last scan error. - Enhanced ScanStatus response to include error information. - Updated UI components to display last scan error when applicable. - Added tests to verify last scan error functionality. Signed-off-by: Deluan <deluan@navidrome.org> * feat(scanner): enhance scan status with type and elapsed time tracking - Added LastScanTypeKey and LastScanStartTimeKey constants for tracking scan type and start time. - Updated StatusInfo struct to include ScanType and ElapsedTime fields. - Implemented getScanInfo method to retrieve scan type, elapsed time, and last error. - Modified scanner logic to store scan type and start time during scans. - Enhanced ScanStatus response and UI components to display scan type and elapsed time. - Added formatShortDuration utility for better elapsed time representation. - Updated activity reducer to handle new scan status fields. Signed-off-by: Deluan <deluan@navidrome.org> * refactor(tests): consolidate controller status tests into a single file - Removed the old controller_status_test.go file. - Merged relevant tests into the new controller_test.go file for better organization and maintainability. - Ensured all existing test cases for controller status are preserved and functional. Signed-off-by: Deluan <deluan@navidrome.org> * Fix formatting issues * refactor(scanner): update getScanInfo method documentation --------- Signed-off-by: Deluan <deluan@navidrome.org>
2025-05-21 05:30:23 -08:00
import { activityReducer } from './activityReducer'
import {
EVENT_SCAN_STATUS,
EVENT_SERVER_START,
EVENT_NOW_PLAYING_COUNT,
EVENT_STREAM_RECONNECTED,
} from '../actions'
feat(ui): add scan progress and error reporting to UI (#4094) * feat(scanner): add LastScanError tracking to scanner status - Introduced LastScanErrorKey constant for error tracking. - Updated StatusInfo struct to include LastError field. - Modified scanner logic to store and retrieve last scan error. - Enhanced ScanStatus response to include error information. - Updated UI components to display last scan error when applicable. - Added tests to verify last scan error functionality. Signed-off-by: Deluan <deluan@navidrome.org> * feat(scanner): enhance scan status with type and elapsed time tracking - Added LastScanTypeKey and LastScanStartTimeKey constants for tracking scan type and start time. - Updated StatusInfo struct to include ScanType and ElapsedTime fields. - Implemented getScanInfo method to retrieve scan type, elapsed time, and last error. - Modified scanner logic to store scan type and start time during scans. - Enhanced ScanStatus response and UI components to display scan type and elapsed time. - Added formatShortDuration utility for better elapsed time representation. - Updated activity reducer to handle new scan status fields. Signed-off-by: Deluan <deluan@navidrome.org> * refactor(tests): consolidate controller status tests into a single file - Removed the old controller_status_test.go file. - Merged relevant tests into the new controller_test.go file for better organization and maintainability. - Ensured all existing test cases for controller status are preserved and functional. Signed-off-by: Deluan <deluan@navidrome.org> * Fix formatting issues * refactor(scanner): update getScanInfo method documentation --------- Signed-off-by: Deluan <deluan@navidrome.org>
2025-05-21 05:30:23 -08:00
import config from '../config'
describe('activityReducer', () => {
const initialState = {
scanStatus: {
scanning: false,
folderCount: 0,
count: 0,
error: '',
elapsedTime: 0,
},
serverStart: { version: config.version },
nowPlayingCount: 0,
streamReconnected: 0,
feat(ui): add scan progress and error reporting to UI (#4094) * feat(scanner): add LastScanError tracking to scanner status - Introduced LastScanErrorKey constant for error tracking. - Updated StatusInfo struct to include LastError field. - Modified scanner logic to store and retrieve last scan error. - Enhanced ScanStatus response to include error information. - Updated UI components to display last scan error when applicable. - Added tests to verify last scan error functionality. Signed-off-by: Deluan <deluan@navidrome.org> * feat(scanner): enhance scan status with type and elapsed time tracking - Added LastScanTypeKey and LastScanStartTimeKey constants for tracking scan type and start time. - Updated StatusInfo struct to include ScanType and ElapsedTime fields. - Implemented getScanInfo method to retrieve scan type, elapsed time, and last error. - Modified scanner logic to store scan type and start time during scans. - Enhanced ScanStatus response and UI components to display scan type and elapsed time. - Added formatShortDuration utility for better elapsed time representation. - Updated activity reducer to handle new scan status fields. Signed-off-by: Deluan <deluan@navidrome.org> * refactor(tests): consolidate controller status tests into a single file - Removed the old controller_status_test.go file. - Merged relevant tests into the new controller_test.go file for better organization and maintainability. - Ensured all existing test cases for controller status are preserved and functional. Signed-off-by: Deluan <deluan@navidrome.org> * Fix formatting issues * refactor(scanner): update getScanInfo method documentation --------- Signed-off-by: Deluan <deluan@navidrome.org>
2025-05-21 05:30:23 -08:00
}
it('returns the initial state when no action is specified', () => {
expect(activityReducer(undefined, {})).toEqual(initialState)
})
it('handles EVENT_SCAN_STATUS action with elapsedTime field', () => {
const elapsedTime = 123456789 // nanoseconds
const action = {
type: EVENT_SCAN_STATUS,
data: {
scanning: true,
folderCount: 5,
count: 100,
error: '',
elapsedTime: elapsedTime,
},
}
const newState = activityReducer(initialState, action)
expect(newState.scanStatus).toEqual({
scanning: true,
folderCount: 5,
count: 100,
error: '',
elapsedTime: elapsedTime,
})
})
it('handles EVENT_SCAN_STATUS action with string elapsedTime', () => {
const action = {
type: EVENT_SCAN_STATUS,
data: {
scanning: true,
folderCount: 5,
count: 100,
error: '',
elapsedTime: '123456789',
},
}
const newState = activityReducer(initialState, action)
expect(newState.scanStatus.elapsedTime).toEqual(123456789)
})
it('handles EVENT_SCAN_STATUS with error field', () => {
const action = {
type: EVENT_SCAN_STATUS,
data: {
scanning: false,
folderCount: 0,
count: 0,
error: 'Test error message',
elapsedTime: 0,
},
}
const newState = activityReducer(initialState, action)
expect(newState.scanStatus.error).toEqual('Test error message')
})
it('handles EVENT_SERVER_START action', () => {
const action = {
type: EVENT_SERVER_START,
data: {
version: '1.0.0',
startTime: '2023-01-01T00:00:00Z',
},
}
const newState = activityReducer(initialState, action)
expect(newState.serverStart).toEqual({
version: '1.0.0',
startTime: Date.parse('2023-01-01T00:00:00Z'),
})
})
it('preserves the scanStatus when handling EVENT_SERVER_START', () => {
const currentState = {
scanStatus: {
scanning: true,
folderCount: 5,
count: 100,
error: 'Previous error',
elapsedTime: 12345,
},
serverStart: { version: config.version },
}
const action = {
type: EVENT_SERVER_START,
data: {
version: '1.0.0',
startTime: '2023-01-01T00:00:00Z',
},
}
const newState = activityReducer(currentState, action)
expect(newState.scanStatus).toEqual(currentState.scanStatus)
expect(newState.serverStart).toEqual({
version: '1.0.0',
startTime: Date.parse('2023-01-01T00:00:00Z'),
})
})
it('handles EVENT_NOW_PLAYING_COUNT', () => {
const action = {
type: EVENT_NOW_PLAYING_COUNT,
data: { count: 5 },
}
const newState = activityReducer(initialState, action)
expect(newState.nowPlayingCount).toEqual(5)
})
it('handles EVENT_STREAM_RECONNECTED', () => {
const action = {
type: EVENT_STREAM_RECONNECTED,
data: {},
}
const beforeTimestamp = Date.now()
const newState = activityReducer(initialState, action)
const afterTimestamp = Date.now()
expect(newState.streamReconnected).toBeGreaterThanOrEqual(beforeTimestamp)
expect(newState.streamReconnected).toBeLessThanOrEqual(afterTimestamp)
})
feat(ui): add scan progress and error reporting to UI (#4094) * feat(scanner): add LastScanError tracking to scanner status - Introduced LastScanErrorKey constant for error tracking. - Updated StatusInfo struct to include LastError field. - Modified scanner logic to store and retrieve last scan error. - Enhanced ScanStatus response to include error information. - Updated UI components to display last scan error when applicable. - Added tests to verify last scan error functionality. Signed-off-by: Deluan <deluan@navidrome.org> * feat(scanner): enhance scan status with type and elapsed time tracking - Added LastScanTypeKey and LastScanStartTimeKey constants for tracking scan type and start time. - Updated StatusInfo struct to include ScanType and ElapsedTime fields. - Implemented getScanInfo method to retrieve scan type, elapsed time, and last error. - Modified scanner logic to store scan type and start time during scans. - Enhanced ScanStatus response and UI components to display scan type and elapsed time. - Added formatShortDuration utility for better elapsed time representation. - Updated activity reducer to handle new scan status fields. Signed-off-by: Deluan <deluan@navidrome.org> * refactor(tests): consolidate controller status tests into a single file - Removed the old controller_status_test.go file. - Merged relevant tests into the new controller_test.go file for better organization and maintainability. - Ensured all existing test cases for controller status are preserved and functional. Signed-off-by: Deluan <deluan@navidrome.org> * Fix formatting issues * refactor(scanner): update getScanInfo method documentation --------- Signed-off-by: Deluan <deluan@navidrome.org>
2025-05-21 05:30:23 -08:00
})