mirror of https://github.com/nocodb/nocodb
Raju Udava
3 years ago
2 changed files with 299 additions and 55 deletions
@ -0,0 +1,148 @@ |
|||||||
|
|
||||||
|
const genTest = (type) => { |
||||||
|
|
||||||
|
describe(`${type.toUpperCase()} api - LookUp column`, () => { |
||||||
|
|
||||||
|
// to retrieve few v-input nodes from their label
|
||||||
|
//
|
||||||
|
const fetchParentFromLabel = (label) => { |
||||||
|
cy.get('label') |
||||||
|
.contains(label) |
||||||
|
.parents('.v-input') |
||||||
|
.click() |
||||||
|
} |
||||||
|
|
||||||
|
// Run once before test- create project (rest/graphql)
|
||||||
|
//
|
||||||
|
before(() => { |
||||||
|
cy.waitForSpinners(); |
||||||
|
|
||||||
|
// create project
|
||||||
|
//
|
||||||
|
if (type === 'rest') { |
||||||
|
cy.openOrCreateRestProject({ new: true }) |
||||||
|
} else { |
||||||
|
cy.openOrCreateGqlProject({ new: true }) |
||||||
|
} |
||||||
|
|
||||||
|
// open a table to work on views
|
||||||
|
//
|
||||||
|
cy.openTableTab('City'); |
||||||
|
}) |
||||||
|
|
||||||
|
// Routine to create a new look up column
|
||||||
|
//
|
||||||
|
const addLookUpColumn = (childTable, childCol) => { |
||||||
|
|
||||||
|
// (+) icon at end of column header (to add a new column)
|
||||||
|
// opens up a pop up window
|
||||||
|
//
|
||||||
|
cy.get('.new-column-header').click() |
||||||
|
|
||||||
|
// Redundant to feed column name. as alias is displayed & referred for
|
||||||
|
cy.get('.nc-column-name-input input').clear().type(childCol) |
||||||
|
|
||||||
|
// Column data type: to be set to lookup in this context
|
||||||
|
cy.get('.nc-ui-dt-dropdown').click() |
||||||
|
cy.getActiveMenu().contains('Lookup').click() |
||||||
|
|
||||||
|
// Configure Child table & column names
|
||||||
|
fetchParentFromLabel('Child Table') |
||||||
|
cy.getActiveMenu().contains(childTable).click() |
||||||
|
|
||||||
|
fetchParentFromLabel('Child column') |
||||||
|
cy.getActiveMenu().contains(childCol).click() |
||||||
|
|
||||||
|
// click on Save
|
||||||
|
cy.get('.nc-col-create-or-edit-card').contains('Save').click() |
||||||
|
cy.wait(1000) |
||||||
|
|
||||||
|
// Verify if column exists.
|
||||||
|
//
|
||||||
|
cy.get(`th:contains(${childCol})`) |
||||||
|
.should('exist'); |
||||||
|
cy.wait(500) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
// routine to delete column
|
||||||
|
//
|
||||||
|
const deleteColumnByName = (childCol) => { |
||||||
|
|
||||||
|
// verify if column exists before delete
|
||||||
|
cy.get(`th:contains(${childCol})`) |
||||||
|
.should('exist'); |
||||||
|
|
||||||
|
// delete opiton visible on mouse-over
|
||||||
|
cy.get(`th:contains(${childCol}) .mdi-menu-down`) |
||||||
|
.trigger('mouseover') |
||||||
|
.click() |
||||||
|
|
||||||
|
// delete/ confirm on pop-up
|
||||||
|
cy.get('.nc-column-delete').click() |
||||||
|
cy.getActiveModal().find('button:contains(Confirm)').click() |
||||||
|
|
||||||
|
// validate if deleted (column shouldnt exist)
|
||||||
|
cy.get(`th:contains(${childCol})`) |
||||||
|
.should('not.exist'); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
///////////////////////////////////////////////////
|
||||||
|
// Test case
|
||||||
|
|
||||||
|
it('Add Lookup column (Address, District) & Delete', () => { |
||||||
|
|
||||||
|
addLookUpColumn('Address', 'District') |
||||||
|
|
||||||
|
// Verify first entry, will be displayed as alias here 'childColumn (from childTable)'
|
||||||
|
cy.get(`tbody > :nth-child(1) > [data-col="District (from Address)"]`) |
||||||
|
.contains('Galicia') |
||||||
|
.should('exist') |
||||||
|
|
||||||
|
deleteColumnByName('District') |
||||||
|
|
||||||
|
}) |
||||||
|
|
||||||
|
it('Add Lookup column (Country, CountryId) & Delete', () => { |
||||||
|
|
||||||
|
addLookUpColumn('Country', 'CountryId') |
||||||
|
|
||||||
|
// Verify first entry, will be displayed as alias here 'childColumn (from childTable)'
|
||||||
|
cy.get(`tbody > :nth-child(1) > [data-col="CountryId (from Country)"]`) |
||||||
|
.contains('87') |
||||||
|
.should('exist') |
||||||
|
|
||||||
|
deleteColumnByName('CountryId') |
||||||
|
|
||||||
|
}) |
||||||
|
|
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
genTest('rest') |
||||||
|
genTest('graphql') |
||||||
|
|
||||||
|
/** |
||||||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd |
||||||
|
* |
||||||
|
* @author Pranav C Balan <pranavxc@gmail.com> |
||||||
|
* @author Raju Udava <sivadstala@gmail.com> |
||||||
|
* |
||||||
|
* @license GNU AGPL version 3 or any later version |
||||||
|
* |
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU Affero General Public License as |
||||||
|
* published by the Free Software Foundation, either version 3 of the |
||||||
|
* License, or (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU Affero General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU Affero General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* |
||||||
|
*/ |
@ -1,102 +1,198 @@ |
|||||||
|
|
||||||
const genTest = (type) => { |
const genTest = (type) => { |
||||||
|
|
||||||
describe(`${type.toUpperCase()} api - Rollup column`, () => { |
describe(`${type.toUpperCase()} api - RollUp column`, () => { |
||||||
const colName = 'column_name' + Date.now(); |
|
||||||
const updatedColName = 'updated_name' + Date.now(); |
// to retrieve few v-input nodes from their label
|
||||||
|
//
|
||||||
|
const fetchParentFromLabel = (label) => { |
||||||
|
cy.get('label') |
||||||
|
.contains(label) |
||||||
|
.parents('.v-input') |
||||||
|
.click() |
||||||
|
} |
||||||
|
|
||||||
|
// Run once before test- create project (rest/graphql)
|
||||||
|
//
|
||||||
before(() => { |
before(() => { |
||||||
cy.waitForSpinners(); |
cy.waitForSpinners(); |
||||||
|
|
||||||
|
// create project
|
||||||
|
//
|
||||||
if (type === 'rest') { |
if (type === 'rest') { |
||||||
cy.openOrCreateRestProject({ |
cy.openOrCreateRestProject({ new: true }) |
||||||
new:true |
|
||||||
}); |
|
||||||
} else { |
} else { |
||||||
cy.openOrCreateGqlProject({ |
cy.openOrCreateGqlProject({ new: true }) |
||||||
new:true |
|
||||||
}); |
|
||||||
} |
} |
||||||
|
|
||||||
|
// open a table to work on views
|
||||||
|
//
|
||||||
cy.openTableTab('Country'); |
cy.openTableTab('Country'); |
||||||
}); |
}) |
||||||
|
|
||||||
|
|
||||||
|
// Routine to create a new look up column
|
||||||
|
//
|
||||||
|
// Input:
|
||||||
|
// columnName: name to be displayed on column
|
||||||
|
// childTable: child-table name to look up to
|
||||||
|
// childCol: child-column name from child-table above to look up to
|
||||||
|
// aggregateFunc: can be one of count/ sum/ ..
|
||||||
|
//
|
||||||
|
const addLookUpColumn = (columnName, childTable, childCol, aggregateFunc) => { |
||||||
|
|
||||||
it('Add rollup column', () => { |
// (+) icon at end of column header (to add a new column)
|
||||||
|
// opens up a pop up window
|
||||||
|
//
|
||||||
|
cy.get('.new-column-header').click() |
||||||
|
|
||||||
cy.get('.v-window-item--active .nc-grid tr > th:last button').click({force: true}); |
// Column name
|
||||||
|
cy.get('.nc-column-name-input input').clear().type(`${columnName}{enter}`) |
||||||
|
|
||||||
cy.get('.nc-column-name-input input').clear().type(colName) |
// Column data type: to be set to rollup in this context
|
||||||
|
// Type 'Rollup' ensures item outside view is also listed (note, rollup is at bottom of scroll list)
|
||||||
|
cy.get('.nc-ui-dt-dropdown').click().type('Rollup') |
||||||
|
cy.getActiveMenu().contains('Rollup').click({ force: true }) |
||||||
|
|
||||||
cy.get('.nc-ui-dt-dropdown').click() |
// Configure Child table & column names
|
||||||
cy.getActiveMenu().contains('Rollup').click() |
fetchParentFromLabel('Child Table') |
||||||
|
cy.getActiveMenu().contains(childTable).click() |
||||||
|
|
||||||
cy.get('.nc-rollup-table').click(); |
fetchParentFromLabel('Child column') |
||||||
cy.getActiveMenu().contains('City').click(); |
cy.getActiveMenu().contains(childCol).click() |
||||||
cy.get('.nc-rollup-column').click(); |
|
||||||
cy.getActiveMenu().contains('CityId').click(); |
|
||||||
cy.get('.nc-rollup-fn').click(); |
|
||||||
cy.getActiveMenu().contains('count').click(); |
|
||||||
|
|
||||||
|
fetchParentFromLabel('Aggregate function') |
||||||
|
cy.getActiveMenu().contains(aggregateFunc).click() |
||||||
|
|
||||||
|
// click on Save
|
||||||
cy.get('.nc-col-create-or-edit-card').contains('Save').click() |
cy.get('.nc-col-create-or-edit-card').contains('Save').click() |
||||||
cy |
cy.wait(1000) |
||||||
.get(`th:contains(${colName})`) |
|
||||||
|
// Verify if column exists.
|
||||||
|
//
|
||||||
|
cy.get(`th:contains(${columnName})`) |
||||||
.should('exist'); |
.should('exist'); |
||||||
cy.wait(500) |
cy.wait(500) |
||||||
|
|
||||||
cy.get(`td[data-col="${colName}"]`).first().invoke('text').should('match', /^\s*\d+\s*$/) |
} |
||||||
|
|
||||||
|
|
||||||
}) |
// routine to delete column
|
||||||
|
// Input:
|
||||||
|
// columnName - columnName to delete
|
||||||
|
//
|
||||||
|
const deleteColumnByName = (columnName) => { |
||||||
|
|
||||||
|
// verify if column exists before delete
|
||||||
|
cy.get(`th:contains(${columnName})`) |
||||||
|
.should('exist'); |
||||||
|
|
||||||
// edit the newly created column
|
// delete opiton visible on mouse-over
|
||||||
it('Edit table column - rename', () => { |
cy.get(`th:contains(${columnName}) .mdi-menu-down`) |
||||||
|
.trigger('mouseover') |
||||||
|
.click() |
||||||
|
|
||||||
|
// delete/ confirm on pop-up
|
||||||
|
cy.get('.nc-column-delete').click() |
||||||
|
cy.getActiveModal().find('button:contains(Confirm)').click() |
||||||
|
|
||||||
cy.get(`th:contains(${colName}) .mdi-menu-down`) |
// validate if deleted (column shouldnt exist)
|
||||||
.trigger('mouseover', {force: true}) |
cy.get(`th:contains(${columnName})`) |
||||||
.click({force: true}) |
.should('not.exist'); |
||||||
|
|
||||||
cy.get('.nc-column-edit').click() |
} |
||||||
|
|
||||||
// rename column and verify
|
|
||||||
cy.get('.nc-column-name-input input').clear().type(updatedColName) |
|
||||||
cy.get('.nc-col-create-or-edit-card').contains('Save').click() |
|
||||||
|
|
||||||
|
// routine to edit column
|
||||||
|
//
|
||||||
|
// Input
|
||||||
|
// oldName: existing column name
|
||||||
|
// newName: new name to change
|
||||||
|
//
|
||||||
|
const editColumnByName = (oldName, newName) => { |
||||||
|
|
||||||
cy |
// verify if column exists before delete
|
||||||
.get(`th:contains(${updatedColName})`) |
cy.get(`th:contains(${oldName})`) |
||||||
.should('exist'); |
.should('exist'); |
||||||
cy |
|
||||||
.get(`th:contains(${colName})`) |
|
||||||
.should('not.exist'); |
|
||||||
|
|
||||||
|
|
||||||
}) |
// delete opiton visible on mouse-over
|
||||||
|
cy.get(`th:contains(${oldName}) .mdi-menu-down`) |
||||||
|
.trigger('mouseover') |
||||||
|
.click() |
||||||
|
|
||||||
|
// edit/ save on pop-up
|
||||||
|
cy.get('.nc-column-edit').click() |
||||||
|
cy.get('.nc-column-name-input input').clear().type(newName) |
||||||
|
cy.get('.nc-col-create-or-edit-card').contains('Save').click() |
||||||
|
|
||||||
// delete the newly created column
|
// validate if deleted (column shouldnt exist)
|
||||||
it('Delete table column', () => { |
cy.get(`th:contains(${oldName})`) |
||||||
cy |
.should('not.exist'); |
||||||
.get(`th:contains(${updatedColName})`) |
cy.get(`th:contains(${newName})`) |
||||||
.should('exist'); |
.should('exist'); |
||||||
|
|
||||||
cy.get(`th:contains(${updatedColName}) .mdi-menu-down`) |
} |
||||||
.trigger('mouseover') |
|
||||||
.click() |
|
||||||
|
|
||||||
cy.get('.nc-column-delete').click() |
///////////////////////////////////////////////////
|
||||||
cy.getActiveModal().find('button:contains(Confirm)').click() |
// Test case
|
||||||
|
|
||||||
|
it('Add Rollup column (City, CityId, sum) & Delete', () => { |
||||||
|
|
||||||
cy |
addLookUpColumn('RollUpCol_2', 'City', 'CityId', 'sum') |
||||||
.get(`th:contains(${updatedColName})`) |
|
||||||
.should('not.exist'); |
// Verify first entry, will be displayed as alias here 'childColumn (from childTable)'
|
||||||
|
// intentionally verifying 4th item, as initial items are being masked out by list scroll down
|
||||||
|
// to be fixed
|
||||||
|
//
|
||||||
|
cy.get(`tbody > :nth-child(4) > [data-col="RollUpCol_2"]`) |
||||||
|
.contains('427') |
||||||
|
.should('exist') |
||||||
|
|
||||||
|
editColumnByName('RollUpCol_2', 'RollUpCol_New') |
||||||
|
deleteColumnByName('RollUpCol_New') |
||||||
|
|
||||||
}) |
}) |
||||||
|
|
||||||
|
it('Add Rollup column (City, CountryId, count) & Delete', () => { |
||||||
|
|
||||||
|
addLookUpColumn('RollUpCol_1', 'City', 'CountryId', 'count') |
||||||
|
|
||||||
|
// Verify first entry, will be displayed as alias here 'childColumn (from childTable)'
|
||||||
|
cy.get(`tbody > :nth-child(4) > [data-col="RollUpCol_1"]`) |
||||||
|
.contains('2') |
||||||
|
.should('exist') |
||||||
|
|
||||||
|
editColumnByName('RollUpCol_1', 'RollUpCol_New') |
||||||
|
deleteColumnByName('RollUpCol_New') |
||||||
|
|
||||||
|
}) |
||||||
|
|
||||||
}); |
}); |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
genTest('rest') |
genTest('rest') |
||||||
genTest('graphql') |
genTest('graphql') |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd |
||||||
|
* |
||||||
|
* @author Pranav C Balan <pranavxc@gmail.com> |
||||||
|
* @author Raju Udava <sivadstala@gmail.com> |
||||||
|
* |
||||||
|
* @license GNU AGPL version 3 or any later version |
||||||
|
* |
||||||
|
* This program is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU Affero General Public License as |
||||||
|
* published by the Free Software Foundation, either version 3 of the |
||||||
|
* License, or (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU Affero General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU Affero General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
Loading…
Reference in new issue