notebook-edit.test.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 Edit', () => {
  7. beforeAll(async () => {
  8. await galata.resetUI();
  9. galata.context.capturePrefix = 'notebook-edit';
  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('Execute Code cell', async () => {
  37. await galata.notebook.runCell(2, true);
  38. const imageName = 'run-cell';
  39. const nbPanel = await galata.notebook.getNotebookInPanel();
  40. await galata.capture.screenshot(imageName, nbPanel);
  41. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  42. });
  43. test('Re-edit after execution', async () => {
  44. await galata.notebook.setCell(2, 'code', '2 ** 6');
  45. const imageName = 'reedit-cell';
  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('Execute again', async () => {
  51. await galata.notebook.runCell(2, true);
  52. const imageName = 'execute-again';
  53. const nbPanel = await galata.notebook.getNotebookInPanel();
  54. await galata.capture.screenshot(imageName, nbPanel);
  55. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  56. });
  57. test('Copy-Paste cell', async () => {
  58. let imageName = 'copy-paste-cell';
  59. await galata.notebook.selectCells(1);
  60. await galata.menu.clickMenuItem('Edit>Copy Cells');
  61. await galata.notebook.selectCells(0);
  62. await galata.menu.clickMenuItem('Edit>Paste Cells Above');
  63. let nbPanel = await galata.notebook.getNotebookInPanel();
  64. await galata.capture.screenshot(imageName, nbPanel);
  65. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  66. });
  67. test('Cut-Paste cell', async () => {
  68. const imageName = 'cut-paste-cell';
  69. await galata.notebook.selectCells(0);
  70. await galata.menu.clickMenuItem('Edit>Cut Cells');
  71. await galata.notebook.selectCells(2);
  72. await galata.menu.clickMenuItem('Edit>Paste Cells Below');
  73. const nbPanel = await galata.notebook.getNotebookInPanel();
  74. await galata.capture.screenshot(imageName, nbPanel);
  75. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  76. });
  77. test('Paste-Replace cell', async () => {
  78. const imageName = 'paste-replace-cell';
  79. await galata.notebook.selectCells(0);
  80. await galata.menu.clickMenuItem('Edit>Copy Cells');
  81. await galata.notebook.selectCells(3);
  82. await galata.menu.clickMenuItem('Edit>Paste Cells and Replace');
  83. const nbPanel = await galata.notebook.getNotebookInPanel();
  84. await galata.capture.screenshot(imageName, nbPanel);
  85. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  86. });
  87. test('Delete cell', async () => {
  88. const imageName = 'delete-cell';
  89. await galata.notebook.selectCells(3);
  90. await galata.menu.clickMenuItem('Edit>Delete Cells');
  91. const nbPanel = await galata.notebook.getNotebookInPanel();
  92. await galata.capture.screenshot(imageName, nbPanel);
  93. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  94. });
  95. test('Select all cells', async () => {
  96. const imageName = 'select-all-cells';
  97. await galata.notebook.selectCells(3);
  98. await galata.menu.clickMenuItem('Edit>Select All Cells');
  99. const nbPanel = await galata.notebook.getNotebookInPanel();
  100. await galata.capture.screenshot(imageName, nbPanel);
  101. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  102. });
  103. test('Deselect all cells', async () => {
  104. const imageName = 'deselect-all-cells';
  105. await galata.notebook.selectCells(3);
  106. await galata.menu.clickMenuItem('Edit>Deselect All Cells');
  107. const nbPanel = await galata.notebook.getNotebookInPanel();
  108. await galata.capture.screenshot(imageName, nbPanel);
  109. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  110. });
  111. test('Move cells up', async () => {
  112. const imageName = 'move-cell-up';
  113. await galata.notebook.selectCells(1);
  114. await galata.menu.clickMenuItem('Edit>Move Cells Up');
  115. const nbPanel = await galata.notebook.getNotebookInPanel();
  116. await galata.capture.screenshot(imageName, nbPanel);
  117. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  118. });
  119. test('Move cells down', async () => {
  120. const imageName = 'move-cell-down';
  121. await galata.notebook.selectCells(0);
  122. await galata.menu.clickMenuItem('Edit>Move Cells Down');
  123. const nbPanel = await galata.notebook.getNotebookInPanel();
  124. await galata.capture.screenshot(imageName, nbPanel);
  125. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  126. });
  127. test('Split cell', async () => {
  128. const page = galata.context.page;
  129. const imageName = 'split-cell';
  130. await galata.notebook.enterCellEditingMode(2);
  131. await page.keyboard.press('End');
  132. await page.keyboard.press('Enter');
  133. await page.keyboard.insertText('3 ** 2');
  134. await page.keyboard.press('Home');
  135. await galata.menu.clickMenuItem('Edit>Split Cell');
  136. const nbPanel = await galata.notebook.getNotebookInPanel();
  137. await galata.capture.screenshot(imageName, nbPanel);
  138. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  139. });
  140. test('Merge split cells', async () => {
  141. const imageName = 'merge-cells';
  142. await galata.notebook.selectCells(2, 3);
  143. await galata.menu.clickMenuItem('Edit>Merge Selected Cells');
  144. const nbPanel = await galata.notebook.getNotebookInPanel();
  145. await galata.capture.screenshot(imageName, nbPanel);
  146. expect(await galata.capture.compareScreenshot(imageName)).toBe('same');
  147. });
  148. test('Delete Notebook', async () => {
  149. await galata.contents.deleteFile(fileName);
  150. expect(await galata.contents.fileExists(fileName)).toBeFalsy();
  151. });
  152. });