panel.spec.ts 3.5 KB

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