Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions packages/phoenix-event-display/src/event-display.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { httpRequest, openFile } from 'jsroot';
import { settings as jsrootSettings } from 'jsroot';
import { httpRequest, settings as jsrootSettings, openFile } from 'jsroot';
import { build } from 'jsroot/geom';
import { ThreeManager } from './managers/three-manager/index';
import { UIManager } from './managers/ui-manager/index';
import { ActiveVariable } from './helpers/active-variable';
import { InfoLogger } from './helpers/info-logger';
import { getLabelTitle } from './helpers/labels';
import type { Configuration } from './lib/types/configuration';
import { StateManager } from './managers/state-manager';
import { PhoenixLoader } from './loaders/phoenix-loader';
import { LoadingManager } from './managers/loading-manager';
import { URLOptionsManager } from './managers/url-options-manager';
import { ActiveVariable } from './helpers/active-variable';
import { StateManager } from './managers/state-manager';
import type { AnimationPreset } from './managers/three-manager/animations-manager';
import { ThreeManager } from './managers/three-manager/index';
import { XRSessionType } from './managers/three-manager/xr/xr-manager';
import { getLabelTitle } from './helpers/labels';
import { PhoenixLoader } from './loaders/phoenix-loader';
import { UIManager } from './managers/ui-manager/index';
import { URLOptionsManager } from './managers/url-options-manager';

declare global {
/**
Expand Down Expand Up @@ -540,11 +539,11 @@ export class EventDisplay {
* Get the different collections for the current stored event.
* @returns List of strings, each representing a collection of the event displayed.
*/
public getCollections(): string[] {
public getCollections(): { [key: string]: string[] } {
if (this.configuration.eventDataLoader) {
return this.configuration.eventDataLoader.getCollections();
}
return [];
return {};
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InfoLogger } from '../helpers/info-logger';
import { ThreeManager } from '../managers/three-manager/index';
import { UIManager } from '../managers/ui-manager/index';
import { InfoLogger } from '../helpers/info-logger';

/**
* Event data loader for implementing different event data loaders.
Expand Down Expand Up @@ -32,7 +32,7 @@ export interface EventDataLoader {
* Get the different collections for the current stored event.
* @returns List of strings, each representing a collection of the event displayed.
*/
getCollections(): string[];
getCollections(): { [key: string]: string[] };

/**
* Get all the objects inside a collection.
Expand Down
37 changes: 19 additions & 18 deletions packages/phoenix-event-display/src/loaders/phoenix-loader.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Group, Object3D, Vector3, Color } from 'three';
import { GUI } from 'dat.gui';
import type { EventDataLoader } from './event-data-loader';
import { UIManager } from '../managers/ui-manager/index';
import { ThreeManager } from '../managers/three-manager/index';
import { Cut } from '../lib/models/cut.model';
import { PhoenixObjects } from './objects/phoenix-objects';
import * as _ from 'lodash';
import { Group, Object3D, Vector3 } from 'three';
import { CoordinateHelper } from '../helpers/coordinate-helper';
import { InfoLogger } from '../helpers/info-logger';
import { PhoenixMenuNode } from '../managers/ui-manager/phoenix-menu/phoenix-menu-node';
import { getLabelTitle } from '../helpers/labels';
import { Cut } from '../lib/models/cut.model';
import { LoadingManager } from '../managers/loading-manager';
import { StateManager } from '../managers/state-manager';
import { CoordinateHelper } from '../helpers/coordinate-helper';
import { getLabelTitle } from '../helpers/labels';
import { ThreeManager } from '../managers/three-manager/index';
import { DatGUIMenuUI } from '../managers/ui-manager/dat-gui-ui';
import { UIManager } from '../managers/ui-manager/index';
import { PhoenixMenuNode } from '../managers/ui-manager/phoenix-menu/phoenix-menu-node';
import { PhoenixMenuUI } from '../managers/ui-manager/phoenix-menu/phoenix-menu-ui';
import * as _ from 'lodash';
import type { EventDataLoader } from './event-data-loader';
import { PhoenixObjects } from './objects/phoenix-objects';

/**
* Loader for processing and loading an event.
Expand Down Expand Up @@ -100,23 +100,24 @@ export class PhoenixLoader implements EventDataLoader {
* Get list of collections in the event data.
* @returns List of all collection names.
*/
public getCollections(): string[] {
public getCollections(): { [key: string]: string[] } {
if (!this.eventData) {
return [];
return {};
}

const collections = [];
const collectionsByType: { [key: string]: string[] } = {};

for (const objectType in this.eventData) {
if (
this.eventData[objectType] &&
typeof this.eventData[objectType] === 'object'
typeof this.eventData[objectType] == 'object'
) {
for (const collection in this.eventData[objectType]) {
collections.push(collection);
}
collectionsByType[objectType] = Object.keys(
this.eventData[objectType],
).sort();
}
}
return collections;
return collectionsByType;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@ describe('PhoenixLoader', () => {
});

it('should not get the list of collections and collection with the given collection name from the event data', () => {
// Set eventData to undefined to simulate no data available
phoenixLoader['eventData'] = undefined;
const tmp = phoenixLoader.getCollections();
expect(tmp).toBeInstanceOf(Array);
expect(tmp).toHaveLength(0);
expect(phoenixLoader.getCollection('hitsCollection')).toBeFalsy();

// Test getCollections()
const collections = phoenixLoader.getCollections();
expect(collections).toEqual({}); // Expect an empty object instead of an array

// Test getCollection() for a specific collection name
const collection = phoenixLoader.getCollection('hitsCollection');
expect(collection).toBeFalsy(); // Ensure it doesn't return a valid collection

// Restore eventData for other tests
phoenixLoader['eventData'] = eventData['Event'];
});

Expand All @@ -92,7 +99,9 @@ describe('PhoenixLoader', () => {
it('should get list of collections in the event data', () => {
const collectionList = phoenixLoader.getCollections();

expect(collectionList).toEqual(['hitsCollection']);
expect(collectionList).toEqual({
Hits: ['hitsCollection'],
});
});

it('should get the collection with the given collection name from the event data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
(change)="changeCollection($event.target.value)"
>
<option value="" selected disabled hidden>Choose Collection</option>
<option *ngFor="let collection of collections" [value]="collection">
{{ collection }}
</option>
<optgroup *ngFor="let group of collections" [label]="group.type">
<option
*ngFor="let collection of group.collections"
[value]="collection"
>
{{ collection }}
</option>
</optgroup>
</select>
</div>
<mat-checkbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@ describe('CollectionsInfoOverlayComponent', () => {
let fixture: ComponentFixture<CollectionsInfoOverlayComponent>;

const mockEventDisplay = {
listenToDisplayedEventChange: (callback) => {
callback();
},
getCollections: jest.fn(),
getActiveObjectId: () => ({
onUpdate: (callback) => {
callback();
},
listenToDisplayedEventChange: jest.fn((callback) => callback()),
getCollections: jest.fn().mockReturnValue({
Hits: ['hitsCollection1', 'hitsCollection2'],
Tracks: ['trackCollection1'],
}),
enableHighlighting: jest.fn().mockReturnThis(),
disableHighlighting: jest.fn().mockReturnThis(),
getActiveObjectId: jest.fn().mockReturnValue({
value: '',
onUpdate: jest.fn((callback) => callback('1234')),
}),
enableHighlighting: jest.fn(),
disableHighlighting: jest.fn(),
getThreeManager: jest.fn().mockReturnThis(),
getSceneManager: jest.fn().mockReturnThis(),
getScene: jest.fn().mockReturnThis(),
getObjectByName: jest.fn().mockReturnThis(),
getCollection: jest.fn().mockReturnThis(),
lookAtObject: jest.fn().mockReturnThis(),
highlightObject: jest.fn().mockReturnThis(),
addLabelToObject: jest.fn().mockReturnThis(),
getObjectByName: jest.fn(),
getCollection: jest
.fn()
.mockReturnValue([{ uuid: '1234', labelText: 'test' }]),
lookAtObject: jest.fn(),
highlightObject: jest.fn(),
addLabelToObject: jest.fn(),
};

beforeEach(() => {
Expand All @@ -49,7 +51,11 @@ describe('CollectionsInfoOverlayComponent', () => {
component = fixture.componentInstance;
fixture.detectChanges();

component.activeObject.update = jest.fn();
component.activeObject = {
value: '',
update: jest.fn(),
onUpdate: jest.fn(),
} as any;
});

it('should create', () => {
Expand All @@ -60,65 +66,50 @@ describe('CollectionsInfoOverlayComponent', () => {
jest.spyOn(mockEventDisplay, 'listenToDisplayedEventChange');
component.ngOnInit();

// Expect to start listening to changes in the currently displayed event
expect(mockEventDisplay.listenToDisplayedEventChange).toHaveBeenCalled();
expect(component.collections).toEqual([
{ type: 'Hits', collections: ['hitsCollection1', 'hitsCollection2'] },
{ type: 'Tracks', collections: ['trackCollection1'] },
]);
});

it('should initially get active object ID', () => {
// Adding an element with the ID of the collections info row
const ROW_ID = '1234';
const activeObjectRow = document.createElement('div');
activeObjectRow.setAttribute('id', ROW_ID);
document.body.appendChild(activeObjectRow);

// Return mocked row ID from the getActiveObjectId function same as the element we added above
jest.spyOn(mockEventDisplay, 'getActiveObjectId');

component.ngOnInit();
component.activeObject.value = ROW_ID;

expect(mockEventDisplay.getActiveObjectId).toHaveBeenCalled();
expect(component.activeObject.value).toBe('1234');
});

it('should change collection', () => {
const uuid = '1234';
const group = new Object3D();
const object = new Object3D();
object.uuid = uuid;

jest
.spyOn(
mockEventDisplay.getThreeManager().getSceneManager().getScene(),
'getObjectByName',
)
.mockImplementation(() => group);

jest
.spyOn(mockEventDisplay, 'getCollection')
.mockImplementation(() => [{ uuid, otherProp: 'testPropValue' }]);

const mockSelectedValue = 'TestCollection';
const mockSelectedValue = 'hitsCollection1';

jest.spyOn(mockEventDisplay, 'getCollection');
component.changeCollection(mockSelectedValue);

expect(mockEventDisplay.getCollection).toHaveBeenCalledWith(
mockSelectedValue,
);
expect(component.showingCollection).toEqual([
{ uuid: '1234', labelText: 'test', isCut: true },
]);
});

it('should look at object through event display', () => {
const mockUuid = '1234';

jest.spyOn(mockEventDisplay, 'lookAtObject');
component.lookAtObject(mockUuid);

expect(mockEventDisplay.lookAtObject).toHaveBeenCalledWith(mockUuid);
});

it('should highlight object through event display', () => {
const mockUuid = '123'; // Wrong uuid to cover else
const mockUuid = '1234';

jest.spyOn(mockEventDisplay, 'highlightObject');
component.highlightObject(mockUuid);

expect(mockEventDisplay.highlightObject).toHaveBeenCalledWith(mockUuid);
});

Expand All @@ -135,57 +126,52 @@ describe('CollectionsInfoOverlayComponent', () => {
});

it('should sort collections in ascending order', () => {
const mockCollections = [
['1235', 'testPropValue'],
['1236', 'testPropValue'],
component.showingCollection = [
{ uuid: '2', labelText: 'b' },
{ uuid: '1', labelText: 'a' },
];

component.showingCollection = mockCollections;

component.sort('mockCollections', 'asc');

component.sort('labelText', 'asc');
expect(component.showingCollection).toEqual([
['1235', 'testPropValue'],
['1236', 'testPropValue'],
{ uuid: '1', labelText: 'a' },
{ uuid: '2', labelText: 'b' },
]);

component.sort('mockCollections', 'desc');

// TODO: why did this fail?
expect(component.showingCollection).not.toEqual([
['1236', 'testPropValue'],
['1235', 'testPropValue'],
component.sort('labelText', 'desc');
expect(component.showingCollection).toEqual([
{ uuid: '2', labelText: 'b' },
{ uuid: '1', labelText: 'a' },
]);
});

it('should toggle invisibility', () => {
component.hideInvisible = false;

component.toggleInvisible(true);
expect(component.hideInvisible).toBeTruthy();
expect(component.hideInvisible).toBe(true);

component.toggleInvisible(false);
expect(component.hideInvisible).toBeFalsy();
expect(component.hideInvisible).toBe(false);
});

it('should add label to object', () => {
const mockUuid = '1234';
const mockLabel = 'testLabel';

component.selectedCollection = mockLabel;
component.selectedCollection = 'hitsCollection1';
component['elementRef'].nativeElement.querySelector = jest
.fn()
.mockImplementation(() => ({
innerHTML: '',
}));
.mockReturnValue({
value: mockLabel,
});

jest.spyOn(mockEventDisplay, 'addLabelToObject');

component.addLabel(1, mockUuid);
component.addLabel(0, mockUuid);

expect(mockEventDisplay.addLabelToObject).toHaveBeenCalledWith(
undefined,
mockLabel,
1,
'hitsCollection1',
0,
mockUuid,
);
});
Expand Down
Loading
Loading