Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/packages/firebird-ng/api/src/lib/services/data-selection.service.spec.ts is written in an unsupported language. File is not indexed.

0001 import { TestBed } from '@angular/core/testing';
0002 import { provideHttpClient } from '@angular/common/http';
0003 import { describe, expect, it, beforeEach } from 'vitest';
0004 import { DATA_CATALOGS } from '../tokens';
0005 import { ConfigService } from '@dexvis/app-features';
0006 import { DataSelectionService, SELECTION_CONFIG_KEYS, isRootSource } from './data-selection.service';
0007 
0008 const catalog = {
0009   entries: [
0010     { name: 'nc', geometry: 'g/full.root', events: 'd/nc.firebird.zip', tags: { process: 'dis-nc' } },
0011     { name: 'geometry only', geometry: 'g/full.root' },
0012   ],
0013 };
0014 
0015 describe('DataSelectionService', () => {
0016   let service: DataSelectionService;
0017   let config: ConfigService;
0018 
0019   beforeEach(() => {
0020     localStorage.clear();
0021     TestBed.configureTestingModule({
0022       providers: [provideHttpClient(), { provide: DATA_CATALOGS, useValue: catalog, multi: true }],
0023     });
0024     service = TestBed.inject(DataSelectionService);
0025     config = TestBed.inject(ConfigService);
0026   });
0027 
0028   const value = (key: string) => config.getConfig<string>(key)?.value;
0029 
0030   it('routes .root event sources to the ROOT key and clears the DEX key, and vice versa', () => {
0031     expect(isRootSource('https://h/x.root?stamp=1')).toBe(true);
0032     expect(isRootSource('https://h/x.firebird.zip')).toBe(false);
0033 
0034     service.apply({ events: 'https://h/events.root', eventRange: '0-4' });
0035     expect(value(SELECTION_CONFIG_KEYS.rootEvents)).toBe('https://h/events.root');
0036     expect(value(SELECTION_CONFIG_KEYS.dexEvents)).toBe('');
0037     expect(value(SELECTION_CONFIG_KEYS.rootEventRange)).toBe('0-4');
0038 
0039     service.apply({ events: 'd/nc.firebird.zip' });
0040     expect(value(SELECTION_CONFIG_KEYS.dexEvents)).toBe('d/nc.firebird.zip');
0041     expect(value(SELECTION_CONFIG_KEYS.rootEvents)).toBe('');
0042   });
0043 
0044   it('leaves undefined fields alone and clears empty ones', () => {
0045     service.apply({ geometry: 'g/full.root', events: 'd/nc.firebird.zip' });
0046     service.apply({ events: '' });
0047     expect(value(SELECTION_CONFIG_KEYS.geometry)).toBe('g/full.root');
0048     expect(value(SELECTION_CONFIG_KEYS.dexEvents)).toBe('');
0049   });
0050 
0051   it('stashes picked files instead of writing them to config, handing them out once', () => {
0052     const file = new File(['x'], 'local.root');
0053     service.apply({ geometry: 'g/full.root' });
0054     service.apply({ geometry: file, events: file });
0055     expect(value(SELECTION_CONFIG_KEYS.geometry)).toBe('g/full.root');
0056     expect(value(SELECTION_CONFIG_KEYS.dexEvents)).toBe('');
0057     expect(value(SELECTION_CONFIG_KEYS.rootEvents)).toBe('');
0058     expect(service.takePickedGeometryFile()).toBe(file);
0059     expect(service.takePickedGeometryFile()).toBeNull();
0060     expect(service.takePickedEventsFile()).toBe(file);
0061   });
0062 
0063   it('derives the active catalog entry from the configured values and reloads an attached display', () => {
0064     const reloads: unknown[] = [];
0065     service.attachDisplay(parts => reloads.push(parts));
0066     service.apply(service.selectionForEntry(catalog.entries[0]));
0067     expect(service.activeEntry()?.name).toBe('nc');
0068     expect(reloads).toEqual([{ geometry: true, events: true }]);
0069 
0070     // An events-only change leaves the geometry alone
0071     service.apply({ collections: 'tracks' });
0072     expect(reloads[1]).toEqual({ geometry: false, events: true });
0073     service.apply({});
0074     expect(reloads.length).toBe(2);
0075 
0076     service.apply(service.selectionForEntry(catalog.entries[1]));
0077     expect(value(SELECTION_CONFIG_KEYS.dexEvents)).toBe('');
0078     expect(service.activeEntry()?.name).toBe('geometry only');
0079     expect(service.draft()).toEqual({});
0080   });
0081 });