feat: add tests for edit_column (#3704)

This commit is contained in:
Kush Trivedi 2021-03-10 15:28:42 +05:30 committed by GitHub
parent c574ed867f
commit a07ca9d72d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 428 additions and 24 deletions

View File

@ -0,0 +1,61 @@
describe(__filename, function () {
it('Ensure new column is added based on previous column in GREL', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', [
'Edit column',
'Add column based on this column...',
]);
cy.waitForDialogPanel();
cy.get('input[bind="columnNameInput"]').type('Test_GREL_toLower');
cy.typeExpression('value.toLowercase()');
cy.get(
'.expression-preview-table-wrapper tr:nth-child(2) td:last-child'
).contains('butter,with salt');
cy.confirmDialogPanel();
cy.assertCellEquals(0, 'Test_GREL_toLower', 'butter,with salt');
cy.assertCellEquals(1, 'Test_GREL_toLower', 'butter,whipped,with salt');
});
it('Ensure new column is added based on previous column in Python', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', [
'Edit column',
'Add column based on this column...',
]);
cy.waitForDialogPanel();
cy.get('input[bind="columnNameInput"]').type('Test_Python_toLower');
cy.get('select[bind="expressionPreviewLanguageSelect"]').select('jython');
cy.typeExpression('return value.lower()');
cy.get(
'.expression-preview-table-wrapper tr:nth-child(2) td:last-child'
).contains('butter,with salt');
cy.confirmDialogPanel();
cy.assertCellEquals(0, 'Test_Python_toLower', 'butter,with salt');
cy.assertCellEquals(1, 'Test_Python_toLower', 'butter,whipped,with salt');
});
it('Ensure new column is added based on previous column in Clojure', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', [
'Edit column',
'Add column based on this column...',
]);
cy.waitForDialogPanel();
cy.get('input[bind="columnNameInput"]').type('Test_Clojure_toLower');
cy.get('select[bind="expressionPreviewLanguageSelect"]').select('clojure');
cy.typeExpression('(.. value (toLowerCase) )');
cy.get(
'.expression-preview-table-wrapper tr:nth-child(2) td:last-child'
).contains('butter,with salt');
cy.confirmDialogPanel();
cy.assertCellEquals(0, 'Test_Clojure_toLower', 'butter,with salt');
cy.assertCellEquals(1, 'Test_Clojure_toLower', 'butter,whipped,with salt');
});
});

View File

@ -0,0 +1,126 @@
describe(__filename, function () {
it('Ensures two columns are joined', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Join columns...']);
cy.waitForDialogPanel();
cy.get('input[column="NDB_No"]').check();
cy.confirmDialogPanel();
cy.assertCellEquals(0, 'Shrt_Desc', 'BUTTER,WITH SALT01001');
cy.assertCellEquals(1, 'Shrt_Desc', 'BUTTER,WHIPPED,WITH SALT01002');
});
it('Ensures two columns are joined respecting the column ordering', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Join columns...']);
cy.waitForDialogPanel();
cy.get('input[column="NDB_No"]').check();
cy.dragAndDrop('div[column="NDB_No', 'div[column="Shrt_Desc"]');
cy.confirmDialogPanel();
cy.assertCellEquals(0, 'Shrt_Desc', '01001BUTTER,WITH SALT');
cy.assertCellEquals(1, 'Shrt_Desc', '01002BUTTER,WHIPPED,WITH SALT');
});
it('Ensures two columns are joined with given seperator', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Join columns...']);
cy.waitForDialogPanel();
cy.get('input[column="NDB_No"]').check();
cy.get('input[bind="field_separatorInput"]').type(':-:');
cy.confirmDialogPanel();
cy.assertCellEquals(0, 'Shrt_Desc', 'BUTTER,WITH SALT:-:01001');
cy.assertCellEquals(1, 'Shrt_Desc', 'BUTTER,WHIPPED,WITH SALT:-:01002');
});
it('Ensures two columns are joined with given seperator with columns reorder', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Join columns...']);
cy.waitForDialogPanel();
cy.dragAndDrop('div[column="NDB_No', 'div[column="Shrt_Desc"]');
cy.get('input[column="NDB_No"]').check();
cy.get('input[bind="field_separatorInput"]').type(':-:');
cy.confirmDialogPanel();
cy.assertCellEquals(0, 'Shrt_Desc', '01001:-:BUTTER,WITH SALT');
cy.assertCellEquals(1, 'Shrt_Desc', '01002:-:BUTTER,WHIPPED,WITH SALT');
});
it('Ensures three columns are joined and written into a new column', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Join columns...']);
cy.waitForDialogPanel();
cy.get('input[column="NDB_No"]').check();
cy.get('input[column="Water"]').check();
cy.get('[type="radio"]').check('copy-to-new-column');
cy.get('input[bind="new_column_nameInput"]').type('Test_Merged_Column');
cy.confirmDialogPanel();
cy.assertCellEquals(0, 'Test_Merged_Column', 'BUTTER,WITH SALT0100115.87');
cy.assertCellEquals(
1,
'Test_Merged_Column',
'BUTTER,WHIPPED,WITH SALT0100215.87'
);
});
it('Ensures three columns are joined and written into a new column with a given seperator', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Join columns...']);
cy.waitForDialogPanel();
cy.get('input[column="NDB_No"]').check();
cy.get('input[column="Water"]').check();
cy.get('[type="radio"]').check('copy-to-new-column');
cy.get('input[bind="new_column_nameInput"]').type('Test_Merged_Column');
cy.get('input[bind="field_separatorInput"]').type(':-:');
cy.confirmDialogPanel();
cy.assertCellEquals(
0,
'Test_Merged_Column',
'BUTTER,WITH SALT:-:01001:-:15.87'
);
cy.assertCellEquals(
1,
'Test_Merged_Column',
'BUTTER,WHIPPED,WITH SALT:-:01002:-:15.87'
);
});
it('Ensures columns are joined and original columns are deleted', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Join columns...']);
cy.waitForDialogPanel();
cy.get('button[bind="selectAllButton"]').click();
cy.get('[type="radio"]').check('copy-to-new-column');
cy.get('input[bind="delete_joined_columnsInput"]').check();
cy.get('input[bind="new_column_nameInput"]').type('Test_Merged_Grid');
cy.confirmDialogPanel();
cy.get('body[ajax_in_progress="true"]');
cy.get('body[ajax_in_progress="false"]');
cy.assertGridEquals([
['Test_Merged_Grid'],
['BUTTER,WITH SALT0100115.87717'],
['BUTTER,WHIPPED,WITH SALT0100215.87717'],
]);
});
});

View File

@ -0,0 +1,40 @@
describe(__filename, function () {
it('Ensures a column is removed from the data-table', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Remove this column']);
cy.assertNotificationContainingText('Remove column Shrt_Desc');
cy.columnActionClick('Water', ['Edit column', 'Remove this column']);
cy.assertNotificationContainingText('Remove column Water');
cy.get('.data-table-header').find('th').should('have.length', 3);
cy.assertGridEquals([
['NDB_No', 'Energ_Kcal'],
['01001', '717'],
['01002', '717'],
]);
});
it('Ensures a column is renamed in the data-table', function () {
cy.loadProject('food.mini').then((projectId) => {
cy.visit(
Cypress.env('OPENREFINE_URL') + '/project?project=' + projectId,
{
onBeforeLoad(win) {
cy.stub(win, 'prompt').returns('test_rename_butter');
},
}
);
});
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Rename this column']);
cy.assertNotificationContainingText('Rename column Shrt_Desc');
cy.assertCellEquals(0, 'test_rename_butter', 'BUTTER,WITH SALT');
cy.assertCellEquals(1, 'test_rename_butter', 'BUTTER,WHIPPED,WITH SALT');
});
});

View File

@ -0,0 +1,53 @@
describe(__filename, function () {
it('Ensures a column is moved to beginning', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', [
'Edit column',
'Move column to beginning',
]);
cy.assertNotificationContainingText('Move column Shrt_Desc to position 0');
cy.get('.data-table-header th:nth-child(2)').should(
'to.contain',
'Shrt_Desc'
);
});
it('Ensures a column is moved to end', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Move column to end']);
cy.assertNotificationContainingText('Move column Shrt_Desc to position 3');
cy.get('.data-table-header th:nth-child(5)').should(
'to.contain',
'Shrt_Desc'
);
});
it('Ensures a column is moved left', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Move column left']);
cy.assertNotificationContainingText('Move column Shrt_Desc to position 0');
cy.get('.data-table-header th:nth-child(2)').should(
'to.contain',
'Shrt_Desc'
);
});
it('Ensures a column is moved right', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', ['Edit column', 'Move column right']);
cy.assertNotificationContainingText('Move column Shrt_Desc to position 2');
cy.get('.data-table-header th:nth-child(4)').should(
'to.contain',
'Shrt_Desc'
);
});
});

View File

@ -0,0 +1,114 @@
describe(__filename, function () {
it('Ensures column is splitted by comma seperator', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', [
'Edit column',
'Split into several columns...',
]);
cy.waitForDialogPanel();
cy.get('input[bind="separatorInput"]').type('{backspace},');
cy.confirmDialogPanel();
cy.get('body[ajax_in_progress="false"]');
cy.assertNotificationContainingText(
'Split 2 cell(s) in column Shrt_Desc into several columns by separator '
);
cy.get('.data-table-header').find('th').should('have.length', 7);
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc 1');
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc 2');
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc 3');
cy.assertCellEquals(0, 'Shrt_Desc 1', 'BUTTER');
cy.assertCellEquals(0, 'Shrt_Desc 2', 'WITH SALT');
cy.assertCellEquals(0, 'Shrt_Desc 3', null);
});
it('Ensures column is splitted by comma seperator without removing original column', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', [
'Edit column',
'Split into several columns...',
]);
cy.waitForDialogPanel();
cy.get('input[bind="separatorInput"]').type('{backspace},');
cy.get('input[bind="removeColumnInput"]').uncheck();
cy.confirmDialogPanel();
cy.get('body[ajax_in_progress="false"]');
cy.assertNotificationContainingText(
'Split 2 cell(s) in column Shrt_Desc into several columns by separator '
);
cy.get('.data-table-header').find('th').should('have.length', 8);
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc');
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc 2');
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc 3');
cy.assertCellEquals(0, 'Shrt_Desc', 'BUTTER,WITH SALT');
cy.assertCellEquals(0, 'Shrt_Desc 1', 'BUTTER');
cy.assertCellEquals(0, 'Shrt_Desc 2', 'WITH SALT');
cy.assertCellEquals(0, 'Shrt_Desc 3', null);
});
it('Ensures column is splitted by field-lengths seperator', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', [
'Edit column',
'Split into several columns...',
]);
cy.waitForDialogPanel();
cy.get('[type="radio"]').check('lengths');
cy.get('textarea[bind="lengthsTextarea"]').type('1, 2, 3');
cy.confirmDialogPanel();
cy.get('body[ajax_in_progress="false"]');
cy.assertNotificationContainingText(
'Split 2 cell(s) in column Shrt_Desc into several columns by field lengths'
);
cy.get('.data-table-header').find('th').should('have.length', 7);
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc 1');
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc 2');
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc 3');
cy.assertCellEquals(0, 'Shrt_Desc 1', 'B');
cy.assertCellEquals(0, 'Shrt_Desc 2', 'UT');
cy.assertCellEquals(0, 'Shrt_Desc 3', 'TER');
});
it('Ensures column is splitted by field-lengths seperator without removing original column', function () {
cy.loadAndVisitProject('food.mini');
cy.columnActionClick('Shrt_Desc', [
'Edit column',
'Split into several columns...',
]);
cy.waitForDialogPanel();
cy.get('[type="radio"]').check('lengths');
cy.get('textarea[bind="lengthsTextarea"]').type('1, 2, 3, 4');
cy.get('input[bind="removeColumnInput"]').uncheck();
cy.confirmDialogPanel();
cy.get('body[ajax_in_progress="false"]');
cy.assertNotificationContainingText(
'Split 2 cell(s) in column Shrt_Desc into several columns by field lengths'
);
cy.get('.data-table-header').find('th').should('have.length', 9);
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc');
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc 2');
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc 3');
cy.get('.data-table-header').find('th').should('to.contain', 'Shrt_Desc 4');
cy.assertCellEquals(0, 'Shrt_Desc', 'BUTTER,WITH SALT');
cy.assertCellEquals(0, 'Shrt_Desc 1', 'B');
cy.assertCellEquals(0, 'Shrt_Desc 2', 'UT');
cy.assertCellEquals(0, 'Shrt_Desc 3', 'TER');
cy.assertCellEquals(0, 'Shrt_Desc 4', ',WIT');
});
});

View File

@ -5,15 +5,6 @@ function loadExpressionPanel() {
cy.columnActionClick('Shrt_Desc', ['Facet', 'Custom text facet']);
}
/**
* Utility method to fill something into the expression input
* Need to wait for OpenRefine to preview the result, hence the cy.wait
*/
function typeExpression(expression) {
cy.get('textarea.expression-preview-code').type(expression);
cy.wait(250); // eslint-disable-line
}
/**
* Generate a unique GREL expression to be used for testing
*/
@ -45,7 +36,7 @@ describe(__filename, function () {
it('Test a valid Grel expression', function () {
cy.loadAndVisitProject('food.mini');
loadExpressionPanel();
typeExpression('value.toLowercase()');
cy.typeExpression('value.toLowercase()');
cy.get('.expression-preview-parsing-status').contains('No syntax error.');
cy.get(
'.expression-preview-table-wrapper tr:nth-child(2) td:last-child'
@ -56,7 +47,7 @@ describe(__filename, function () {
cy.loadAndVisitProject('food.mini');
loadExpressionPanel();
cy.get('select[bind="expressionPreviewLanguageSelect"]').select('jython');
typeExpression('return value.lower()');
cy.typeExpression('return value.lower()');
cy.get('.expression-preview-parsing-status').contains('No syntax error.');
cy.get(
'.expression-preview-table-wrapper tr:nth-child(2) td:last-child'
@ -67,7 +58,7 @@ describe(__filename, function () {
cy.loadAndVisitProject('food.mini');
loadExpressionPanel();
cy.get('select[bind="expressionPreviewLanguageSelect"]').select('clojure');
typeExpression('(.. value (toLowerCase) )');
cy.typeExpression('(.. value (toLowerCase) )');
cy.get('.expression-preview-parsing-status').contains('No syntax error.');
cy.get(
'.expression-preview-table-wrapper tr:nth-child(2) td:last-child'
@ -77,7 +68,7 @@ describe(__filename, function () {
it('Test a Grel syntax error', function () {
cy.loadAndVisitProject('food.mini');
loadExpressionPanel();
typeExpression('()');
cy.typeExpression('()');
cy.get('.expression-preview-parsing-status').contains('Parsing error');
});
@ -85,7 +76,7 @@ describe(__filename, function () {
cy.loadAndVisitProject('food.mini');
loadExpressionPanel();
cy.get('select[bind="expressionPreviewLanguageSelect"]').select('jython');
typeExpression('(;)');
cy.typeExpression('(;)');
cy.get('.expression-preview-parsing-status').contains('Internal error');
});
@ -93,7 +84,7 @@ describe(__filename, function () {
cy.loadAndVisitProject('food.mini');
loadExpressionPanel();
cy.get('select[bind="expressionPreviewLanguageSelect"]').select('clojure');
typeExpression('(;)');
cy.typeExpression('(;)');
cy.get('.expression-preview-parsing-status').contains(
'Syntax error reading source'
);
@ -102,7 +93,7 @@ describe(__filename, function () {
it('Test a Grel language error', function () {
cy.loadAndVisitProject('food.mini');
loadExpressionPanel();
typeExpression('value.thisGrelFunctionDoesNotExists()');
cy.typeExpression('value.thisGrelFunctionDoesNotExists()');
cy.get('.expression-preview-parsing-status').contains(
'Unknown function thisGrelFunctionDoesNotExists'
);
@ -112,7 +103,7 @@ describe(__filename, function () {
cy.loadAndVisitProject('food.mini');
loadExpressionPanel();
cy.get('select[bind="expressionPreviewLanguageSelect"]').select('jython');
typeExpression('return value.thisPythonFunctionDoesNotExists()');
cy.typeExpression('return value.thisPythonFunctionDoesNotExists()');
cy.get(
'.expression-preview-table-wrapper tr:nth-child(2) td:last-child'
@ -123,7 +114,7 @@ describe(__filename, function () {
cy.loadAndVisitProject('food.mini');
loadExpressionPanel();
cy.get('select[bind="expressionPreviewLanguageSelect"]').select('clojure');
typeExpression('(.. value (thisClojureFunctionDoesNotExists) )');
cy.typeExpression('(.. value (thisClojureFunctionDoesNotExists) )');
cy.get(
'.expression-preview-table-wrapper tr:nth-child(2) td:last-child'
).should('to.contain', 'Error: No matching method');
@ -132,7 +123,7 @@ describe(__filename, function () {
it('Test switching from one langage to another', function () {
cy.loadAndVisitProject('food.mini');
loadExpressionPanel();
typeExpression('(.. value (toLowerCase) )');
cy.typeExpression('(.. value (toLowerCase) )');
// error is expected, this is clojure language
cy.get('.expression-preview-parsing-status').should(
'to.contain',
@ -149,7 +140,7 @@ describe(__filename, function () {
it('Test the preview (GREL)', function () {
cy.loadAndVisitProject('food.mini');
loadExpressionPanel();
typeExpression('value.toLowercase()');
cy.typeExpression('value.toLowercase()');
cy.get(
'.expression-preview-table-wrapper tr:nth-child(1) td:last-child'
@ -180,7 +171,7 @@ describe(__filename, function () {
// Use a first unique expression
const uniqueExpression = generateUniqueExpression();
loadExpressionPanel();
typeExpression(uniqueExpression);
cy.typeExpression(uniqueExpression);
cy.get('.dialog-footer button').contains('OK').click();
// ensure the function has been added to the facet
cy.get('#refine-tabs-facets').contains(uniqueExpression.replace('()', ''));
@ -199,7 +190,7 @@ describe(__filename, function () {
// Because history is shared across projects, we need to build and use an expression that is unique
const uniqueExpression = generateUniqueExpression();
loadExpressionPanel();
typeExpression(uniqueExpression);
cy.typeExpression(uniqueExpression);
cy.get('.dialog-footer button').contains('OK').click();
cy.get('#refine-tabs-facets').contains(uniqueExpression.replace('()', ''));
@ -252,7 +243,7 @@ describe(__filename, function () {
// Load an expression
loadExpressionPanel();
const uniqueExpression = generateUniqueExpression();
typeExpression(uniqueExpression);
cy.typeExpression(uniqueExpression);
cy.get('.dialog-footer button').contains('OK').click();
// Star the expression

View File

@ -212,6 +212,15 @@ Cypress.Commands.add('waitForOrOperation', () => {
cy.get('body[ajax_in_progress="false"]');
});
/**
* Utility method to fill something into the expression input
* Need to wait for OpenRefine to preview the result, hence the cy.wait
*/
Cypress.Commands.add('typeExpression', (expression) => {
cy.get('textarea.expression-preview-code').type(expression);
cy.wait(250); // eslint-disable-line
});
/**
* Delete a column from the grid
*/
@ -289,6 +298,15 @@ Cypress.Commands.add(
}
);
/**
* Performs drag and drop on target and source item
*/
Cypress.Commands.add('dragAndDrop', (sourceSelector, targetSelector) => {
cy.get(sourceSelector).trigger('mousedown', { which: 1 });
cy.get(targetSelector).trigger('mousemove').trigger('mouseup');
});
Cypress.Commands.add(
'loadAndVisitSampleJSONProject',
(projectName, fixture) => {

View File

@ -9,7 +9,7 @@
"test": "cypress run --browser electron --headless --quiet",
"fix-lint": "prettier --write . && eslint --fix .",
"lint": "prettier --check . && eslint ."
},
},
"dependencies": {
"cypress": "6.6.0",
"cypress-file-upload": "^5.0.2",

View File

@ -484,6 +484,7 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
.appendTo(elmts.column_join_columnPicker);
$('<input>').
attr('type', 'checkbox')
.attr("column", colName)
.prop('checked',(i == columnIndex) ? true : false)
.appendTo(div);
$('<span>')