panel.spec.ts 3.5 KB

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