notebook-toolbar.test.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. const fileName = 'notebook.ipynb';
  5. jest.setTimeout(60000);
  6. describe('Notebook Toolbar', () => {
  7. beforeAll(async () => {
  8. await galata.resetUI();
  9. galata.context.capturePrefix = 'notebook-toolbar';
  10. });
  11. afterAll(() => {
  12. galata.context.capturePrefix = '';
  13. });
  14. test('Create new Notebook', async () => {
  15. await expect(galata.notebook.createNew(fileName)).resolves.toEqual(true);
  16. });
  17. test('Create a Raw cell', async () => {
  18. await galata.notebook.setCell(0, 'raw', 'Just a raw cell');
  19. expect(await galata.notebook.getCellCount()).toBe(1);
  20. expect(await galata.notebook.getCellType(0)).toBe('raw');
  21. });
  22. test('Create a Markdown cell', async () => {
  23. await galata.notebook.addCell(
  24. 'markdown',
  25. '## This is **bold** and *italic* [link to jupyter.org!](http://jupyter.org)'
  26. );
  27. await galata.notebook.runCell(1, true);
  28. expect(await galata.notebook.getCellCount()).toBe(2);
  29. expect(await galata.notebook.getCellType(1)).toBe('markdown');
  30. });
  31. test('Create a Code cell', async () => {
  32. await galata.notebook.addCell('code', '2 ** 3');
  33. expect(await galata.notebook.getCellCount()).toBe(3);
  34. expect(await galata.notebook.getCellType(2)).toBe('code');
  35. });
  36. test('Save Notebook', async () => {
  37. await galata.notebook.save();
  38. expect(await galata.contents.fileExists(fileName)).toBeTruthy();
  39. });
  40. test('Insert cells', async () => {
  41. const imageName = 'insert-cells';
  42. await galata.notebook.selectCells(0);
  43. await galata.notebook.clickToolbarItem('insert');
  44. await galata.notebook.selectCells(2);
  45. await galata.notebook.clickToolbarItem('insert');
  46. const nbPanel = await galata.notebook.getNotebookInPanel();
  47. await galata.capture.screenshot(imageName, nbPanel);
  48. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  49. });
  50. test('Copy-Paste cell', async () => {
  51. const imageName = 'copy-paste-cell';
  52. await galata.notebook.selectCells(2);
  53. await galata.notebook.clickToolbarItem('copy');
  54. await galata.notebook.selectCells(0);
  55. await galata.notebook.clickToolbarItem('paste');
  56. const nbPanel = await galata.notebook.getNotebookInPanel();
  57. await galata.capture.screenshot(imageName, nbPanel);
  58. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  59. });
  60. test('Cut cell', async () => {
  61. const imageName = 'cut-cell';
  62. await galata.notebook.selectCells(1);
  63. await galata.notebook.clickToolbarItem('cut');
  64. const nbPanel = await galata.notebook.getNotebookInPanel();
  65. await galata.capture.screenshot(imageName, nbPanel);
  66. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  67. });
  68. test('Paste cell', async () => {
  69. const imageName = 'paste-cell';
  70. await galata.notebook.selectCells(4);
  71. await galata.notebook.clickToolbarItem('paste');
  72. const nbPanel = await galata.notebook.getNotebookInPanel();
  73. await galata.capture.screenshot(imageName, nbPanel);
  74. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  75. });
  76. test('Delete cells', async () => {
  77. const imageName = 'delete-cell';
  78. await galata.notebook.selectCells(1, 3);
  79. await galata.menu.clickMenuItem('Edit>Delete Cells');
  80. const nbPanel = await galata.notebook.getNotebookInPanel();
  81. await galata.capture.screenshot(imageName, nbPanel);
  82. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  83. });
  84. test('Run cell', async () => {
  85. const imageName = 'run-cell';
  86. await galata.notebook.selectCells(1);
  87. await galata.notebook.clickToolbarItem('run');
  88. await galata.notebook.waitForRun();
  89. const nbPanel = await galata.notebook.getNotebookInPanel();
  90. await galata.capture.screenshot(imageName, nbPanel);
  91. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  92. });
  93. test('Change cell type to Markdown', async () => {
  94. const imageName = 'change-to-markdown';
  95. await galata.notebook.selectCells(1);
  96. await galata.notebook.clickToolbarItem('cellType');
  97. await galata.context.page.keyboard.press('m');
  98. await galata.context.page.keyboard.press('Enter');
  99. await galata.notebook.selectCells(1);
  100. const nbPanel = await galata.notebook.getNotebookInPanel();
  101. await galata.capture.screenshot(imageName, nbPanel);
  102. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  103. });
  104. test('Re-run cell', async () => {
  105. const imageName = 're-run-cell';
  106. await galata.notebook.selectCells(1);
  107. await galata.notebook.clickToolbarItem('run');
  108. await galata.notebook.waitForRun();
  109. const nbPanel = await galata.notebook.getNotebookInPanel();
  110. await galata.capture.screenshot(imageName, nbPanel);
  111. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  112. });
  113. test('Delete Notebook', async () => {
  114. await galata.contents.deleteFile(fileName);
  115. expect(await galata.contents.fileExists(fileName)).toBeFalsy();
  116. });
  117. });