|
| 1 | +import { get_breadcrumbs } from './utils'; |
| 2 | +import { VirtualDocument } from '../virtual/document'; |
| 3 | +import { WidgetAdapter } from '../adapters/adapter'; |
| 4 | +import { IDocumentWidget } from '@jupyterlab/docregistry'; |
| 5 | + |
| 6 | +function create_dummy_document(options: Partial<VirtualDocument.IOptions>) { |
| 7 | + return new VirtualDocument({ |
| 8 | + language: 'python', |
| 9 | + foreign_code_extractors: {}, |
| 10 | + overrides_registry: {}, |
| 11 | + path: 'Untitled.ipynb.py', |
| 12 | + file_extension: 'py', |
| 13 | + has_lsp_supported_file: false, |
| 14 | + ...options |
| 15 | + }); |
| 16 | +} |
| 17 | + |
| 18 | +describe('get_breadcrumbs', () => { |
| 19 | + it('should collapse long paths', () => { |
| 20 | + let document = create_dummy_document({ |
| 21 | + path: 'dir1/dir2/Test.ipynb' |
| 22 | + }); |
| 23 | + let breadcrumbs = get_breadcrumbs(document, { |
| 24 | + has_multiple_editors: false |
| 25 | + } as WidgetAdapter<IDocumentWidget>); |
| 26 | + expect(breadcrumbs[0].props['title']).toBe('dir1/dir2/Test.ipynb'); |
| 27 | + expect(breadcrumbs[0].props['children']).toBe('dir1/.../Test.ipynb'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should trim the extra filename suffix for files created out of notebooks', () => { |
| 31 | + let document = create_dummy_document({ |
| 32 | + path: 'Test.ipynb.py', |
| 33 | + file_extension: 'py', |
| 34 | + has_lsp_supported_file: false |
| 35 | + }); |
| 36 | + let breadcrumbs = get_breadcrumbs(document, { |
| 37 | + has_multiple_editors: false |
| 38 | + } as WidgetAdapter<IDocumentWidget>); |
| 39 | + expect(breadcrumbs[0].props['children']).toBe('Test.ipynb'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should not trim the filename suffix for standalone files', () => { |
| 43 | + let document = create_dummy_document({ |
| 44 | + path: 'test.py', |
| 45 | + file_extension: 'py', |
| 46 | + has_lsp_supported_file: true |
| 47 | + }); |
| 48 | + let breadcrumbs = get_breadcrumbs(document, { |
| 49 | + has_multiple_editors: false |
| 50 | + } as WidgetAdapter<IDocumentWidget>); |
| 51 | + expect(breadcrumbs[0].props['children']).toBe('test.py'); |
| 52 | + }); |
| 53 | +}); |
0 commit comments