Skip to content

Commit

Permalink
feat(Cypress): refactor after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Fewwy committed Sep 27, 2022
1 parent 7b4790b commit 20c83ce
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 232 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//need the following line to explain typescript that cy is = to cypress
/// <reference types="cypress" />
// @ts-nocheck
import { DEFAULT_ROW_COUNT, DROPDOWN_ITEM, DROPDOWN_TOGGLE, PAGINATION_MENU, TOOLBAR } from './UIConstants';
import { cy } from 'cypress';
import { DROPDOWN_ITEM, DROPDOWN_TOGGLE, PAGINATION_MENU, TOOLBAR } from './selectors';

const DEFAULT_ROW_COUNT = 20;
const PAGINATION_VALUES = [10, 20, 50, 100];
const SORTING_ORDERS = ['ascending', 'descending'];

// FIXME improve syntax
export function itemsPerPage(totalLength, pageSize = DEFAULT_ROW_COUNT) {
let items = totalLength;
const array = [];
Expand Down Expand Up @@ -31,7 +32,9 @@ export function checkPaginationValues(expectedValues) {
});
}

export function changePagination(textInItem) {
export function changePagination(paginationValue) {
cy.get(TOOLBAR).find(PAGINATION_MENU).find(DROPDOWN_TOGGLE).click();
return cy.get(TOOLBAR).find(PAGINATION_MENU).find('ul[class=pf-c-options-menu__menu]').find(DROPDOWN_ITEM).contains(`${textInItem}`).click();
return cy.get(TOOLBAR).find(PAGINATION_MENU).find('ul[class=pf-c-options-menu__menu]').find(DROPDOWN_ITEM).contains(`${paginationValue}`).click();
}

export { DEFAULT_ROW_COUNT, PAGINATION_VALUES, SORTING_ORDERS };
41 changes: 41 additions & 0 deletions packages/utils/src/CypressUtils/TableUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Cypress, cy } from 'cypress';
import _ from 'lodash';

import { ROW, TABLE, TBODY, TITLE } from './selectors';

export function checkTableHeaders(expectedHeaders) {
/* patternfly/react-table-4.71.16, for some reason, renders extra empty `th` container;
thus, it is necessary to look at the additional `scope` attr to distinguish between visible columns
*/
return cy
.get('table th[scope="col"]')
.then(($els) => {
return _.map(Cypress.$.makeArray($els), 'innerText');
})
.should('deep.equal', expectedHeaders);
}

export function checkRowCounts(n, isSelectableTable = false) {
return isSelectableTable ? cy.get('table').find(TBODY).should('have.length', n) : cy.get('table').find(TBODY).find(ROW).should('have.length', n);
}

export function columnName2UrlParam(name) {
return name.toLowerCase().replace(/ /g, '_');
}

export function tableIsSortedBy(columnTitle) {
return cy.get('table').find(`th[data-label="${columnTitle}"]`).should('have.class', 'pf-c-table__sort pf-m-selected');
}

export function checkEmptyState(title, checkIcon = false) {
checkRowCounts(1);
cy.get(TABLE)
// @ts-ignore
// NEED TO FIX type error here
.ouiaId('empty-state')
.should('have.length', 1)
.within(() => {
cy.get('.pf-c-empty-state__icon').should('have.length', checkIcon ? 1 : 0);
cy.get(`h5${TITLE}`).should('have.text', title);
});
}
207 changes: 0 additions & 207 deletions packages/utils/src/CypressUtils/TableUtils.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
//need the following line to explain typescript that cy is = to cypress
/// <reference types="cypress" />
// @ts-nocheck
import { cy } from 'cypress';
/*
Utilities related to URL parameters passed for table filtering
*/

import _ from 'lodash';

import { CHIP, CHIP_GROUP } from './UIConstants';

const FILTERS_DROPDOWN = 'ul[class=pf-c-dropdown__menu]';
const FILTER_TOGGLE = 'button[class=pf-c-select__toggle]';
const VERSION_COMBINATIONS = [['4.18.12'], ['4.17.9'], ['3.0.3'], ['4.18.12', '4.17.9']];
import { CHIP, CHIP_GROUP, FILTERS_DROPDOWN, FILTER_TOGGLE } from './selectors';

/**
* A filter configuration
Expand Down Expand Up @@ -96,7 +90,7 @@ function filter(conf, data, filters) {
}

function removeAllChips() {
// FIXME does not work: CCXDEV-8090
// FIXME does not work: OCPADVISOR-22
// cy.get(CHIP_GROUP)
// .find(CHIP)
// .ouiaId('close', 'button')
Expand All @@ -109,4 +103,4 @@ function removeAllChips() {
});
}

export { applyFilters, urlParamConvert, hasChip, filter, removeAllChips, VERSION_COMBINATIONS };
export { applyFilters, urlParamConvert, hasChip, filter, removeAllChips };
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './UIConstants';
export * from './selectors';
export * from './UIFilters';
export * from './TableUtils';
export * from './PaginationUtils';
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ const TABLE = 'table';
const TABLE_HEADER = 'thead';
const ROWS_TOGGLER = `${TABLE_HEADER} .pf-c-table__toggle`;
const TITLE = '[data-ouia-component-type="PF4/Title"]';
const ouiaId = (id: string) => `[data-ouia-component-id="${id}"]`;
const DEFAULT_ROW_COUNT = 20;
const PAGINATION_VALUES = [10, 20, 50, 100];
const SORTING_ORDERS = ['ascending', 'descending'];
const ouiaId = (id) => `[data-ouia-component-id="${id}"]`;
const FILTERS_DROPDOWN = 'ul[class=pf-c-dropdown__menu]';
const FILTER_TOGGLE = 'button[class=pf-c-select__toggle]';

export {
ouiaId,
Expand All @@ -41,7 +40,6 @@ export {
TABLE_HEADER,
ROWS_TOGGLER,
TITLE,
DEFAULT_ROW_COUNT,
PAGINATION_VALUES,
SORTING_ORDERS,
FILTERS_DROPDOWN,
FILTER_TOGGLE,
};

0 comments on commit 20c83ce

Please sign in to comment.