modelfactory.spec.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import 'jest';
  4. import { CodeCellModel } from '@jupyterlab/cells';
  5. import { NotebookModel } from '../src';
  6. import { NotebookModelFactory } from '../src';
  7. describe('@jupyterlab/notebook', () => {
  8. describe('NotebookModelFactory', () => {
  9. describe('#constructor', () => {
  10. it('should create a new notebook model factory', () => {
  11. const factory = new NotebookModelFactory({});
  12. expect(factory).toBeInstanceOf(NotebookModelFactory);
  13. });
  14. it('should accept a code cell content factory', () => {
  15. const codeCellContentFactory = new CodeCellModel.ContentFactory();
  16. const factory = new NotebookModelFactory({ codeCellContentFactory });
  17. expect(factory.contentFactory.codeCellContentFactory).toBe(
  18. codeCellContentFactory
  19. );
  20. });
  21. it('should accept a notebook model content factory', () => {
  22. const contentFactory = new NotebookModel.ContentFactory({});
  23. const factory = new NotebookModelFactory({ contentFactory });
  24. expect(factory.contentFactory).toBe(contentFactory);
  25. });
  26. });
  27. describe('#contentFactory', () => {
  28. it('should be the content factory used by the model factory', () => {
  29. const factory = new NotebookModelFactory({});
  30. expect(factory.contentFactory).toBeInstanceOf(
  31. NotebookModel.ContentFactory
  32. );
  33. });
  34. });
  35. describe('#name', () => {
  36. it('should get the name of the model factory', () => {
  37. const factory = new NotebookModelFactory({});
  38. expect(factory.name).toBe('notebook');
  39. });
  40. });
  41. describe('#contentType', () => {
  42. it('should get the file type', () => {
  43. const factory = new NotebookModelFactory({});
  44. expect(factory.contentType).toBe('notebook');
  45. });
  46. });
  47. describe('#fileFormat', () => {
  48. it('should get the file format', () => {
  49. const factory = new NotebookModelFactory({});
  50. expect(factory.fileFormat).toBe('json');
  51. });
  52. });
  53. describe('#isDisposed', () => {
  54. it('should get whether the factory is disposed', () => {
  55. const factory = new NotebookModelFactory({});
  56. expect(factory.isDisposed).toBe(false);
  57. factory.dispose();
  58. expect(factory.isDisposed).toBe(true);
  59. });
  60. });
  61. describe('#dispose()', () => {
  62. it('should dispose of the model factory', () => {
  63. const factory = new NotebookModelFactory({});
  64. factory.dispose();
  65. expect(factory.isDisposed).toBe(true);
  66. });
  67. it('should be safe to call multiple times', () => {
  68. const factory = new NotebookModelFactory({});
  69. factory.dispose();
  70. factory.dispose();
  71. expect(factory.isDisposed).toBe(true);
  72. });
  73. });
  74. describe('#createNew()', () => {
  75. it('should create a new model for a given path', () => {
  76. const factory = new NotebookModelFactory({});
  77. const model = factory.createNew();
  78. expect(model).toBeInstanceOf(NotebookModel);
  79. });
  80. it('should accept a language preference', () => {
  81. const factory = new NotebookModelFactory({});
  82. const model = factory.createNew('foo');
  83. expect(model.defaultKernelLanguage).toBe('foo');
  84. });
  85. });
  86. describe('#preferredLanguage()', () => {
  87. it('should always return an empty string', () => {
  88. const factory = new NotebookModelFactory({});
  89. expect(factory.preferredLanguage('')).toBe('');
  90. expect(factory.preferredLanguage('.ipynb')).toBe('');
  91. });
  92. });
  93. });
  94. });