mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-19 01:25:06 +00:00
Add default/advanced mode toggle and test coverage for EPG matching
Enhanced EPG matching UX by adding radio button toggle to more clearly define optional advanced options. Also added test coverage for stability. Frontend Changes: - Added radio button UI to EPGMatchModal for default/advanced mode selection - Default mode: Uses built-in normalization - Advanced mode: Shows TagsInput fields for custom prefixes/suffixes/strings - Mode persists across sessions and settings are preserved when switching modes Test Coverage: - Created EPGMatchModal.test.jsx with test cases covering: - Component rendering and mode switching - Form submission and settings persistence - Error handling and UI text variations - Added test cases to SettingsUtils.test.js for EPG mode handling: - epg_match_mode routing to epg_settings group - Settings creation and preservation Since advanced settings are saved persistently but ignored when default settings are used, this adds an easy way in the future to add additional advanced settings to EPG matching like region influence, match aggression, and match preview, since users can easily switch between modes.
This commit is contained in:
parent
0172a7cc00
commit
d7b98fef8d
6 changed files with 429 additions and 65 deletions
|
|
@ -28,7 +28,7 @@ export const saveChangedSettings = async (settings, changedSettings) => {
|
|||
|
||||
// Map of field prefixes to their groups
|
||||
const streamFields = ['default_user_agent', 'default_stream_profile', 'm3u_hash_key', 'preferred_region', 'auto_import_mapped_files'];
|
||||
const epgFields = ['epg_match_ignore_prefixes', 'epg_match_ignore_suffixes', 'epg_match_ignore_custom'];
|
||||
const epgFields = ['epg_match_mode', 'epg_match_ignore_prefixes', 'epg_match_ignore_suffixes', 'epg_match_ignore_custom'];
|
||||
const dvrFields = ['tv_template', 'movie_template', 'tv_fallback_dir', 'tv_fallback_template', 'movie_fallback_template',
|
||||
'comskip_enabled', 'comskip_custom_path', 'pre_offset_minutes', 'post_offset_minutes', 'series_rules'];
|
||||
const backupFields = ['schedule_enabled', 'schedule_frequency', 'schedule_time', 'schedule_day_of_week',
|
||||
|
|
@ -134,6 +134,12 @@ export const getChangedSettings = (values, settings) => {
|
|||
let actualValue = values[settingKey];
|
||||
let compareValue;
|
||||
|
||||
// Handle EPG mode field - always include (defaults to 'default' if not set)
|
||||
if (settingKey === 'epg_match_mode') {
|
||||
changedSettings[settingKey] = actualValue || 'default';
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle EPG fields specially - keep as arrays, don't skip empty arrays
|
||||
if (epgFields.includes(settingKey)) {
|
||||
if (!Array.isArray(actualValue)) {
|
||||
|
|
|
|||
|
|
@ -407,5 +407,131 @@ describe('SettingsUtils', () => {
|
|||
expect(changes.network_access).toBeUndefined();
|
||||
expect(changes.time_zone).toBe('America/New_York');
|
||||
});
|
||||
|
||||
it('should always include epg_match_mode', () => {
|
||||
const values = {
|
||||
epg_match_mode: 'advanced',
|
||||
epg_match_ignore_prefixes: ['HD:'],
|
||||
};
|
||||
const settings = {};
|
||||
|
||||
const changes = SettingsUtils.getChangedSettings(values, settings);
|
||||
expect(changes.epg_match_mode).toBe('advanced');
|
||||
});
|
||||
|
||||
it('should default epg_match_mode to "default" if not provided', () => {
|
||||
const values = {
|
||||
epg_match_ignore_prefixes: ['HD:'],
|
||||
};
|
||||
const settings = {};
|
||||
|
||||
const changes = SettingsUtils.getChangedSettings(values, settings);
|
||||
// epg_match_mode should not be included if not in values
|
||||
expect(changes.epg_match_mode).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should always include EPG array fields even if empty', () => {
|
||||
const values = {
|
||||
epg_match_ignore_prefixes: [],
|
||||
epg_match_ignore_suffixes: [],
|
||||
epg_match_ignore_custom: [],
|
||||
};
|
||||
const settings = {};
|
||||
|
||||
const changes = SettingsUtils.getChangedSettings(values, settings);
|
||||
expect(changes.epg_match_ignore_prefixes).toEqual([]);
|
||||
expect(changes.epg_match_ignore_suffixes).toEqual([]);
|
||||
expect(changes.epg_match_ignore_custom).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('saveChangedSettings - EPG Mode', () => {
|
||||
it('should save epg_match_mode to epg_settings group', async () => {
|
||||
const settings = {
|
||||
epg_settings: {
|
||||
id: 3,
|
||||
key: 'epg_settings',
|
||||
value: {
|
||||
epg_match_mode: 'default',
|
||||
epg_match_ignore_prefixes: [],
|
||||
epg_match_ignore_suffixes: [],
|
||||
epg_match_ignore_custom: [],
|
||||
}
|
||||
}
|
||||
};
|
||||
const changedSettings = {
|
||||
epg_match_mode: 'advanced',
|
||||
epg_match_ignore_prefixes: ['HD:'],
|
||||
};
|
||||
|
||||
API.updateSetting.mockResolvedValue({});
|
||||
|
||||
await SettingsUtils.saveChangedSettings(settings, changedSettings);
|
||||
|
||||
expect(API.updateSetting).toHaveBeenCalledWith({
|
||||
id: 3,
|
||||
key: 'epg_settings',
|
||||
value: {
|
||||
epg_match_mode: 'advanced',
|
||||
epg_match_ignore_prefixes: ['HD:'],
|
||||
epg_match_ignore_suffixes: [],
|
||||
epg_match_ignore_custom: [],
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should create epg_settings if it does not exist', async () => {
|
||||
const settings = {};
|
||||
const changedSettings = {
|
||||
epg_match_mode: 'advanced',
|
||||
epg_match_ignore_prefixes: ['Sling:'],
|
||||
};
|
||||
|
||||
API.createSetting.mockResolvedValue({});
|
||||
|
||||
await SettingsUtils.saveChangedSettings(settings, changedSettings);
|
||||
|
||||
expect(API.createSetting).toHaveBeenCalledWith({
|
||||
key: 'epg_settings',
|
||||
name: 'Epg Settings',
|
||||
value: {
|
||||
epg_match_mode: 'advanced',
|
||||
epg_match_ignore_prefixes: ['Sling:'],
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should preserve existing EPG settings when updating mode', async () => {
|
||||
const settings = {
|
||||
epg_settings: {
|
||||
id: 3,
|
||||
key: 'epg_settings',
|
||||
value: {
|
||||
epg_match_mode: 'advanced',
|
||||
epg_match_ignore_prefixes: ['HD:'],
|
||||
epg_match_ignore_suffixes: [' 4K'],
|
||||
epg_match_ignore_custom: ['Plus'],
|
||||
}
|
||||
}
|
||||
};
|
||||
const changedSettings = {
|
||||
epg_match_mode: 'default',
|
||||
};
|
||||
|
||||
API.updateSetting.mockResolvedValue({});
|
||||
|
||||
await SettingsUtils.saveChangedSettings(settings, changedSettings);
|
||||
|
||||
expect(API.updateSetting).toHaveBeenCalledWith({
|
||||
id: 3,
|
||||
key: 'epg_settings',
|
||||
value: {
|
||||
epg_match_mode: 'default',
|
||||
epg_match_ignore_prefixes: ['HD:'],
|
||||
epg_match_ignore_suffixes: [' 4K'],
|
||||
epg_match_ignore_custom: ['Plus'],
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue