panel.spec.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. Context
  6. } from '@jupyterlab/docregistry';
  7. import {
  8. INotebookModel, NotebookPanel, Notebook
  9. } from '@jupyterlab/notebook';
  10. import {
  11. Toolbar
  12. } from '@jupyterlab/apputils';
  13. import {
  14. createNotebookContext
  15. } from '../../utils';
  16. import {
  17. DEFAULT_CONTENT, createNotebookPanelFactory, rendermime,
  18. mimeTypeService, editorFactory, createNotebookPanel, createNotebook
  19. } from '../../notebook-utils';
  20. /**
  21. * Default data.
  22. */
  23. const contentFactory = createNotebookPanelFactory();
  24. describe('@jupyterlab/notebook', () => {
  25. describe('NotebookPanel', () => {
  26. let context: Context<INotebookModel>;
  27. beforeEach(async () => {
  28. context = await createNotebookContext();
  29. });
  30. afterEach(async () => {
  31. await context.session.shutdown();
  32. context.dispose();
  33. });
  34. describe('#constructor()', () => {
  35. it('should create a notebook panel', () => {
  36. const content = createNotebook();
  37. const panel = new NotebookPanel({ context, content });
  38. expect(panel).to.be.a(NotebookPanel);
  39. });
  40. it('should change notebook to edit mode if we have a single empty code cell', async () => {
  41. const panel = createNotebookPanel(context);
  42. const model = panel.content.model;
  43. expect(model).to.be(context.model);
  44. await context.initialize(true);
  45. await context.ready;
  46. expect(panel.content.mode).to.equal('edit');
  47. });
  48. });
  49. describe('#toolbar', () => {
  50. it('should be the toolbar used by the widget', () => {
  51. let panel = createNotebookPanel(context);
  52. expect(panel.toolbar).to.be.a(Toolbar);
  53. });
  54. });
  55. describe('#content', () => {
  56. it('should be the notebook content widget', () => {
  57. let panel = createNotebookPanel(context);
  58. expect(panel.content).to.be.a(Notebook);
  59. });
  60. });
  61. describe('#context', () => {
  62. it('should get the document context for the widget', () => {
  63. let panel = createNotebookPanel(context);
  64. expect(panel.context).to.be(context);
  65. });
  66. });
  67. describe('#dispose()', () => {
  68. it('should dispose of the resources used by the widget', () => {
  69. let panel = createNotebookPanel(context);
  70. panel.dispose();
  71. expect(panel.isDisposed).to.be(true);
  72. });
  73. it('should be safe to call more than once', () => {
  74. let panel = createNotebookPanel(context);
  75. panel.dispose();
  76. panel.dispose();
  77. expect(panel.isDisposed).to.be(true);
  78. });
  79. });
  80. describe.skip('.ContentFactory', () => {
  81. // TODO: make notebook panel still take a content factory for a notebook, and use that for a default notebook? This also moves all creation options to the notebook panel that are now just part of the content widget. That would be more backwards compatible, even if it departs a bit from our story about document widgets.
  82. describe('#constructor', () => {
  83. it('should create a new ContentFactory', () => {
  84. let factory = new NotebookPanel.ContentFactory({ editorFactory });
  85. expect(factory).to.be.a(NotebookPanel.ContentFactory);
  86. });
  87. });
  88. describe('#createNotebook()', () => {
  89. it('should create a notebook widget', () => {
  90. let options = {
  91. contentFactory: contentFactory,
  92. rendermime,
  93. mimeTypeService
  94. };
  95. expect(contentFactory.createNotebook(options)).to.be.a(Notebook);
  96. });
  97. });
  98. });
  99. });
  100. });