|
| 1 | +import {ComponentFixture, TestBed} from '@angular/core/testing'; |
| 2 | +import {FormsModule} from '@angular/forms'; |
| 3 | +import {MatFormFieldModule} from '@angular/material/form-field'; |
| 4 | +import {MatInputModule} from '@angular/material/input'; |
| 5 | +import {MatDialog, MatDialogModule, MatDialogRef} from '@angular/material/dialog'; |
| 6 | +import {MockProviders} from 'ng-mocks'; |
| 7 | +import {TranslateModule, TranslateService} from '@ngx-translate/core'; |
| 8 | +import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; |
| 9 | +import {FilesSearchComponent} from './files-search.component'; |
| 10 | +import {SearchesStateService} from '../../search-state.service'; |
| 11 | +import {SidebarStateService} from '@ame/sidebar'; |
| 12 | +import {ModelSavingTrackerService, NotificationsService, SearchService} from '@ame/shared'; |
| 13 | +import {FileHandlingService, SaveModelDialogService} from '@ame/editor'; |
| 14 | +import {LanguageTranslationService} from '@ame/translation'; |
| 15 | +import {HttpClientModule} from '@angular/common/http'; |
| 16 | +import {MxGraphService} from '@ame/mx-graph'; |
| 17 | +import {By} from '@angular/platform-browser'; |
| 18 | + |
| 19 | +describe('Files search', () => { |
| 20 | + let component: FilesSearchComponent; |
| 21 | + let fixture: ComponentFixture<FilesSearchComponent>; |
| 22 | + |
| 23 | + beforeEach(async () => { |
| 24 | + await TestBed.configureTestingModule({ |
| 25 | + imports: [ |
| 26 | + FormsModule, |
| 27 | + MatFormFieldModule, |
| 28 | + MatInputModule, |
| 29 | + MatDialogModule, |
| 30 | + BrowserAnimationsModule, |
| 31 | + TranslateModule.forRoot(), |
| 32 | + HttpClientModule, |
| 33 | + ], |
| 34 | + providers: [ |
| 35 | + MockProviders(MatDialogRef, MxGraphService!, NotificationsService, FileHandlingService), |
| 36 | + TranslateService, |
| 37 | + SearchesStateService, |
| 38 | + SidebarStateService, |
| 39 | + MatDialog, |
| 40 | + ModelSavingTrackerService, |
| 41 | + SaveModelDialogService, |
| 42 | + SearchService, |
| 43 | + LanguageTranslationService, |
| 44 | + ], |
| 45 | + }).compileComponents(); |
| 46 | + }); |
| 47 | + |
| 48 | + beforeEach(() => { |
| 49 | + fixture = TestBed.createComponent(FilesSearchComponent); |
| 50 | + component = fixture.componentInstance; |
| 51 | + fixture.detectChanges(); |
| 52 | + }); |
| 53 | + |
| 54 | + const files = [ |
| 55 | + { |
| 56 | + name: 'AspectDefault.ttl', |
| 57 | + loaded: true, |
| 58 | + locked: false, |
| 59 | + outdated: false, |
| 60 | + errored: false, |
| 61 | + sammVersion: '2.1.0', |
| 62 | + }, |
| 63 | + { |
| 64 | + name: 'SharedModel.ttl', |
| 65 | + locked: false, |
| 66 | + outdated: false, |
| 67 | + errored: false, |
| 68 | + loaded: true, |
| 69 | + sammVersion: '2.1.0', |
| 70 | + }, |
| 71 | + ]; |
| 72 | + |
| 73 | + const namespaces = { |
| 74 | + 'org.eclipse.examples:1.0.0': files, |
| 75 | + }; |
| 76 | + |
| 77 | + it('should parse files correctly', () => { |
| 78 | + component.parseFiles(namespaces); |
| 79 | + |
| 80 | + expect(component.searchableFiles).toEqual([ |
| 81 | + {file: 'AspectDefault.ttl', namespace: 'org.eclipse.examples:1.0.0'}, |
| 82 | + {file: 'SharedModel.ttl', namespace: 'org.eclipse.examples:1.0.0'}, |
| 83 | + ]); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should have mat option if there are namespaces with files', () => { |
| 87 | + jest.spyOn(component, 'openFile'); |
| 88 | + |
| 89 | + component.searchableFiles = files; |
| 90 | + fixture.detectChanges(); |
| 91 | + const autocomplete = fixture.debugElement.query(By.css('mat-autocomplete')); |
| 92 | + expect(autocomplete).toBeTruthy(); |
| 93 | + fixture.detectChanges(); |
| 94 | + const matOptions = autocomplete.nativeElement.querySelectorAll('mat-option'); |
| 95 | + expect(matOptions).toBeTruthy(); |
| 96 | + }); |
| 97 | +}); |
0 commit comments