Add a liveChannelListMode setting (default 'grouped') with a Settings toggle to display the Live TV channel list flat, without category group sections. When enabled, logical channels are listed directly with their stream variants still grouped as in #9/#10. Cover the setting default and flat-list behavior with tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
62 lines
2.9 KiB
JavaScript
62 lines
2.9 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const grouping = require('../public/js/services/channelVariantGrouping.js');
|
|
|
|
const channel = (id, name, extra = {}) => ({ id, streamId: id, sourceId: 1, name, groupTitle: 'Sports', ...extra });
|
|
|
|
test('normalizes regional prefixes and quality markers into one logical channel', () => {
|
|
const names = ['|FR| BEIN SPORTS uhd 1', '|FR| BEIN SPORTS 1 4K', 'FR-CAR| bein sports 1'];
|
|
assert.deepEqual(names.map(grouping.normalizeChannelName), ['bein sports 1', 'bein sports 1', 'bein sports 1']);
|
|
const logical = grouping.groupChannels(names.map((name, index) => channel(String(index + 1), name)));
|
|
assert.equal(logical.length, 1);
|
|
assert.equal(logical[0].displayName, 'beIN Sports 1');
|
|
assert.equal(logical[0].variants.length, 3);
|
|
});
|
|
|
|
test('does not merge distinct numbered channels', () => {
|
|
const logical = grouping.groupChannels([
|
|
channel('1', 'beIN Sports 1 HD'),
|
|
channel('2', 'beIN Sports 2 HD')
|
|
]);
|
|
assert.deepEqual(logical.map(item => item.fingerprint), ['bein sports 1', 'bein sports 2']);
|
|
});
|
|
|
|
test('logical favorite and hidden state are derived from individual streams', () => {
|
|
const variants = [channel('1', 'BEIN SPORTS 1 HD'), channel('2', 'BEIN SPORTS 1 4K')];
|
|
const logical = grouping.groupChannels(variants, {
|
|
isFavorite: item => item.id === '1',
|
|
isHidden: item => item.id === '2'
|
|
})[0];
|
|
assert.equal(logical.isFavorite, true);
|
|
assert.equal(logical.isHidden, false);
|
|
assert.equal(logical.preferredVariant.id, '1');
|
|
|
|
assert.equal(grouping.groupChannels(variants, { isHidden: () => true }).length, 0);
|
|
assert.equal(grouping.groupChannels(variants, { isHidden: () => true, showHidden: true })[0].isHidden, true);
|
|
});
|
|
|
|
test('an explicit visible selection overrides the automatic quality preference', () => {
|
|
const hd = channel('1', 'BEIN SPORTS 1 HD');
|
|
const uhd = channel('2', 'BEIN SPORTS 1 UHD');
|
|
const selectedVariants = new Map([['bein sports 1', grouping.getVariantKey(hd)]]);
|
|
const logical = grouping.groupChannels([hd, uhd], { selectedVariants })[0];
|
|
assert.equal(logical.preferredVariant.id, '1');
|
|
});
|
|
|
|
test('flat list ordering promotes favorites without duplicating channels', () => {
|
|
const channels = [
|
|
{ id: 'one', isFavorite: false },
|
|
{ id: 'two', isFavorite: true },
|
|
{ id: 'three', isFavorite: false },
|
|
{ id: 'four', isFavorite: true }
|
|
];
|
|
const ordered = grouping.orderFlatChannels(channels);
|
|
assert.deepEqual(ordered.map(item => item.id), ['two', 'four', 'one', 'three']);
|
|
assert.equal(new Set(ordered.map(item => item.id)).size, channels.length);
|
|
});
|
|
|
|
test('favorites group updates are disabled for flat lists', () => {
|
|
assert.equal(grouping.shouldUseFavoritesGroup('flat'), false);
|
|
assert.equal(grouping.shouldUseFavoritesGroup('grouped'), true);
|
|
});
|