Back to home page

EIC code displayed by LXR

 
 

    


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

0001 import JSZip from 'jszip';
0002 import fetch from 'node-fetch';
0003 import { ComponentFixture, TestBed } from '@angular/core/testing';
0004 
0005 import { IOOptionsDialogComponent } from './io-options-dialog.component';
0006 import { MatDialogRef } from '@angular/material/dialog';
0007 import { EventDisplayService } from '../../../../services/event-display.service';
0008 import { PhoenixUIModule } from '../../../phoenix-ui.module';
0009 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
0010 
0011 const mockFileList = (files: File[]): FileList => {
0012   const fileList: FileList = {
0013     length: files.length,
0014     item: (index) => files[index],
0015     [Symbol.iterator]: files[Symbol.iterator],
0016   };
0017   Object.assign(fileList, files);
0018 
0019   return fileList;
0020 };
0021 
0022 describe('IoOptionsDialogComponent', () => {
0023   let component: IOOptionsDialogComponent;
0024   let fixture: ComponentFixture<IOOptionsDialogComponent>;
0025 
0026   const mockDialogRef = {
0027     close: jest.fn(),
0028   };
0029 
0030   const mockEventDisplayService = {
0031     buildEventDataFromJSON: jest.fn(),
0032     parsePhoenixEvents: jest.fn(),
0033     parseOBJGeometry: jest.fn(),
0034     parsePhoenixDisplay: jest.fn(),
0035     parseGLTFGeometry: jest.fn(),
0036     exportPhoenixDisplay: jest.fn(),
0037     exportToOBJ: jest.fn(),
0038     getInfoLogger: () => ({
0039       add: jest.fn(),
0040     }),
0041   };
0042 
0043   beforeEach(() => {
0044     TestBed.configureTestingModule({
0045       imports: [BrowserAnimationsModule, PhoenixUIModule],
0046       providers: [
0047         {
0048           provide: EventDisplayService,
0049           useValue: mockEventDisplayService,
0050         },
0051         {
0052           provide: MatDialogRef,
0053           useValue: mockDialogRef,
0054         },
0055       ],
0056       declarations: [IOOptionsDialogComponent],
0057     }).compileComponents();
0058 
0059     fixture = TestBed.createComponent(IOOptionsDialogComponent);
0060     component = fixture.componentInstance;
0061     fixture.detectChanges();
0062   });
0063 
0064   afterEach(() => {
0065     fixture.destroy();
0066   });
0067 
0068   it('should create', () => {
0069     expect(component).toBeTruthy();
0070   });
0071 
0072   it('should close the IOOptionsDialog', () => {
0073     component.onClose();
0074 
0075     expect(mockDialogRef.close).toHaveBeenCalled();
0076   });
0077 
0078   describe('handleFileInput', () => {
0079     beforeEach(() => {
0080       jest.spyOn(component, 'handleFileInput').mockImplementation(() => {});
0081     });
0082 
0083     it('should handle JiveXML event data input', async () => {
0084       await fetch(
0085         'https://raw.githubusercontent.com/HSF/phoenix/main/packages/phoenix-ng/projects/phoenix-app/src/assets/files/JiveXML/JiveXML_336567_2327102923.xml',
0086       )
0087         .then((res) => res.text())
0088         .then((res) => {
0089           const files = mockFileList([
0090             new File([res], 'testfile.xml', { type: 'text/xml' }),
0091           ]);
0092           component.handleJiveXMLDataInput(files);
0093           expect(component.readTextFile).toHaveBeenCalled();
0094         });
0095     }, 30000);
0096 
0097     describe('handleFileInput sync', () => {
0098       afterEach(() => {
0099         expect(component.readTextFile).toHaveBeenCalled();
0100       });
0101 
0102       it('should log error for wrong file', () => {
0103         const filesWrong = mockFileList([
0104           new File(['test data'], 'testfile.xml', {
0105             type: 'text/xml',
0106           }),
0107         ]);
0108         component.handleJSONEventDataInput(filesWrong);
0109       });
0110 
0111       it('should handle JSON event data input', () => {
0112         const files = mockFileList([
0113           new File(['{}'], 'testfile.json', {
0114             type: 'application/json',
0115           }),
0116         ]);
0117         component.handleJSONEventDataInput(files);
0118       });
0119 
0120       it('should handle OBJ file input', () => {
0121         const files = mockFileList([
0122           new File(['test data'], 'testfile.obj', {
0123             type: 'text/plain',
0124           }),
0125         ]);
0126         component.handleOBJInput(files);
0127       });
0128 
0129       it('should handle scene file input', () => {
0130         const files = mockFileList([
0131           new File(['test data'], 'testfile.phnx', {
0132             type: 'text/plain',
0133           }),
0134         ]);
0135         component.handleSceneInput(files);
0136       });
0137 
0138       it('should handle glTF file input', () => {
0139         const files = mockFileList([
0140           new File(['{}'], 'testfile.gltf', {
0141             type: 'application/json',
0142           }),
0143         ]);
0144         component.handleGLTFInput(files);
0145       });
0146 
0147       it('should handle phoenix file input', () => {
0148         const files = mockFileList([
0149           new File(['{}'], 'testfile.phnx', {
0150             type: 'application/json',
0151           }),
0152         ]);
0153         component.handlePhoenixInput(files);
0154       });
0155     });
0156   });
0157 
0158   it('should handle zipped event data', async () => {
0159     const zip = new JSZip();
0160     zip.file('test_data.json', '{ "event": null }');
0161     const jivexmlData = await fetch(
0162       'https://raw.githubusercontent.com/HSF/phoenix/main/packages/phoenix-ng/projects/phoenix-app/src/assets/files/JiveXML/JiveXML_336567_2327102923.xml',
0163     );
0164     zip.file('test_data.xml', jivexmlData.text());
0165     const zipBlob = await zip.generateAsync({ type: 'blob' });
0166     const files = mockFileList([
0167       new File([zipBlob], 'test_data.zip', { type: 'application/zip' }),
0168     ]);
0169     component.handleZipEventDataInput(files);
0170   }, 30000);
0171 
0172   it('should handle ig event data', async () => {
0173     const ig = new JSZip();
0174     ig.file('test_data', '{}');
0175     const igBlob = await ig.generateAsync({ type: 'blob' });
0176     const files = mockFileList([new File([igBlob], 'test_data.ig')]);
0177     component.handleZipEventDataInput(files);
0178   });
0179 
0180   it('should save scene', () => {
0181     component.saveScene();
0182     expect(mockEventDisplayService.exportPhoenixDisplay).toHaveBeenCalled();
0183   });
0184 
0185   it('should export to OBJ', () => {
0186     component.exportOBJ();
0187     expect(mockEventDisplayService.exportToOBJ).toHaveBeenCalled();
0188   });
0189 });