panel.spec.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { expect } from 'chai';
  4. import { Context } from '@jupyterlab/docregistry';
  5. import { INotebookModel, NotebookPanel, Notebook } from '@jupyterlab/notebook';
  6. import { Toolbar } from '@jupyterlab/apputils';
  7. import { createNotebookContext, NBTestUtils } from '@jupyterlab/testutils';
  8. /**
  9. * Default data.
  10. */
  11. const contentFactory = NBTestUtils.createNotebookPanelFactory();
  12. describe('@jupyterlab/notebook', () => {
  13. describe('NotebookPanel', () => {
  14. let context: Context<INotebookModel>;
  15. beforeEach(async () => {
  16. context = await createNotebookContext();
  17. });
  18. afterEach(async () => {
  19. await context.session.shutdown();
  20. context.dispose();
  21. });
  22. describe('#constructor()', () => {
  23. it('should create a notebook panel', () => {
  24. const content = NBTestUtils.createNotebook();
  25. const panel = new NotebookPanel({ context, content });
  26. expect(panel).to.be.an.instanceof(NotebookPanel);
  27. });
  28. it('should change notebook to edit mode if we have a single empty code cell', async () => {
  29. const panel = NBTestUtils.createNotebookPanel(context);
  30. const model = panel.content.model;
  31. expect(model).to.equal(context.model);
  32. await context.initialize(true);
  33. await context.ready;
  34. expect(panel.content.mode).to.equal('edit');
  35. });
  36. });
  37. describe('#toolbar', () => {
  38. it('should be the toolbar used by the widget', () => {
  39. const panel = NBTestUtils.createNotebookPanel(context);
  40. expect(panel.toolbar).to.be.an.instanceof(Toolbar);
  41. });
  42. });
  43. describe('#content', () => {
  44. it('should be the notebook content widget', () => {
  45. const panel = NBTestUtils.createNotebookPanel(context);
  46. expect(panel.content).to.be.an.instanceof(Notebook);
  47. });
  48. });
  49. describe('#context', () => {
  50. it('should get the document context for the widget', () => {
  51. const panel = NBTestUtils.createNotebookPanel(context);
  52. expect(panel.context).to.equal(context);
  53. });
  54. });
  55. describe('#dispose()', () => {
  56. it('should dispose of the resources used by the widget', () => {
  57. const panel = NBTestUtils.createNotebookPanel(context);
  58. panel.dispose();
  59. expect(panel.isDisposed).to.equal(true);
  60. });
  61. it('should be safe to call more than once', () => {
  62. const panel = NBTestUtils.createNotebookPanel(context);
  63. panel.dispose();
  64. panel.dispose();
  65. expect(panel.isDisposed).to.equal(true);
  66. });
  67. });
  68. describe('.ContentFactory', () => {
  69. describe('#constructor', () => {
  70. it('should create a new ContentFactory', () => {
  71. const factory = new NotebookPanel.ContentFactory({
  72. editorFactory: NBTestUtils.editorFactory
  73. });
  74. expect(factory).to.be.an.instanceof(NotebookPanel.ContentFactory);
  75. });
  76. });
  77. describe('#NBTestUtils.createNotebook()', () => {
  78. it('should create a notebook widget', () => {
  79. const options = {
  80. contentFactory: contentFactory,
  81. rendermime: NBTestUtils.defaultRenderMime(),
  82. mimeTypeService: NBTestUtils.mimeTypeService
  83. };
  84. expect(contentFactory.createNotebook(options)).to.be.an.instanceof(
  85. Notebook
  86. );
  87. });
  88. });
  89. });
  90. });
  91. });