123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- /*
- * Copyright 2018-2022 Elyra Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import '@testing-library/cypress/add-commands';
- import './../utils/snapshots/add-commands';
- Cypress.Commands.add('installRuntimeConfig', ({ type } = {}): void => {
- const kfpRuntimeInstallCommand =
- 'elyra-metadata create runtimes \
- --schema_name=kfp \
- --display_name="KFP Test Runtime" \
- --api_endpoint=https://kubernetes-service.ibm.com/pipeline \
- --cos_endpoint=http://0.0.0.0:9000 \
- --cos_username=minioadmin \
- --cos_password=minioadmin \
- --cos_bucket=test-bucket';
- const airflowRuntimeInstallCommand =
- 'elyra-metadata create runtimes \
- --schema_name=airflow \
- --display_name="Airflow Test Runtime" \
- --api_endpoint=https://kubernetes-service.ibm.com/pipeline \
- --github_repo=akchinstc/test-repo \
- --github_branch=main \
- --github_repo_token=xxxxxxxx \
- --github_api_endpoint=https://api.github.com \
- --cos_endpoint=http://0.0.0.0:9000 \
- --cos_username=minioadmin \
- --cos_password=minioadmin \
- --cos_bucket=test-bucket';
- cy.exec(
- type === 'kfp' ? kfpRuntimeInstallCommand : airflowRuntimeInstallCommand,
- { failOnNonZeroExit: false }
- );
- });
- // Only used for testing filling out form for runtime metadata editor
- Cypress.Commands.add('createRuntimeConfig', ({ type } = {}): void => {
- cy.findByRole('tab', { name: /runtimes/i }).click();
- cy.findByRole('button', { name: /create new runtime/i }).click();
- if (type === 'kfp') {
- cy.findByRole('menuitem', { name: /kubeflow pipelines/i }).click();
- } else {
- cy.findByRole('menuitem', { name: /apache airflow/i }).click();
- }
- cy.findByLabelText(/^name/i).type(`${type} Test Runtime`);
- if (type === 'kfp') {
- cy.findByLabelText(/kubeflow .* endpoint \*/i).type(
- 'https://kubernetes-service.ibm.com/pipeline'
- );
- } else {
- cy.findByLabelText(/airflow .* endpoint/i).type(
- 'https://kubernetes-service.ibm.com/pipeline'
- );
- cy.findByLabelText(/github .* repository \*/i).type('akchinstc/test-repo');
- cy.findByLabelText(/github .* branch/i).type('main');
- cy.findByLabelText(/personal access token/i).type('xxxxxxxx');
- // Check the default value is displayed on github api endpoint field
- cy.findByLabelText(/github .* endpoint/i).should(
- 'have.value',
- 'https://api.github.com'
- );
- }
- cy.findByLabelText(/object storage endpoint/i).type('http://0.0.0.0:9000');
- cy.findByLabelText(/object storage username/i).type('minioadmin');
- cy.findByLabelText(/object storage password/i).type('minioadmin');
- cy.findByLabelText(/object storage bucket/i).type('test-bucket');
- // save it
- cy.findByRole('button', { name: /save/i }).click();
- // reset runtimes widget
- cy.findByRole('tab', { name: /runtimes/i }).click();
- });
- Cypress.Commands.add('createExampleComponentCatalog', ({ type } = {}): void => {
- cy.on('fail', e => {
- console.error(
- `Example catalog connectors do not appear to be installed.\n${e}`
- );
- throw new Error(
- `Example catalog connectors do not appear to be installed.\n${e}`
- );
- });
- cy.findByRole('tab', { name: /component catalogs/i }).click();
- cy.findByRole('button', { name: /create new component catalog/i }).click();
- if (type === 'kfp') {
- cy.findByRole('menuitem', {
- name: /new kubeflow pipelines example components catalog/i
- }).click();
- } else {
- cy.findByRole('menuitem', {
- name: /new apache airflow example components catalog/i
- }).click();
- }
- cy.findByLabelText(/^name/i).type('Example Components');
- // save it
- cy.findByRole('button', { name: /save/i }).click();
- });
- Cypress.Commands.add('deleteFile', (name: string): void => {
- cy.exec(`find build/cypress-tests/ -name "${name}" -delete`, {
- failOnNonZeroExit: false
- });
- });
- Cypress.Commands.add('createPipeline', ({ name, type } = {}): void => {
- if (name === undefined) {
- switch (type) {
- case 'kfp':
- cy.get(
- '.jp-LauncherCard[data-category="Elyra"][title="Kubeflow Pipelines Pipeline Editor"]'
- ).click();
- break;
- case 'airflow':
- cy.get(
- '.jp-LauncherCard[data-category="Elyra"][title="Apache Airflow Pipeline Editor"]'
- ).click();
- break;
- default:
- cy.get(
- '.jp-LauncherCard[data-category="Elyra"][title="Generic Pipeline Editor"]'
- ).click();
- break;
- }
- } else {
- cy.writeFile(`build/cypress-tests/${name}`, '');
- cy.openFile(name);
- }
- cy.get('.common-canvas-drop-div');
- // wait an additional 300ms for the list of items to settle
- cy.wait(300);
- });
- Cypress.Commands.add('openDirectory', (name: string): void => {
- cy.findByRole('listitem', {
- name: (n, _el) => n.includes(name)
- }).dblclick();
- });
- Cypress.Commands.add('addFileToPipeline', (name: string): void => {
- cy.findByRole('listitem', {
- name: (n, _el) => n.includes(name)
- }).rightclick();
- cy.findByRole('menuitem', { name: /add file to pipeline/i }).click();
- });
- Cypress.Commands.add('dragAndDropFileToPipeline', (name: string): void => {
- const dragItem = cy.findByRole('listitem', {
- name: (n, _el) => n.includes(name)
- });
- dragItem.trigger('mousedown', { button: 0 });
- // drop item into canvas
- cy.get('.d3-svg-background')
- .trigger('mousemove')
- .trigger('mouseup', { button: 0, force: true })
- .wait(100);
- });
- Cypress.Commands.add('savePipeline', (): void => {
- cy.findByRole('button', { name: /save pipeline/i }).click();
- // can take a moment to register as saved in ci
- cy.wait(1000);
- });
- Cypress.Commands.add('openFile', (name: string): void => {
- cy.findByRole('listitem', {
- name: (n, _el) => n.includes(name),
- timeout: 50000
- }).dblclick();
- });
- Cypress.Commands.add('bootstrapFile', (name: string): void => {
- cy.readFile(`tests/assets/${name}`).then((file: any) => {
- cy.writeFile(`build/cypress-tests/${name}`, file);
- });
- });
- Cypress.Commands.add('resetJupyterLab', (): void => {
- // open jupyterlab with a clean workspace
- cy.visit('?token=test&reset');
- cy.findByRole('tab', { name: /file browser/i, timeout: 25000 }).should(
- 'exist'
- );
- });
- Cypress.Commands.add('checkTabMenuOptions', (fileType: string): void => {
- cy.findByRole('tab', { name: /\.pipeline/i }).rightclick();
- cy.findAllByRole('menuitem', { name: new RegExp(fileType, 'i') }).should(
- 'exist'
- );
- //dismiss menu
- cy.get('[aria-label="Canvas"]').click({ force: true });
- });
- Cypress.Commands.add('closeTab', (index: number): void => {
- cy.get('.lm-TabBar-tabCloseIcon:visible')
- .eq(index)
- .click();
- });
- Cypress.Commands.add('createNewScriptEditor', (language: string): void => {
- cy.get(
- `.jp-LauncherCard[data-category="Elyra"][title="Create a new ${language} Editor"]:visible`
- ).click();
- });
|