widgetfactory.spec.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import expect = require('expect.js');
  4. import {
  5. toArray
  6. } from 'phosphor/lib/algorithm/iteration';
  7. import {
  8. INotebookModel
  9. } from '../../../lib/notebook/model';
  10. import {
  11. NotebookPanel
  12. } from '../../../lib/notebook/panel';
  13. import {
  14. NotebookWidgetFactory
  15. } from '../../../lib/notebook/widgetfactory';
  16. import {
  17. Context
  18. } from '../../../lib/docregistry/context';
  19. import {
  20. createNotebookContext
  21. } from '../utils';
  22. import {
  23. createNotebookPanelFactory, clipboard, rendermime, mimeTypeService
  24. } from './utils';
  25. const contentFactory = createNotebookPanelFactory();
  26. function createFactory(): NotebookWidgetFactory {
  27. return new NotebookWidgetFactory({
  28. name: 'notebook',
  29. fileExtensions: ['.ipynb'],
  30. rendermime,
  31. clipboard,
  32. contentFactory,
  33. mimeTypeService
  34. });
  35. }
  36. describe('notebook/notebook/widgetfactory', () => {
  37. let context: Context<INotebookModel>;
  38. beforeEach(() => {
  39. context = createNotebookContext();
  40. });
  41. afterEach(() => {
  42. context.dispose();
  43. });
  44. describe('NotebookWidgetFactory', () => {
  45. describe('#constructor()', () => {
  46. it('should create a notebook widget factory', () => {
  47. let factory = createFactory();
  48. expect(factory).to.be.a(NotebookWidgetFactory);
  49. });
  50. });
  51. describe('#isDisposed', () => {
  52. it('should get whether the factory has been disposed', () => {
  53. let factory = createFactory();
  54. expect(factory.isDisposed).to.be(false);
  55. factory.dispose();
  56. expect(factory.isDisposed).to.be(true);
  57. });
  58. });
  59. describe('#dispose()', () => {
  60. it('should dispose of the resources held by the factory', () => {
  61. let factory = createFactory();
  62. factory.dispose();
  63. expect(factory.isDisposed).to.be(true);
  64. });
  65. it('should be safe to call multiple times', () => {
  66. let factory = createFactory();
  67. factory.dispose();
  68. factory.dispose();
  69. expect(factory.isDisposed).to.be(true);
  70. });
  71. });
  72. describe('#createNew()', () => {
  73. it('should create a new `NotebookPanel` widget', () => {
  74. let factory = createFactory();
  75. let panel = factory.createNew(context);
  76. expect(panel).to.be.a(NotebookPanel);
  77. });
  78. it('should create a clone of the rendermime', () => {
  79. let factory = createFactory();
  80. let panel = factory.createNew(context);
  81. expect(panel.rendermime).to.not.be(rendermime);
  82. });
  83. it('should populate the default toolbar items', () => {
  84. let factory = createFactory();
  85. let panel = factory.createNew(context);
  86. let items = toArray(panel.toolbar.names());
  87. expect(items).to.contain('save');
  88. expect(items).to.contain('restart');
  89. expect(items).to.contain('kernelStatus');
  90. });
  91. });
  92. });
  93. });