pythoneditor.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Copyright 2018-2022 Elyra Authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. describe('Python Editor tests', () => {
  17. before(() => {
  18. cy.resetJupyterLab();
  19. cy.bootstrapFile('helloworld.py'); // load python file used to check existing contents
  20. });
  21. after(() => {
  22. // delete files created for testing
  23. cy.deleteFile('untitled*.py');
  24. cy.deleteFile('helloworld.py'); // delete python file used for testing
  25. // Delete runtime configuration used for testing
  26. cy.exec('elyra-metadata remove runtimes --name=kfp_test_runtime', {
  27. failOnNonZeroExit: false
  28. });
  29. });
  30. // Python Editor Tests
  31. it('opens blank Python editor from launcher', () => {
  32. cy.createNewScriptEditor('Python');
  33. cy.get('.lm-TabBar-tab[data-type="document-title"]');
  34. });
  35. it('check Python editor tab right click content', () => {
  36. cy.checkRightClickTabContent('Python');
  37. });
  38. it('close editor', () => {
  39. cy.closeTab(-1);
  40. });
  41. it('open Python file with expected content', () => {
  42. cy.openFileAndCheckContent('py');
  43. });
  44. it('opens blank Python editor from menu', () => {
  45. cy.findByRole('menuitem', { name: /file/i }).click();
  46. cy.findByText(/^new$/i).click();
  47. cy.get(
  48. '[data-command="script-editor:create-new-python-editor"] > .lm-Menu-itemLabel'
  49. ).click();
  50. });
  51. it('check toolbar and its content for Python file', () => {
  52. cy.checkScriptEditorToolbarContent();
  53. });
  54. it('check kernel dropdown has Python option', () => {
  55. cy.get('.elyra-ScriptEditor .jp-Toolbar select > option[value*=python]');
  56. });
  57. it('click the Run as Pipeline button should display dialog', () => {
  58. // Install runtime configuration
  59. cy.installRuntimeConfig({ type: 'kfp' });
  60. clickRunAsPipelineButton();
  61. // Check for expected dialog title
  62. cy.get('.jp-Dialog-header').should('have.text', 'Run file as pipeline');
  63. // Dismiss dialog
  64. cy.get('button.jp-mod-reject').click();
  65. // Close editor tab
  66. cy.closeTab(-1);
  67. });
  68. it('click the Run as Pipeline button on unsaved file should display save dialog', () => {
  69. // Create new python editor
  70. cy.createNewScriptEditor('Python');
  71. // Add some text to the editor (wait code editor to load)
  72. cy.wait(1000);
  73. cy.get('span[role="presentation"]')
  74. .should('be.visible')
  75. .type('print("test")');
  76. cy.wait(500);
  77. cy.dismissAssistant('scripteditor');
  78. clickRunAsPipelineButton();
  79. // Check expected save and submit dialog message
  80. cy.contains('.jp-Dialog-header', /this file contains unsaved changes/i);
  81. // Dismiss save and submit dialog
  82. cy.get('button.jp-mod-reject').click();
  83. // Close editor tab
  84. cy.closeTab(-1);
  85. // Dismiss save your work dialog by discarding changes
  86. cy.get('button.jp-mod-warn').click();
  87. });
  88. // check for new output console and scroll up/down buttons
  89. it('opens new output console', () => {
  90. cy.openHelloWorld('py');
  91. clickRunButton();
  92. cy.get('[id=tab-ScriptEditor-output]').should(
  93. 'have.text',
  94. 'Console Output'
  95. );
  96. cy.get('button[title="Top"]').should('be.visible');
  97. cy.get('button[title="Bottom"]').should('be.visible');
  98. //close console tab
  99. cy.closeTab(-1);
  100. // Close editor tab
  101. cy.closeTab(-1);
  102. });
  103. // TODO: Investigate CI failures commented below
  104. // check for expected output on running a valid code
  105. // it('checks for valid output', () => {
  106. // cy.openHelloWorld('py');
  107. // clickRunButton();
  108. // cy.wait(1000);
  109. // cy.get('.elyra-ScriptEditor-OutputArea-output').should(
  110. // 'have.text',
  111. // 'Hello Elyra\n'
  112. // );
  113. // //close console tab
  114. // cy.closeTab(-1);
  115. // // Close editor tab
  116. // cy.closeTab(-1);
  117. // });
  118. // check for error message running an invalid code
  119. // it('checks for Error message', () => {
  120. // cy.createNewScriptEditor('Python');
  121. // cy.wait(1000);
  122. // // Add some code with syntax error to the editor (wait code editor to load)
  123. // cy.get('.CodeMirror-lines')
  124. // .first()
  125. // .should('be.visible')
  126. // .type('print"test"');
  127. // cy.wait(500);
  128. // cy.dismissAssistant('scripteditor');
  129. // clickRunButton();
  130. // cy.findByText(/Error : SyntaxError/i).should('be.visible');
  131. // //close console tab
  132. // cy.closeTab(-1);
  133. // // Close editor tab
  134. // cy.closeTab(-1);
  135. // // Dismiss save your work dialog by discarding changes
  136. // cy.get('button.jp-mod-warn').click();
  137. // });
  138. it('check icons', () => {
  139. // Check file menu editor contents
  140. cy.findByRole('menuitem', { name: /file/i }).click();
  141. cy.findByText(/^new$/i).click();
  142. cy.get(
  143. '[data-command="script-editor:create-new-python-editor"] svg[data-icon="elyra:pyIcon"]'
  144. );
  145. // Check python icons from launcher & file explorer
  146. cy.get(
  147. '.jp-LauncherCard[data-category="Elyra"][title="Create a new Python Editor"] svg[data-icon="elyra:pyIcon"]'
  148. ).click();
  149. cy.get(
  150. '#filebrowser [title*="Name: untitled1.py"] svg[data-icon="elyra:pyIcon"]'
  151. );
  152. cy.closeTab(-1);
  153. });
  154. });
  155. // ------------------------------
  156. // ----- Utility Functions
  157. // ------------------------------
  158. // Click Run as Pipeline button
  159. const clickRunAsPipelineButton = (): void => {
  160. cy.findByText(/run as pipeline/i).click();
  161. };
  162. // Click Run button
  163. const clickRunButton = (): void => {
  164. cy.get('button[title="Run"]', { timeout: 30000 }).click();
  165. };