operations-vocabulary.component.spec.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { ComponentFixture, TestBed } from '@angular/core/testing';
  2. import { OperationsService } from '../operations.service';
  3. import { OperationsVocabularyComponent } from './operations-vocabulary.component';
  4. describe('OperationsVocabularyComponent', () => {
  5. let fixture: ComponentFixture<OperationsVocabularyComponent>;
  6. let component: OperationsVocabularyComponent;
  7. let operations: jasmine.SpyObj<OperationsService>;
  8. beforeEach(async () => {
  9. operations = jasmine.createSpyObj<OperationsService>('OperationsService', ['vocabularyTree', 'vocabulary']);
  10. operations.vocabularyTree.and.resolveTo({ items: [], total: 0, totalWords: 89620, refreshedAt: '2026-08-22T12:00:00.000Z' });
  11. operations.vocabulary.and.resolveTo({ page: 1, pageSize: 30, total: 89620, items: [], refreshedAt: '2026-08-22T12:00:00.000Z' });
  12. await TestBed.configureTestingModule({
  13. imports: [OperationsVocabularyComponent],
  14. providers: [
  15. { provide: OperationsService, useValue: operations },
  16. ],
  17. }).compileComponents();
  18. fixture = TestBed.createComponent(OperationsVocabularyComponent);
  19. component = fixture.componentInstance;
  20. fixture.detectChanges();
  21. await fixture.whenStable();
  22. });
  23. it('loads the complete vocabulary by default instead of one arbitrary unit', () => {
  24. expect(component.totalWords()).toBe(89620);
  25. expect(component.selectedNodeId()).toBe(0);
  26. expect(operations.vocabulary).toHaveBeenCalledWith(1, 30, '', { nodeId: 0, status: '', missingAudio: false });
  27. });
  28. it('normalizes old audio filenames and UploadFiles paths through the legacy asset host', () => {
  29. expect(component.audioSource('apple.mp3')).toBe('/backend/UploadFiles/apple.mp3');
  30. expect(component.audioSource('UploadFiles/unit/apple.mp3')).toBe('/backend/UploadFiles/unit/apple.mp3');
  31. expect(component.audioSource('/UploadFiles/unit/apple.mp3')).toBe('/backend/UploadFiles/unit/apple.mp3');
  32. expect(component.audioSource('https://cdn.example/apple.mp3')).toBe('https://cdn.example/apple.mp3');
  33. });
  34. it('keeps the normalized old-site audio URL unchanged', () => {
  35. const url = 'https://a018.2018.z01.com/UploadFiles/audio/c/cherish.mp3';
  36. expect(component.audioSource(url)).toBe(url);
  37. });
  38. });