Skip to content

Commit

Permalink
Merge pull request #478 from alfonsomthd/cleanup-cypress-folder
Browse files Browse the repository at this point in the history
Enable linting for Cypress folder
  • Loading branch information
openshift-merge-robot authored Oct 11, 2022
2 parents 9f1aa92 + 76cfd8e commit 4511aec
Show file tree
Hide file tree
Showing 25 changed files with 54 additions and 120 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ module.exports = {
'jsx-a11y/no-static-element-interactions': 'off',
'max-classes-per-file': 'off',
'max-len': 'off',
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'error',
'no-empty-pattern': 'off',
'no-nested-ternary': 'off',
'no-param-reassign': 'off',
Expand All @@ -84,6 +86,8 @@ module.exports = {
'no-unused-expressions': 'off',
'no-use-before-define': 'off',
'no-useless-catch': 'off',
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'operator-linebreak': 'off',
'prefer-destructuring': 'off',
'react/destructuring-assignment': 'off',
Expand Down
2 changes: 1 addition & 1 deletion cypress/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const CEPH_CLUSTER_NAME = `${STORAGE_CLUSTER_NAME}-cephcluster`;
* storage cluster's status.
*/
const CLUSTER_PHASE_QUERY = (name: string) => {
return `{range .items[*]}{.metadata.name==${name}\"}{.status.phase}{\"\\n\"}{end}`;
return `{range .items[*]}{.metadata.name==${name}"}{.status.phase}{"\\n"}{end}`;
};
const STORAGECLUSTER_PHASE = `"$(oc get storageclusters -n openshift-storage -o=jsonpath='${CLUSTER_PHASE_QUERY(
STORAGE_CLUSTER_NAME
Expand Down
2 changes: 1 addition & 1 deletion cypress/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import './support/login';

declare global {
namespace Cypress {
interface Chainable<Subject> {
interface Chainable {
install(encrypted?: boolean): Chainable<Element>;
}
}
Expand Down
7 changes: 5 additions & 2 deletions cypress/support/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { submitButton, masthead } from './views';

declare global {
namespace Cypress {
interface Chainable<Subject> {
interface Chainable {
login(
providerName?: string,
username?: string,
Expand Down Expand Up @@ -33,16 +33,19 @@ Cypress.Commands.add(
const idp = provider || KUBEADMIN_IDP;
cy.task('log', ` Logging in as ${username || KUBEADMIN_USERNAME}`);
cy.byLegacyTestID('login').should('be.visible');
// eslint-disable-next-line cypress/require-data-selectors
cy.get('body').then(($body) => {
if ($body.text().includes(idp)) {
cy.contains(idp).should('be.visible').click();
}
});
/* eslint-disable cypress/require-data-selectors */
cy.get('#inputUsername').type(username || KUBEADMIN_USERNAME);
cy.get('#inputPassword').type(
password || Cypress.env('BRIDGE_KUBEADMIN_PASSWORD')
);
cy.get(submitButton).click();
/* eslint-enable cypress/require-data-selectors */
masthead.username.shouldBeVisible();
});
}
Expand All @@ -61,7 +64,7 @@ Cypress.Commands.add('logout', () => {
cy.task('log', ' Logging out');
cy.byTestID('user-dropdown').click();
cy.byTestID('log-out').should('be.visible');
cy.byTestID('log-out').click({ force: true });
cy.byTestID('log-out').click({ force: true }); // eslint-disable-line cypress/no-force
cy.byLegacyTestID('login').should('be.visible');
});
});
4 changes: 3 additions & 1 deletion cypress/support/pages/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ export const app = {
cy.document().its('readyState').should('eq', 'complete');
},
waitForLoad: (timeout: number = 160000) => {
/* eslint-disable cypress/require-data-selectors */
cy.get('.co-m-loader', { timeout }).should('not.exist');
cy.get('.pf-c-spinner', { timeout }).should('not.exist');
cy.get('.skeleton-catalog--grid', { timeout }).should('not.exist');
cy.get('.loading-skeleton--table', { timeout }).should('not.exist');
/* eslint-enable cypress/require-data-selectors */
cy.byTestID('skeleton-detail-view', { timeout }).should('not.exist');
app.waitForDocumentLoad();
},
Expand All @@ -19,7 +21,7 @@ export const projectNameSpace = {

enterProjectName: (projectName: string) => {
cy.byLegacyTestID('modal-cancel-action').should('be.visible');
cy.get('#input-name').type(projectName);
cy.get('#input-name').type(projectName); // eslint-disable-line cypress/require-data-selectors
},

selectOrCreateProject: (projectName: string) => {
Expand Down
6 changes: 3 additions & 3 deletions cypress/support/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Shadow = Cypress.Shadow;
export {};
declare global {
namespace Cypress {
interface Chainable<Subject> {
interface Chainable {
byTestID(
selector: string,
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>
Expand Down Expand Up @@ -77,12 +77,12 @@ Cypress.Commands.add('clickNavLink', (path: [string, string?]) => {
cy.byTestID('nav')
.contains(path[0], { timeout: 10 * 1000 })
.should((el) => {
if ($(el).attr('aria-expanded') == 'false') {
if ($(el).attr('aria-expanded') === 'false') {
$(el).click();
}
});
if (path.length > 1) {
cy.get('#page-sidebar').contains(path[1]).click();
cy.get('#page-sidebar').contains(path[1]).click(); // eslint-disable-line cypress/require-data-selectors
}
});

Expand Down
2 changes: 1 addition & 1 deletion cypress/tests/block-pool-create.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createBlockPool, deleteBlockPoolFromCli } from '../views/block-pool';

/** @depricated testcases are moved to odf-console */
/** @deprecated testcases are moved to odf-console */
xdescribe('Test block pool creation under ODF UI', () => {
before(() => {
cy.login();
Expand Down
5 changes: 2 additions & 3 deletions cypress/tests/block-pool-delete.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { modal } from '../views/modals';

import { POOL_PROGRESS } from '../constants/storage-pool-const';
import {
poolName,
Expand All @@ -8,12 +6,13 @@ import {
verifyFooterActions,
poolMessage,
} from '../views/block-pool';
import { modal } from '../views/modals';
import { pvc } from '../views/pvc';
import { createStorageClass } from '../views/storage-class';

const pvcName: string = 'testing-pvc';

/** @depricated testcases are moved to odf-console */
/** @deprecated testcases are moved to odf-console */
xdescribe('Test block pool deletion under ODF UI', () => {
before(() => {
cy.login();
Expand Down
5 changes: 2 additions & 3 deletions cypress/tests/block-pool-update.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { modal } from '../views/modals';
import { POOL_PROGRESS } from '../constants/storage-pool-const';

import {
createBlockPool,
deleteBlockPoolFromCli,
verifyFooterActions,
verifyBlockPoolJSON,
poolMessage,
} from '../views/block-pool';
import { modal } from '../views/modals';

/** @depricated testcases are moved to odf-console */
/** @deprecated testcases are moved to odf-console */
xdescribe('Test block pool update under ODF UI', () => {
before(() => {
cy.login();
Expand Down
3 changes: 1 addition & 2 deletions cypress/tests/create-backing-store.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { commonFlows } from '../views/common';
import { createStore, Providers, testName } from '../views/store';
import { ODFCommon } from '../views/odf-common';
import { createStore, Providers, testName } from '../views/store';

describe('Tests creation of Backing Stores', () => {
before(() => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/tests/multiple-storageclass-selection.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { K8sResourceKind, getCurrentDeviceSetIndex } from '../mocks/ksm';
import {
testEbsSC,
testNoProvisionerSC,
getPVJSON,
} from '../mocks/storageclass';
import { K8sResourceKind, getCurrentDeviceSetIndex } from '../mocks/ksm';
import {
withJSONResult,
fetchStorageClusterJson,
Expand Down
13 changes: 6 additions & 7 deletions cypress/tests/obc-test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { expect } from 'chai';
import { testName } from '../utils/consts';
import { detailsPage } from '../views/details-page';
import { listPage } from '../views/list-page';
import { deployment } from '../mocks/deploymentData';
import {
ACCESS_KEY,
Expand All @@ -14,7 +10,10 @@ import {
OBC_STORAGE_CLASS,
OBC_STORAGE_CLASS_EXACT,
SECRET_KEY,
testName,
} from '../utils/consts';
import { detailsPage } from '../views/details-page';
import { listPage } from '../views/list-page';
import { CreateOBCHandler } from '../views/obcPage';

describe('Test Object Bucket Claim resource', () => {
Expand All @@ -34,7 +33,7 @@ describe('Test Object Bucket Claim resource', () => {

after(() => {
cy.visit(obcUrl);
obcHandler.deleteBucketClaim();
CreateOBCHandler.deleteBucketClaim();
cy.logout();
});

Expand All @@ -57,7 +56,7 @@ describe('Test Object Bucket Claim resource', () => {
});

cy.log('Test if secret data can be revealed');
obcHandler.revealHiddenValues();
CreateOBCHandler.revealHiddenValues();
cy.byTestID('secret-data').should(($h) => {
expect($h[0].innerText).to.equal('Endpoint');
expect($h[2].innerText).to.equal('Access Key');
Expand All @@ -70,7 +69,7 @@ describe('Test Object Bucket Claim resource', () => {
});

cy.log('Test if secret data can be hidden again');
obcHandler.hideValues();
CreateOBCHandler.hideValues();
cy.byTestID('copy-to-clipboard').as('secrets');
cy.get('@secrets').should(($el) => {
const childCount = $el.length;
Expand Down
4 changes: 2 additions & 2 deletions cypress/tests/object-service-dashboards.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Tests Buckets, Status, Object Storage Efficiency, and Resource Provide
beforeEach(() => {
ODFCommon.visitStorageDashboard();
cy.byLegacyTestID('horizontal-link-Storage Systems').first().click();
cy.byLegacyTestID('item-filter')
cy.byLegacyTestID('item-filter') // eslint-disable-line cypress/no-unnecessary-waiting
.type('ocs-storagecluster-storagesystem')
.wait(5000);
cy.byTestRows('resource-row').get('td a').first().click();
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('Tests Buckets, Status, Object Storage Efficiency, and Resource Provide
cy.byTestID('nb-resource-providers-card')
.invoke('text')
.then((text) => {
const s = parseInt(text);
const s = parseInt(text, 10);
expect(s).greaterThan(0);
});
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/tests/persistent-dashboard-check-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Check Persistent Dashboard', () => {

it('Check Inventory card is correct', () => {
cy.log('Check the total number of OCS nodes');
cy.get('.skeleton-activity').should('not.exist');
cy.get('.skeleton-activity').should('not.exist'); // eslint-disable-line cypress/require-data-selectors
cy.byTestID('inventory-nodes')
.invoke('text')
.then((text) => {
Expand Down
2 changes: 0 additions & 2 deletions cypress/views/common.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export const commonFlows = {
navigateToODF: () => {
cy.clickNavLink(['Storage', 'Data Foundation']);
//cy.byTestOperatorRow('OpenShift Data Foundation').click();
},
checkAll: () => cy.get('input[name=check-all]'),
};

export const commandPoll = (
Expand Down
5 changes: 2 additions & 3 deletions cypress/views/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ export const modal = {
submitShouldBeDisabled: () => cy.get(submitButton).should('be.disabled'),
// eslint-disable-next-line cypress/require-data-selectors
submitShouldBeEnabled: () => cy.get(submitButton).should('not.be.disabled'),
// eslint-disable-next-line cypress/no-force
cancel: (force: boolean = false) =>
cy.byLegacyTestID('modal-cancel-action').click({ force }),
// eslint-disable-next-line cypress/require-data-selectors,cypress/no-force
cy.byLegacyTestID('modal-cancel-action').click({ force }), // eslint-disable-line cypress/no-force
submit: (force: boolean = false) =>
// eslint-disable-next-line cypress/require-data-selectors,cypress/no-force
cy.byTestID('modal-submit-action').contains('Add').click({ force }),
modalTitleShouldContain: (modalTitle: string) =>
cy.byLegacyTestID('modal-title').should('contain.text', modalTitle),
Expand Down
10 changes: 5 additions & 5 deletions cypress/views/obcPage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { projectNameSpace } from '../support/pages/app';
import { DEPLOYMENT_REPLICAS_STATUS, MINUTE } from '../utils/consts';
import { MINUTE } from '../utils/consts';

export class CreateOBCHandler {
name: string;
Expand All @@ -25,21 +25,21 @@ export class CreateOBCHandler {
cy.byTestID('loading-indicator').should('not.exist');
cy.byTestID('sc-dropdown').should('be.visible').click();
cy.contains('openshift-storage.noobaa.io').click();
cy.get('button').contains('Create').click();
cy.byTestID('obc-create').click();
cy.byLegacyTestID('resource-title').contains(this.name, {
timeout: MINUTE,
});
}

revealHiddenValues() {
static revealHiddenValues() {
cy.contains('Reveal Values').click();
}

hideValues() {
static hideValues() {
cy.contains('Hide Values').click();
}

deleteBucketClaim() {
static deleteBucketClaim() {
cy.byTestID('loading-indicator').should('not.exist');
cy.log('Deleting Object Bucket Claim');
cy.byTestID('kebab-button').click();
Expand Down
6 changes: 4 additions & 2 deletions cypress/views/storage-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export const createStorageClass = (
);
cy.byTestID('dropdown-menu-item-link').click();

cy.log('Enable encryption');
encrypted && configureKms();
if (encrypted) {
cy.log('Enabling encryption');
configureKms();
}

cy.log(`Selecting block pool ${poolName}`);
cy.byTestID('pool-dropdown-toggle').click();
Expand Down
3 changes: 2 additions & 1 deletion cypress/views/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ const setupProvider = (provider: Providers, storeType: StoreType) => {
cy.byTestID('aws-region-dropdown').click();
cy.byTestDropDownMenu('us-east-1').click();
break;
case Providers.S3:
case Providers.S3: {
const ENDPOINT = 'http://test-endpoint.com';
cy.byTestID(`${storeType}-s3-endpoint`).type(ENDPOINT);
break;
}
default:
break;
}
Expand Down
25 changes: 0 additions & 25 deletions cypress/views/yaml-editor.ts

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
"ts-node": "ts-node -O '{\"module\":\"commonjs\"}' -I '/node_modules/(?!(@odf)/)/'",
"lint-css": "yarn stylelint packages/**/**/*.scss",
"lint-css-fix": "yarn stylelint packages/**/**/*.scss --fix",
"lint": "yarn eslint --ext .ts,.tsx ./packages/ && yarn lint-css",
"lint-fix": "yarn eslint --fix --ext .ts,.tsx ./packages/ && yarn lint-css-fix",
"lint-ts": "yarn eslint --ext .ts,.tsx .",
"lint-ts-fix": "yarn eslint --fix --ext .ts,.tsx .",
"lint": "yarn lint-ts && yarn lint-css",
"lint-fix": "yarn lint-ts-fix && yarn lint-css-fix",
"format": "yarn prettier -w .",
"format-test": "yarn prettier -c .",
"prepare": "husky install",
Expand Down Expand Up @@ -94,7 +96,6 @@
"@typescript-eslint/parser": "^4.28.5",
"buffer": "^6.0.3",
"cache-loader": "1.x",
"chai": "^4.3.6",
"comment-json": "4.x",
"copy-webpack-plugin": "^6.4.1",
"css-loader": "0.28.x",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const generatefooterButtons = (props: ModalFooterProps): FooterButtonProps => ({
variant: ButtonVariant.primary,
isLoading: true,
isDisabled: true,
onClick: () => {},
onClick: () => null,
},
{
id: 'modal-cancel-action',
Expand Down
Loading

0 comments on commit 4511aec

Please sign in to comment.