Browse Source

Set mocked settings to separate file

master
jeffvli 3 years ago
parent
commit
18fb512e7b
  1. 209
      src/__tests__/settings.json
  2. 1
      src/components/shared/ContextMenu.tsx
  3. 11
      src/redux/miscSlice.ts
  4. 11
      src/redux/playQueueSlice.ts
  5. 209
      src/shared/mockSettings.ts
  6. 17
      src/shared/utils.ts

209
src/__tests__/settings.json

@ -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
}

1
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 (

11
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;

11
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;

209
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,
};

17
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 = () => {

Loading…
Cancel
Save