modelfactory.spec.ts 3.6 KB

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