Back to home page

EIC code displayed by LXR

 
 

    


Warning, /firebird/firebird-ng/src/app/components/view-options/view-options.component.test.ts is written in an unsupported language. File is not indexed.

0001 import { ComponentFixture, TestBed } from '@angular/core/testing';
0002 import { PresetView } from 'phoenix-event-display';
0003 import { ViewOptionsComponent } from './view-options.component';
0004 import {
0005   EventDisplayService,
0006   PhoenixUIModule,
0007   CartesianGridConfigComponent,
0008 } from 'phoenix-ui-components';
0009 import { MatCheckboxChange } from '@angular/material/checkbox';
0010 import { MatDialog } from '@angular/material/dialog';
0011 import { Vector3 } from 'three';
0012 import { of } from 'rxjs/internal/observable/of';
0013 import { Subscription } from 'rxjs';
0014 
0015 describe('ViewOptionsComponent', () => {
0016   let component: ViewOptionsComponent;
0017   let fixture: ComponentFixture<ViewOptionsComponent>;
0018 
0019   const origin = new Vector3(100, 200, 300);
0020 
0021   const mockEventDisplay = {
0022     getUIManager: jest.fn().mockReturnThis(),
0023     getThreeManager: jest.fn().mockReturnThis(),
0024     getPresetViews: jest.fn().mockReturnValue([]),
0025     displayView: jest.fn().mockReturnThis(),
0026     setShowAxis: jest.fn().mockReturnThis(),
0027     setShowEtaPhiGrid: jest.fn().mockReturnThis(),
0028     setShowCartesianGrid: jest.fn().mockReturnThis(),
0029     showLabels: jest.fn().mockReturnThis(),
0030     show3DMousePoints: jest.fn().mockReturnThis(),
0031     show3DDistance: jest.fn().mockReturnThis(),
0032     originChanged: of(origin),
0033   };
0034 
0035   const mockMatDialog = {
0036     open: jest.fn().mockReturnThis(),
0037   };
0038 
0039   beforeEach(() => {
0040     TestBed.configureTestingModule({
0041       imports: [PhoenixUIModule],
0042       declarations: [ViewOptionsComponent, CartesianGridConfigComponent],
0043       providers: [
0044         {
0045           provide: EventDisplayService,
0046           useValue: mockEventDisplay,
0047         },
0048         {
0049           provide: MatDialog,
0050           useValue: mockMatDialog,
0051         },
0052       ],
0053     }).compileComponents();
0054 
0055     fixture = TestBed.createComponent(ViewOptionsComponent);
0056     component = fixture.componentInstance;
0057     fixture.detectChanges();
0058   });
0059 
0060   it('should create', () => {
0061     expect(component).toBeTruthy();
0062   });
0063 
0064   it('should initially get preset views and set up the subscription', () => {
0065     component.ngOnInit();
0066 
0067     expect(mockEventDisplay.getUIManager().getPresetViews).toHaveBeenCalled();
0068 
0069     mockEventDisplay.getThreeManager().originChanged.subscribe((intersect) => {
0070       expect(component.origin).toBe(intersect);
0071     });
0072   });
0073 
0074   it('should open cartesian grid config dialog box', () => {
0075     const mockParams = {
0076       data: {
0077         gridVisible: component.showCartesianGrid,
0078         scale: component.scale,
0079       },
0080       position: {
0081         bottom: '5rem',
0082         left: '3rem',
0083       },
0084     };
0085 
0086     component.openCartesianGridConfigDialog();
0087 
0088     expect(mockMatDialog.open).toHaveBeenCalledWith(
0089       CartesianGridConfigComponent,
0090       mockParams,
0091     );
0092   });
0093 
0094   it('should display the chosen preset view', () => {
0095     const mockEvent = {
0096       stopPropagation: jest.fn(),
0097     };
0098     const mockPresetView = new PresetView(
0099       'Test View',
0100       [0, 0, -12000],
0101       [0, 0, 0],
0102       'left-cube',
0103     );
0104     component.displayView(mockEvent, mockPresetView);
0105 
0106     expect(mockEventDisplay.getUIManager().displayView).toHaveBeenCalledWith(
0107       mockPresetView,
0108     );
0109   });
0110 
0111   it('should set axis', () => {
0112     const VALUE = false;
0113     const event = new MatCheckboxChange();
0114     event.checked = VALUE;
0115 
0116     component.setAxis(event);
0117 
0118     expect(mockEventDisplay.getUIManager().setShowAxis).toHaveBeenCalledWith(
0119       VALUE,
0120     );
0121   });
0122 
0123   it('should set eta phi grid', () => {
0124     const VALUE = false;
0125     const event = new MatCheckboxChange();
0126     event.checked = VALUE;
0127 
0128     component.setEtaPhiGrid(event);
0129 
0130     expect(
0131       mockEventDisplay.getUIManager().setShowEtaPhiGrid,
0132     ).toHaveBeenCalledWith(VALUE);
0133   });
0134 
0135   it('should set cartesian grid', () => {
0136     const VALUE = false;
0137     const event = new MatCheckboxChange();
0138     event.checked = VALUE;
0139 
0140     component.setCartesianGrid(event);
0141 
0142     expect(component.showCartesianGrid).toBe(false);
0143     expect(
0144       mockEventDisplay.getUIManager().setShowCartesianGrid,
0145     ).toHaveBeenCalledWith(VALUE, component.scale);
0146   });
0147 
0148   it('should show labels', () => {
0149     const VALUE = false;
0150     const event = new MatCheckboxChange();
0151     event.checked = VALUE;
0152 
0153     component.showLabels(event);
0154 
0155     expect(mockEventDisplay.getUIManager().showLabels).toHaveBeenCalledWith(
0156       VALUE,
0157     );
0158   });
0159 
0160   it('should show 3D mouse points', () => {
0161     const VALUE = true;
0162     const event = new MatCheckboxChange();
0163     event.checked = VALUE;
0164 
0165     component.show3DMousePoints(event);
0166 
0167     expect(component.show3DPoints).toBe(VALUE);
0168     expect(
0169       mockEventDisplay.getUIManager().show3DMousePoints,
0170     ).toHaveBeenCalledWith(component.show3DPoints);
0171   });
0172 
0173   it('should toggle the show-distance function', () => {
0174     const VALUE = true;
0175     const event = new MatCheckboxChange();
0176     event.checked = VALUE;
0177 
0178     component.toggleShowDistance(event);
0179 
0180     expect(mockEventDisplay.getUIManager().show3DDistance).toHaveBeenCalledWith(
0181       VALUE,
0182     );
0183   });
0184 
0185   it('should unsubscribe the existing subscriptions', () => {
0186     component.sub = new Subscription();
0187     const spy = jest.spyOn(component.sub, 'unsubscribe');
0188 
0189     component.ngOnDestroy();
0190 
0191     expect(spy).toHaveBeenCalledTimes(1);
0192   });
0193 });