From 3db9453661261e1917aaa21fd3c1e3559536f6f2 Mon Sep 17 00:00:00 2001 From: Kush Trivedi <44091822+kushthedude@users.noreply.github.com> Date: Sat, 27 Feb 2021 01:42:46 +0530 Subject: [PATCH] feat: add tests for create project (#3603) * feat: add tests for create project Signed-off-by: kushthedude * add test for URL and increase timeout Signed-off-by: kushthedude * restore timeout Signed-off-by: kushthedude * restore timeout Signed-off-by: kushthedude * fix Signed-off-by: kushthedude * amend urls Signed-off-by: kushthedude Co-authored-by: Tom Morris --- .../cypress/cypress/fixtures/shop.mini.tsv | 6 + .../create-project/create_project.spec.js | 217 ++++++++++++------ .../create-project/preview_project.spec.js | 48 ++++ .../tests/cypress/cypress/support/commands.js | 4 +- 4 files changed, 205 insertions(+), 70 deletions(-) create mode 100644 main/tests/cypress/cypress/fixtures/shop.mini.tsv create mode 100644 main/tests/cypress/cypress/integration/create-project/preview_project.spec.js diff --git a/main/tests/cypress/cypress/fixtures/shop.mini.tsv b/main/tests/cypress/cypress/fixtures/shop.mini.tsv new file mode 100644 index 000000000..bea43ce97 --- /dev/null +++ b/main/tests/cypress/cypress/fixtures/shop.mini.tsv @@ -0,0 +1,6 @@ +storm instant amount choice pool married +keep fifty memory behavior courage troops +hello mass industry cannot complete practical +add shop surrounded time highway myself +first task fine steep should great +has shot bet became damage share \ No newline at end of file diff --git a/main/tests/cypress/cypress/integration/create-project/create_project.spec.js b/main/tests/cypress/cypress/integration/create-project/create_project.spec.js index 7c757d15a..ed927292c 100644 --- a/main/tests/cypress/cypress/integration/create-project/create_project.spec.js +++ b/main/tests/cypress/cypress/integration/create-project/create_project.spec.js @@ -1,5 +1,6 @@ describe(__filename, function () { - it('Test the create project page', function () { + it('Test the create project from this computer based on CSV', function () { + // navigate to the create page cy.visitOpenRefine(); cy.navigateTo('Create Project'); cy.get('#create-project-ui-source-selection-tabs > div') @@ -8,8 +9,7 @@ describe(__filename, function () { cy.get('.create-project-ui-source-selection-tab-body.selected').contains( 'Locate one or more files on your computer to upload' ); - - // load a file + // add file const csvFile = { filePath: 'food.mini.csv', mimeType: 'application/csv', @@ -26,89 +26,168 @@ describe(__filename, function () { // then ensure we are on the preview page cy.get('.create-project-ui-panel').contains('Configure Parsing Options'); - }); - it('Test project naming', function () { - cy.visitOpenRefine(); - cy.createProjectThroughUserInterface('food.mini.csv'); - cy.get('.create-project-ui-panel').contains('Configure Parsing Options'); - cy.get( - '.default-importing-wizard-header input[bind="projectNameInput"]' - ).type('this is a test'); + // preview and click next cy.doCreateProjectThroughUserInterface(); - - cy.get('#project-name-button').contains('this is a test'); }); - - it('Test project tagging', function () { - cy.visitOpenRefine(); - cy.createProjectThroughUserInterface('food.mini.csv'); - cy.get('.create-project-ui-panel').contains('Configure Parsing Options'); - const uniqueProjectName = Date.now(); - const uniqueTagName1 = 'tag1_' + Date.now(); - const uniqueTagName2 = 'tag2_' + Date.now(); - - cy.get( - '.default-importing-wizard-header input[bind="projectNameInput"]' - ).type(uniqueProjectName); - // triger the select input - cy.get('#project-tags-container').click(); - // Type and Validate the tag, pressing enter - cy.get('#project-tags-container .select2-input').type(uniqueTagName1); - cy.get('body').type('{enter}'); - cy.get('#project-tags-container .select2-input').type(uniqueTagName2); - cy.get('body').type('{enter}'); - cy.get('#or-import-parsopt').click(); - cy.doCreateProjectThroughUserInterface(); - - cy.visitOpenRefine(); - cy.navigateTo('Open Project'); - cy.get('#projects-list') - .contains(uniqueProjectName) - .parent() - .parent() - .contains(uniqueTagName1); - cy.get('#projects-list') - .contains(uniqueProjectName) - .parent() - .parent() - .contains(uniqueTagName2); - }); - - it('E2E, Creates a simple project, based on a CSV', function () { + it('Test the create project from this computer based on TSV', function () { // navigate to the create page cy.visitOpenRefine(); cy.navigateTo('Create Project'); + cy.get('#create-project-ui-source-selection-tabs > div') + .contains('This Computer') + .click(); + cy.get('.create-project-ui-source-selection-tab-body.selected').contains( + 'Locate one or more files on your computer to upload' + ); // add file - const csvFile = { - filePath: 'food.mini.csv', - mimeType: 'application/csv', + const tsvFile = { + filePath: 'shop.mini.tsv', + mimeType: 'text/tab-separated-values', }; cy.get( '.create-project-ui-source-selection-tab-body.selected input[type="file"]' - ).attachFile(csvFile); + ).attachFile(tsvFile); cy.get( '.create-project-ui-source-selection-tab-body.selected button.button-primary' ).click(); + cy.get( + '.default-importing-wizard-header input[bind="projectNameInput"]' + ).should('have.value', 'shop mini tsv'); + + // then ensure we are on the preview page + cy.get('.create-project-ui-panel').contains('Configure Parsing Options'); // preview and click next + cy.doCreateProjectThroughUserInterface(); + }); + it('Test the create project from clipboard based on CSV', function () { + // navigate to the create page + cy.visitOpenRefine(); + cy.navigateTo('Create Project'); + cy.get('#create-project-ui-source-selection-tabs > div') + .contains('Clipboard') + .click(); + cy.get('#or-import-clipboard').should( + 'to.contain', + 'Paste data from clipboard here:' + ); + // add file + const csvFile = `Username; Identifier;First name;Last name + booker12;9012;Rachel;Booker + grey07;2070;Laura;Grey + johnson81;4081;Craig;Johnson + jenkins46;9346;Mary;Jenkins + smith79;5079;Jamie;Smith`; + cy.get('textarea').invoke('val', csvFile); cy.get( - '.default-importing-wizard-header button[bind="nextButton"]' - ).click(); - cy.get('#create-project-progress-message').contains('Done.'); + '.create-project-ui-source-selection-tab-body.selected button.button-primary' + ) + .contains('Next »') + .click(); + cy.get( + '.default-importing-wizard-header input[bind="projectNameInput"]' + ).should('have.value', 'Clipboard'); - // workaround to ensure project is loaded - // cypress does not support window.location = ... - cy.get('h2').contains('HTTP ERROR 404'); - cy.location().should((location) => { - expect(location.href).contains( - Cypress.env('OPENREFINE_URL') + '/__/project?' - ); - }); + // then ensure we are on the preview page + cy.get('.create-project-ui-panel').contains('Configure Parsing Options'); - cy.location().then((location) => { - const projectId = location.href.split('=').slice(-1)[0]; - cy.visitProject(projectId); - }); + // preview and click next + cy.doCreateProjectThroughUserInterface(); + }); + it('Test the create project from clipboard based on TSV', function () { + // navigate to the create page + cy.visitOpenRefine(); + cy.navigateTo('Create Project'); + cy.get('#create-project-ui-source-selection-tabs > div') + .contains('Clipboard') + .click(); + cy.get('#or-import-clipboard').should( + 'to.contain', + 'Paste data from clipboard here:' + ); + // add file + const tsvFile = `Some parameter Other parameter Last parameter + CONST 123456 12.45`; + cy.get('textarea').invoke('val', tsvFile); + cy.get( + '.create-project-ui-source-selection-tab-body.selected button.button-primary' + ) + .contains('Next »') + .click(); + cy.get( + '.default-importing-wizard-header input[bind="projectNameInput"]' + ).should('have.value', 'Clipboard'); + + // then ensure we are on the preview page + cy.get('.create-project-ui-panel').contains('Configure Parsing Options'); + + // preview and click next + cy.doCreateProjectThroughUserInterface(); + }); + it('Test the create project from Web URL based on CSV', function () { + // navigate to the create page + cy.visitOpenRefine(); + cy.navigateTo('Create Project'); + cy.get('#create-project-ui-source-selection-tabs > div') + .contains('Web Addresses (URLs)') + .click(); + cy.get('#or-import-enterurl').should( + 'to.contain', + 'Enter one or more web addresses (URLs) pointing to data to download:' + ); + // add file + const csvURL = + 'https://raw.githubusercontent.com/OpenRefine/OpenRefine/master/main/tests/cypress/cypress/fixtures/food.mini.csv'; + cy.get('input[bind="urlInput"]').filter(':visible').type(csvURL); + cy.get( + '.create-project-ui-source-selection-tab-body.selected button.button-primary' + ) + .contains('Next »') + .click(); + cy.get( + '.default-importing-wizard-header input[bind="projectNameInput"]' + ).should('have.value', 'food mini csv'); + + // then ensure we are on the preview page + cy.get('.create-project-ui-panel').contains('Configure Parsing Options'); + + // preview and click next + cy.doCreateProjectThroughUserInterface(); + }); + it('Test the create project from Multiple Web URLs based on CSV', function () { + // navigate to the create page + cy.visitOpenRefine(); + cy.navigateTo('Create Project'); + cy.get('#create-project-ui-source-selection-tabs > div') + .contains('Web Addresses (URLs)') + .click(); + cy.get('#or-import-enterurl').should( + 'to.contain', + 'Enter one or more web addresses (URLs) pointing to data to download:' + ); + // add file + const csvURL = + 'https://raw.githubusercontent.com/OpenRefine/OpenRefine/master/main/tests/cypress/cypress/fixtures/food.mini.csv'; + cy.get('input[bind="urlInput"]').filter(':visible').type(csvURL); + cy.get('button[bind="addButton"]').contains('Add Another URL').click(); + + cy.get( + '.create-project-ui-source-selection-tab-body.selected button.button-primary' + ) + .contains('Next »') + .click(); + cy.get('.create-project-ui-panel', { timeout: 7500 }) + .contains('Configure Parsing Options »') + .click(); + cy.get( + '.default-importing-wizard-header input[bind="projectNameInput"]' + ).should('have.value', 'food mini csv'); + + // then ensure we are on the preview page + cy.get('.create-project-ui-panel').contains('Configure Parsing Options'); + + // preview and click next + cy.doCreateProjectThroughUserInterface(); }); }); diff --git a/main/tests/cypress/cypress/integration/create-project/preview_project.spec.js b/main/tests/cypress/cypress/integration/create-project/preview_project.spec.js new file mode 100644 index 000000000..455042c96 --- /dev/null +++ b/main/tests/cypress/cypress/integration/create-project/preview_project.spec.js @@ -0,0 +1,48 @@ +describe(__filename, function () { + it('Test project naming', function () { + cy.visitOpenRefine(); + cy.createProjectThroughUserInterface('food.mini.csv'); + cy.get('.create-project-ui-panel').contains('Configure Parsing Options'); + cy.get( + '.default-importing-wizard-header input[bind="projectNameInput"]' + ).type('this is a test'); + cy.doCreateProjectThroughUserInterface(); + + cy.get('#project-name-button').contains('this is a test'); + }); + + it('Test project tagging', function () { + cy.visitOpenRefine(); + cy.createProjectThroughUserInterface('food.mini.csv'); + cy.get('.create-project-ui-panel').contains('Configure Parsing Options'); + const uniqueProjectName = Date.now(); + const uniqueTagName1 = 'tag1_' + Date.now(); + const uniqueTagName2 = 'tag2_' + Date.now(); + + cy.get( + '.default-importing-wizard-header input[bind="projectNameInput"]' + ).type(uniqueProjectName); + // triger the select input + cy.get('#project-tags-container').click(); + // Type and Validate the tag, pressing enter + cy.get('#project-tags-container .select2-input').type(uniqueTagName1); + cy.get('body').type('{enter}'); + cy.get('#project-tags-container .select2-input').type(uniqueTagName2); + cy.get('body').type('{enter}'); + cy.get('#or-import-parsopt').click(); + cy.doCreateProjectThroughUserInterface(); + + cy.visitOpenRefine(); + cy.navigateTo('Open Project'); + cy.get('#projects-list') + .contains(uniqueProjectName) + .parent() + .parent() + .contains(uniqueTagName1); + cy.get('#projects-list') + .contains(uniqueProjectName) + .parent() + .parent() + .contains(uniqueTagName2); + }); +}); diff --git a/main/tests/cypress/cypress/support/commands.js b/main/tests/cypress/cypress/support/commands.js index 9b1951bf4..7dc6b05e5 100644 --- a/main/tests/cypress/cypress/support/commands.js +++ b/main/tests/cypress/cypress/support/commands.js @@ -66,7 +66,9 @@ Cypress.Commands.add('createProjectThroughUserInterface', (fixtureFile) => { }); Cypress.Commands.add('doCreateProjectThroughUserInterface', () => { - cy.get('.default-importing-wizard-header button[bind="nextButton"]').click(); + cy.get('.default-importing-wizard-header button[bind="nextButton"]') + .contains('Create Project »') + .click(); cy.get('#create-project-progress-message').contains('Done.'); // workaround to ensure project is loaded