modelfactory.spec.ts 3.5 KB

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