Back to home page

EIC code displayed by LXR

 
 

    


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

0001 import { ComponentFixture, TestBed, tick } from '@angular/core/testing';
0002 
0003 import { CartesianGridConfigComponent } from './cartesian-grid-config.component';
0004 import { EventDisplayService, PhoenixUIModule } from 'phoenix-ui-components';
0005 import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
0006 import { MatCheckboxChange } from '@angular/material/checkbox';
0007 import { Vector3 } from 'three';
0008 import { of } from 'rxjs/internal/observable/of';
0009 
0010 describe('CartesianGridConfigComponent', () => {
0011   let component: CartesianGridConfigComponent;
0012   let fixture: ComponentFixture<CartesianGridConfigComponent>;
0013 
0014   const mockDialogRef = {
0015     close: jest.fn().mockReturnThis(),
0016   };
0017 
0018   const gridOrigin = new Vector3(100, 200, 300);
0019 
0020   const mockEventDisplay = {
0021     getUIManager: jest.fn().mockReturnThis(),
0022     translateCartesianGrid: jest.fn().mockReturnThis(),
0023     translateCartesianLabels: jest.fn().mockReturnThis(),
0024     getCartesianGridConfig: jest.fn().mockReturnValue({
0025       showXY: true,
0026       showYZ: true,
0027       showZX: true,
0028       xDistance: 300,
0029       yDistance: 300,
0030       zDistance: 300,
0031       sparsity: 2,
0032     }),
0033     setShowCartesianGrid: jest.fn().mockReturnThis(),
0034     shiftCartesianGridByPointer: jest.fn().mockReturnThis(),
0035     getThreeManager: jest.fn().mockReturnThis(),
0036     originChanged: of(gridOrigin),
0037     stopShifting: of(true),
0038     origin: new Vector3(0, 0, 0),
0039     originChangedEmit: jest.fn().mockReturnThis(),
0040   };
0041 
0042   const mockData = {
0043     gridVisible: true,
0044     scale: 3000,
0045   };
0046 
0047   beforeEach(async () => {
0048     await TestBed.configureTestingModule({
0049       imports: [PhoenixUIModule],
0050       declarations: [CartesianGridConfigComponent],
0051       providers: [
0052         {
0053           provide: MatDialogRef<CartesianGridConfigComponent>,
0054           useValue: mockDialogRef,
0055         },
0056         {
0057           provide: EventDisplayService,
0058           useValue: mockEventDisplay,
0059         },
0060         {
0061           provide: MAT_DIALOG_DATA,
0062           useValue: mockData,
0063         },
0064       ],
0065     }).compileComponents();
0066 
0067     fixture = TestBed.createComponent(CartesianGridConfigComponent);
0068     component = fixture.componentInstance;
0069     fixture.detectChanges();
0070   });
0071 
0072   it('should create', () => {
0073     expect(component).toBeTruthy();
0074   });
0075 
0076   it('should set initial configuration', (done) => {
0077     const VALUE1 = component.data.gridVisible;
0078     const VALUE2 = component.data.scale;
0079 
0080     component.ngOnInit();
0081 
0082     expect(component.showCartesianGrid).toBe(VALUE1);
0083     expect(component.scale).toBe(VALUE2);
0084 
0085     expect(
0086       mockEventDisplay.getUIManager().getCartesianGridConfig,
0087     ).toHaveBeenCalled();
0088 
0089     const VALUE3 = component.gridConfig;
0090 
0091     expect(
0092       mockEventDisplay.getUIManager().getCartesianGridConfig,
0093     ).toHaveReturnedWith(VALUE3);
0094 
0095     expect(mockEventDisplay.getThreeManager).toHaveBeenCalled();
0096 
0097     const VALUE4 = component.cartesianPos;
0098 
0099     expect(mockEventDisplay.getThreeManager().origin).toBe(VALUE4);
0100     done();
0101   });
0102 
0103   it('should close', () => {
0104     component.onClose();
0105 
0106     expect(mockDialogRef.close).toHaveBeenCalled();
0107   });
0108 
0109   it('should save the updated grid origin', () => {
0110     const VALUE1 = 10;
0111     const VALUE2 = 20;
0112     const VALUE3 = 30;
0113 
0114     const spy = jest.spyOn(component, 'shiftCartesianGridByValues');
0115 
0116     component.onSave(VALUE1, VALUE2, VALUE3);
0117 
0118     expect(spy).toHaveBeenCalledWith(
0119       new Vector3(VALUE1 * 10, VALUE2 * 10, VALUE3 * 10),
0120     );
0121   });
0122 
0123   it('should shift cartesian grid by a mouse click', () => {
0124     component.shiftCartesianGridByPointer();
0125 
0126     mockEventDisplay.getUIManager().shiftCartesianGridByPointer(true);
0127 
0128     mockEventDisplay.getThreeManager().originChanged.subscribe((intersect) => {
0129       expect(component.translateGrid).toHaveBeenCalledWith(intersect);
0130     });
0131 
0132     const originChangedUnSpy = jest.spyOn(
0133       component.originChangedSub,
0134       'unsubscribe',
0135     );
0136     const stopShiftingUnSpy = jest.spyOn(
0137       component.stopShiftingSub,
0138       'unsubscribe',
0139     );
0140 
0141     mockEventDisplay.getThreeManager().stopShifting.subscribe((stop) => {
0142       if (stop) {
0143         expect(originChangedUnSpy).toHaveBeenCalled();
0144         expect(stopShiftingUnSpy).toHaveBeenCalled();
0145       }
0146     });
0147   });
0148 
0149   it('should shift cartesian grid by values', () => {
0150     const VALUE = new Vector3(100, 200, 300);
0151 
0152     const spy = jest.spyOn(component, 'translateGrid');
0153 
0154     component.shiftCartesianGridByValues(VALUE);
0155 
0156     expect(spy).toHaveBeenCalledWith(VALUE);
0157     expect(
0158       mockEventDisplay.getThreeManager().originChangedEmit,
0159     ).toHaveBeenCalledWith(VALUE);
0160   });
0161 
0162   it('should translate grid', () => {
0163     const VALUE1 = new Vector3(100, 200, 300);
0164 
0165     const finalPos = VALUE1;
0166     const initialPos = component.cartesianPos;
0167     const difference = new Vector3(
0168       finalPos.x - initialPos.x,
0169       finalPos.y - initialPos.y,
0170       finalPos.z - initialPos.z,
0171     );
0172 
0173     component['translateGrid'](VALUE1);
0174 
0175     expect(
0176       mockEventDisplay.getUIManager().translateCartesianGrid,
0177     ).toHaveBeenCalledWith(difference.clone());
0178     expect(
0179       mockEventDisplay.getUIManager().translateCartesianLabels,
0180     ).toHaveBeenCalledWith(difference.clone());
0181     expect(component.cartesianPos).toBe(finalPos);
0182   });
0183 
0184   it('should add XY Planes', () => {
0185     const event = { target: { value: '600' } } as any;
0186     const VALUE = Number(event.target.value);
0187 
0188     const spy = jest.spyOn(component, 'callSetShowCartesianGrid');
0189 
0190     component.addXYPlanes(event);
0191 
0192     expect(component.gridConfig.zDistance).toBe(VALUE);
0193     expect(spy).toHaveBeenCalled();
0194   });
0195 
0196   it('should add YZ Planes', () => {
0197     const event = { target: { value: '600' } } as any;
0198     const VALUE = Number(event.target.value);
0199 
0200     const spy = jest.spyOn(component, 'callSetShowCartesianGrid');
0201 
0202     component.addYZPlanes(event);
0203 
0204     expect(component.gridConfig.xDistance).toBe(VALUE);
0205     expect(spy).toHaveBeenCalled();
0206   });
0207 
0208   it('should add ZX Planes', () => {
0209     const event = { target: { value: '600' } } as any;
0210     const VALUE = Number(event.target.value);
0211 
0212     const spy = jest.spyOn(component, 'callSetShowCartesianGrid');
0213 
0214     component.addZXPlanes(event);
0215 
0216     expect(component.gridConfig.yDistance).toBe(VALUE);
0217     expect(spy).toHaveBeenCalled();
0218   });
0219 
0220   it('should change sparsity', () => {
0221     const event = { target: { value: '2' } } as any;
0222     const VALUE = Number(event.target.value);
0223 
0224     const spy = jest.spyOn(component, 'callSetShowCartesianGrid');
0225     component.changeSparsity(event);
0226 
0227     expect(component.gridConfig.sparsity).toBe(VALUE);
0228     expect(spy).toHaveBeenCalled();
0229   });
0230 
0231   it('should show XY Planes', () => {
0232     const VALUE = false;
0233     const event = new MatCheckboxChange();
0234     event.checked = VALUE;
0235 
0236     component.showXYPlanes(event);
0237     expect(component.gridConfig.showXY).toBe(VALUE);
0238   });
0239 
0240   it('should show YZ Planes', () => {
0241     const VALUE = false;
0242     const event = new MatCheckboxChange();
0243     event.checked = VALUE;
0244 
0245     component.showYZPlanes(event);
0246     expect(component.gridConfig.showYZ).toBe(VALUE);
0247   });
0248 
0249   it('should show ZX Planes', () => {
0250     const VALUE = false;
0251     const event = new MatCheckboxChange();
0252     event.checked = VALUE;
0253 
0254     component.showZXPlanes(event);
0255     expect(component.gridConfig.showZX).toBe(VALUE);
0256   });
0257 
0258   it('should call setShowCartesianGrid', () => {
0259     component.callSetShowCartesianGrid();
0260 
0261     expect(
0262       mockEventDisplay.getUIManager().setShowCartesianGrid,
0263     ).toHaveBeenCalledWith(
0264       component.showCartesianGrid,
0265       component.scale,
0266       component.gridConfig,
0267     );
0268   });
0269 });