this.navigateTo();
this.getFirstTableCell(name).click();
}
+ cy.contains('Creating...').should('not.exist');
cy.contains('button', 'Edit').click();
this.expectBreadcrumbText('Edit');
}
cy.get('.breadcrumb-item.active').should('have.text', text);
}
+ getTabs() {
+ return cy.get('.nav.nav-tabs li');
+ }
+
+ getTab(tabName: string) {
+ return cy.contains('.nav.nav-tabs li', new RegExp(`^${tabName}$`));
+ }
+
getTabText(index: number) {
- return cy.get('.nav.nav-tabs li').its(index).text();
+ return this.getTabs().its(index).text();
}
getTabsCount(): any {
- return cy.get('.nav.nav-tabs li').its('length');
+ return this.getTabs().its('length');
}
/**
return cy.get('cd-table .dataTables_wrapper');
}
- getTableTotalCount() {
- this.waitDataTableToLoad();
-
- return cy.get('.datatable-footer-inner .page-count span').then(($elem) => {
- const text = $elem
- .filter((_i, e) => e.innerText.includes('total'))
- .first()
- .text();
-
- return Number(text.match(/(\d+)\s+total/)[1]);
- });
+ private getTableCountSpan(spanType: 'selected' | 'found' | 'total') {
+ return cy.contains('.datatable-footer-inner .page-count span', spanType);
}
- getTableSelectedCount() {
+ // Get 'selected', 'found', or 'total' row count of a table.
+ getTableCount(spanType: 'selected' | 'found' | 'total') {
this.waitDataTableToLoad();
-
- return cy.get('.datatable-footer-inner .page-count span').then(($elem) => {
+ return this.getTableCountSpan(spanType).then(($elem) => {
const text = $elem
- .filter((_i, e) => e.innerText.includes('selected'))
+ .filter((_i, e) => e.innerText.includes(spanType))
.first()
.text();
- return Number(text.match(/(\d+)\s+selected/)[1]);
+ return Number(text.match(/(\d+)\s+\w*/)[1]);
});
}
- getTableFoundCount() {
+ // Wait until selected', 'found', or 'total' row count of a table equal to a number.
+ expectTableCount(spanType: 'selected' | 'found' | 'total', count: number) {
this.waitDataTableToLoad();
-
- return cy.get('.datatable-footer-inner .page-count span').then(($elem) => {
- const text = $elem
- .filter((_i, e) => e.innerText.includes('found'))
- .first()
- .text();
-
- return Number(text.match(/(\d+)\s+found/)[1]);
+ this.getTableCountSpan(spanType).should(($elem) => {
+ const text = $elem.first().text();
+ expect(Number(text.match(/(\d+)\s+\w*/)[1])).to.equal(count);
});
}
}
}
+ getTableCell(columnIndex: number, exactContent: string) {
+ this.waitDataTableToLoad();
+ this.seachTable(exactContent);
+ return cy.contains(
+ `datatable-body-row datatable-body-cell:nth-child(${columnIndex})`,
+ new RegExp(`^${exactContent}$`)
+ );
+ }
+
getExpandCollapseElement(content?: string) {
this.waitDataTableToLoad();
return cy.get('.tc_expand-collapse').first();
}
}
+
/**
* Gets column headers of table
*/
filterTable(name: string, option: string) {
this.waitDataTableToLoad();
- cy.get('.tc_filter_name > a').click();
+ cy.get('.tc_filter_name > button').click();
cy.contains(`.tc_filter_name .dropdown-item`, name).click();
- cy.get('.tc_filter_option > a').click();
+ cy.get('.tc_filter_option > button').click();
cy.contains(`.tc_filter_option .dropdown-item`, option).click();
}
+ setPageSize(size: string) {
+ cy.get('cd-table .dataTables_paginate input').first().clear({ force: true }).type(size);
+ }
+
seachTable(text: string) {
this.waitDataTableToLoad();
- cy.get('cd-table .dataTables_paginate input').first().clear().type('10');
+ this.setPageSize('10');
cy.get('cd-table .search input').first().clear().type(text);
}
return cy.get('cd-table .search button').click();
}
+ // Click the action button
+ clickActionButton(action: string) {
+ cy.get('.table-actions button.dropdown-toggle').first().click(); // open submenu
+ cy.get(`button.${action}`).click(); // click on "action" menu item
+ }
+
/**
* This is a generic method to delete table rows.
* It will select the first row that contains the provided name and delete it.
* After that it will wait until the row is no longer displayed.
+ * @param name The string to search in table cells.
+ * @param columnIndex If provided, search string in columnIndex column.
*/
- delete(name: string) {
+ delete(name: string, columnIndex?: number) {
// Selects row
- this.getFirstTableCell(name).click();
+ const getRow = columnIndex
+ ? this.getTableCell.bind(this, columnIndex)
+ : this.getFirstTableCell.bind(this);
+ getRow(name).click();
// Clicks on table Delete button
- cy.get('.table-actions button.dropdown-toggle').first().click(); // open submenu
- cy.get('li.delete a').click(); // click on "delete" menu item
+ this.clickActionButton('delete');
// Confirms deletion
- cy.get('.custom-control-label').click();
- cy.contains('button', 'Delete').click();
+ cy.get('cd-modal .custom-control-label').click();
+ cy.contains('cd-modal button', 'Delete').click();
// Wait for modal to close
cy.get('cd-modal').should('not.exist');
// Waits for item to be removed from table
- this.getFirstTableCell(name).should('not.exist');
+ getRow(name).should('not.exist');
}
}