notebook-create.test.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { describe, galata, test } from '@jupyterlab/galata';
  4. import { runMenuOpenTest } from './util';
  5. const fileName = 'notebook.ipynb';
  6. jest.setTimeout(60000);
  7. describe('Notebook Create', () => {
  8. beforeAll(async () => {
  9. await galata.resetUI();
  10. galata.context.capturePrefix = 'notebook-create';
  11. });
  12. afterAll(() => {
  13. galata.context.capturePrefix = '';
  14. });
  15. test('Create new Notebook', async () => {
  16. await expect(galata.notebook.createNew(fileName)).resolves.toEqual(true);
  17. });
  18. test('Create a Raw cell', async () => {
  19. await galata.notebook.setCell(0, 'raw', 'Just a raw cell');
  20. expect(await galata.notebook.getCellCount()).toBe(1);
  21. expect(await galata.notebook.getCellType(0)).toBe('raw');
  22. });
  23. test('Create a Markdown cell', async () => {
  24. await galata.notebook.addCell(
  25. 'markdown',
  26. '## This is **bold** and *italic* [link to jupyter.org!](http://jupyter.org)'
  27. );
  28. await galata.notebook.runCell(1, true);
  29. expect(await galata.notebook.getCellCount()).toBe(2);
  30. expect(await galata.notebook.getCellType(1)).toBe('markdown');
  31. });
  32. test('Create a Code cell', async () => {
  33. await galata.notebook.addCell('code', '2 ** 3');
  34. expect(await galata.notebook.getCellCount()).toBe(3);
  35. expect(await galata.notebook.getCellType(2)).toBe('code');
  36. });
  37. test('Save Notebook', async () => {
  38. await galata.notebook.save();
  39. expect(await galata.contents.fileExists(fileName)).toBeTruthy();
  40. });
  41. runMenuOpenTest();
  42. test('Run cells', async () => {
  43. await galata.notebook.run();
  44. await galata.notebook.save();
  45. const imageName = 'run-cells';
  46. expect((await galata.notebook.getCellTextOutput(2))[0]).toBe('8');
  47. const nbPanel = await galata.notebook.getNotebookInPanel();
  48. await galata.capture.screenshot(imageName, nbPanel);
  49. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  50. });
  51. test('Toggle Dark theme', async () => {
  52. await galata.theme.setDarkTheme();
  53. const nbPanel = await galata.notebook.getNotebookInPanel();
  54. const imageName = 'dark-theme';
  55. await galata.capture.screenshot(imageName, nbPanel);
  56. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  57. });
  58. test('Toggle Light theme', async () => {
  59. await galata.theme.setLightTheme();
  60. await expect(galata.theme.getTheme()).resolves.toEqual('JupyterLab Light');
  61. });
  62. test('Delete Notebook', async () => {
  63. await galata.contents.deleteFile(fileName);
  64. expect(await galata.contents.fileExists(fileName)).toBeFalsy();
  65. });
  66. });