diff --git a/src/__tests__/settings.json b/src/__tests__/settings.json deleted file mode 100644 index 305ce36..0000000 --- a/src/__tests__/settings.json +++ /dev/null @@ -1,209 +0,0 @@ -{ - "theme": "defaultDark", - "showDebugWindow": false, - "globalMediaHotkeys": true, - "cachePath": "C:\\Users\\jli\\AppData\\Roaming\\Electron", - "volume": 0.93, - "seekForwardInterval": 5, - "seekBackwardInterval": 5, - "volumeFade": true, - "repeat": "all", - "shuffle": false, - "scrollWithCurrentSong": true, - "cacheImages": true, - "cacheSongs": false, - "pollingInterval": 20, - "fadeDuration": 9, - "fadeType": "equalPower", - "gridCardSize": 200, - "playlistViewType": "grid", - "albumViewType": "grid", - "musicListFontSize": "13", - "musicListRowHeight": "50", - "musicListColumns": [ - { - "id": "#", - "dataKey": "index", - "alignment": "center", - "resizable": true, - "width": 50, - "label": "# (Drag/Drop)" - }, - { - "id": "Title", - "dataKey": "combinedtitle", - "alignment": "left", - "resizable": true, - "width": 273, - "label": "Title (Combined)" - }, - { - "id": "Album", - "dataKey": "album", - "alignment": "left", - "resizable": true, - "width": 263, - "label": "Album" - }, - { - "id": "Duration", - "dataKey": "duration", - "alignment": "center", - "resizable": true, - "width": 110, - "label": "Duration" - }, - { - "id": "Bitrate", - "dataKey": "bitRate", - "alignment": "left", - "resizable": true, - "width": 72, - "label": "Bitrate" - }, - { - "id": "Fav", - "dataKey": "starred", - "alignment": "center", - "resizable": true, - "width": 100, - "label": "Favorite" - } - ], - "albumListFontSize": "14", - "albumListRowHeight": "60", - "albumListColumns": [ - { - "id": "#", - "dataKey": "index", - "alignment": "center", - "resizable": true, - "width": 50, - "label": "#" - }, - { - "id": "Title", - "dataKey": "combinedtitle", - "alignment": "left", - "resizable": true, - "width": 457, - "label": "Title (Combined)" - }, - { - "id": "Tracks", - "dataKey": "songCount", - "alignment": "center", - "resizable": true, - "width": 100, - "label": "Track Count" - }, - { - "id": "Duration", - "dataKey": "duration", - "alignment": "center", - "resizable": true, - "width": 80, - "label": "Duration" - }, - { - "id": "Fav", - "dataKey": "starred", - "alignment": "center", - "resizable": true, - "width": 100, - "label": "Favorite" - } - ], - "playlistListFontSize": "14", - "playlistListRowHeight": "80", - "playlistListColumns": [ - { - "id": "#", - "dataKey": "index", - "alignment": "center", - "resizable": true, - "width": 50, - "label": "#" - }, - { - "id": "Art", - "dataKey": "coverart", - "alignment": "center", - "resizable": true, - "width": 100, - "label": "CoverArt" - }, - { - "id": "Title", - "dataKey": "name", - "alignment": "left", - "resizable": true, - "width": 300, - "label": "Title" - }, - { - "id": "Description", - "dataKey": "comment", - "alignment": "left", - "resizable": true, - "width": 200, - "label": "Description" - }, - { - "id": "Tracks", - "dataKey": "songCount", - "alignment": "center", - "resizable": true, - "width": 100, - "label": "Track Count" - }, - { - "id": "Owner", - "dataKey": "owner", - "alignment": "left", - "resizable": true, - "width": 150, - "label": "Owner" - }, - { - "id": "Modified", - "dataKey": "changed", - "alignment": "left", - "resizable": true, - "width": 100, - "label": "Modified" - } - ], - "miniListFontSize": "14", - "miniListColumns": [ - { - "id": "#", - "dataKey": "index", - "alignment": "center", - "resizable": true, - "width": 50, - "label": "# (Drag/Drop)" - }, - { - "id": "Title", - "dataKey": "title", - "alignment": "left", - "resizable": true, - "width": 250, - "label": "Title" - }, - { - "id": "Duration", - "dataKey": "duration", - "alignment": "center", - "resizable": true, - "width": 80, - "label": "Duration" - } - ], - "font": "Poppins", - "server": "http://192.168.14.11:4040", - "serverBase64": "aHR0cDovLzE5Mi4xNjguMTQuMTE6NDA0MA==", - "miniListRowHeight": "30", - "dynamicBackground": false -} diff --git a/src/components/shared/ContextMenu.tsx b/src/components/shared/ContextMenu.tsx index b5dfd40..88d30d1 100644 --- a/src/components/shared/ContextMenu.tsx +++ b/src/components/shared/ContextMenu.tsx @@ -26,7 +26,6 @@ import { } from './styled'; import { notifyToast } from './toast'; import { sleep } from '../../shared/utils'; -import { setStatus } from '../../redux/playerSlice'; export const ContextMenuButton = ({ text, children, ...rest }: any) => { return ( diff --git a/src/redux/miscSlice.ts b/src/redux/miscSlice.ts index 9927094..74d8597 100644 --- a/src/redux/miscSlice.ts +++ b/src/redux/miscSlice.ts @@ -1,14 +1,9 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import settings from 'electron-settings'; +import { mockSettings } from '../shared/mockSettings'; -if (process.env.NODE_ENV === 'test') { - settings.configure({ - dir: '/src/__tests__/', - fileName: 'settings.json', - }); -} - -const parsedSettings = settings.getSync(); +const parsedSettings = + process.env.NODE_ENV === 'test' ? mockSettings : settings.getSync(); export interface ModalPage { pageType: string; diff --git a/src/redux/playQueueSlice.ts b/src/redux/playQueueSlice.ts index ddbd64d..0b9a7c3 100644 --- a/src/redux/playQueueSlice.ts +++ b/src/redux/playQueueSlice.ts @@ -4,15 +4,10 @@ import settings from 'electron-settings'; import { nanoid } from 'nanoid/non-secure'; import arrayMove from 'array-move'; import { areConsecutive, consecutiveRanges } from '../shared/utils'; +import { mockSettings } from '../shared/mockSettings'; -if (process.env.NODE_ENV === 'test') { - settings.configure({ - dir: '/src/__tests__/', - fileName: 'settings.json', - }); -} - -const parsedSettings = settings.getSync(); +const parsedSettings = + process.env.NODE_ENV === 'test' ? mockSettings : settings.getSync(); export interface Entry { id: string; diff --git a/src/shared/mockSettings.ts b/src/shared/mockSettings.ts new file mode 100644 index 0000000..d67c2d3 --- /dev/null +++ b/src/shared/mockSettings.ts @@ -0,0 +1,209 @@ +export const mockSettings = { + theme: 'defaultDark', + showDebugWindow: false, + globalMediaHotkeys: true, + cachePath: 'C:\\Users\\jli\\AppData\\Roaming\\Electron', + volume: 0.93, + seekForwardInterval: 5, + seekBackwardInterval: 5, + volumeFade: true, + repeat: 'all', + shuffle: false, + scrollWithCurrentSong: true, + cacheImages: true, + cacheSongs: false, + pollingInterval: 20, + fadeDuration: 9, + fadeType: 'equalPower', + gridCardSize: 200, + playlistViewType: 'grid', + albumViewType: 'grid', + musicListFontSize: '13', + musicListRowHeight: '50', + musicListColumns: [ + { + id: '#', + dataKey: 'index', + alignment: 'center', + resizable: true, + width: 50, + label: '# (Drag/Drop)', + }, + { + id: 'Title', + dataKey: 'combinedtitle', + alignment: 'left', + resizable: true, + width: 273, + label: 'Title (Combined)', + }, + { + id: 'Album', + dataKey: 'album', + alignment: 'left', + resizable: true, + width: 263, + label: 'Album', + }, + { + id: 'Duration', + dataKey: 'duration', + alignment: 'center', + resizable: true, + width: 110, + label: 'Duration', + }, + { + id: 'Bitrate', + dataKey: 'bitRate', + alignment: 'left', + resizable: true, + width: 72, + label: 'Bitrate', + }, + { + id: 'Fav', + dataKey: 'starred', + alignment: 'center', + resizable: true, + width: 100, + label: 'Favorite', + }, + ], + albumListFontSize: '14', + albumListRowHeight: '60', + albumListColumns: [ + { + id: '#', + dataKey: 'index', + alignment: 'center', + resizable: true, + width: 50, + label: '#', + }, + { + id: 'Title', + dataKey: 'combinedtitle', + alignment: 'left', + resizable: true, + width: 457, + label: 'Title (Combined)', + }, + { + id: 'Tracks', + dataKey: 'songCount', + alignment: 'center', + resizable: true, + width: 100, + label: 'Track Count', + }, + { + id: 'Duration', + dataKey: 'duration', + alignment: 'center', + resizable: true, + width: 80, + label: 'Duration', + }, + { + id: 'Fav', + dataKey: 'starred', + alignment: 'center', + resizable: true, + width: 100, + label: 'Favorite', + }, + ], + playlistListFontSize: '14', + playlistListRowHeight: '80', + playlistListColumns: [ + { + id: '#', + dataKey: 'index', + alignment: 'center', + resizable: true, + width: 50, + label: '#', + }, + { + id: 'Art', + dataKey: 'coverart', + alignment: 'center', + resizable: true, + width: 100, + label: 'CoverArt', + }, + { + id: 'Title', + dataKey: 'name', + alignment: 'left', + resizable: true, + width: 300, + label: 'Title', + }, + { + id: 'Description', + dataKey: 'comment', + alignment: 'left', + resizable: true, + width: 200, + label: 'Description', + }, + { + id: 'Tracks', + dataKey: 'songCount', + alignment: 'center', + resizable: true, + width: 100, + label: 'Track Count', + }, + { + id: 'Owner', + dataKey: 'owner', + alignment: 'left', + resizable: true, + width: 150, + label: 'Owner', + }, + { + id: 'Modified', + dataKey: 'changed', + alignment: 'left', + resizable: true, + width: 100, + label: 'Modified', + }, + ], + miniListFontSize: '14', + miniListColumns: [ + { + id: '#', + dataKey: 'index', + alignment: 'center', + resizable: true, + width: 50, + label: '# (Drag/Drop)', + }, + { + id: 'Title', + dataKey: 'title', + alignment: 'left', + resizable: true, + width: 250, + label: 'Title', + }, + { + id: 'Duration', + dataKey: 'duration', + alignment: 'center', + resizable: true, + width: 80, + label: 'Duration', + }, + ], + font: 'Poppins', + server: 'http://192.168.14.11:4040', + serverBase64: 'aHR0cDovLzE5Mi4xNjguMTQuMTE6NDA0MA==', + miniListRowHeight: '30', + dynamicBackground: false, +}; diff --git a/src/shared/utils.ts b/src/shared/utils.ts index 52494f1..7204fdd 100644 --- a/src/shared/utils.ts +++ b/src/shared/utils.ts @@ -2,17 +2,24 @@ import fs from 'fs'; import path from 'path'; import moment from 'moment'; import settings from 'electron-settings'; +import { mockSettings } from './mockSettings'; export const isCached = (filePath: string) => { return fs.existsSync(filePath); }; export const getRootCachePath = () => { - return path.join( - String(settings.getSync('cachePath')), - 'sonixdCache', - String(settings.getSync('serverBase64')) - ); + const baseCachePath = + process.env.NODE_ENV === 'test' + ? mockSettings.cachePath + : String(settings.getSync('cachePath')); + + const serverBase64 = + process.env.NODE_ENV === 'test' + ? mockSettings.serverBase64 + : String(settings.getSync('serverBase64')); + + return path.join(baseCachePath, 'sonixdCache', serverBase64); }; export const getImageCachePath = () => {