feat: add tests for tutorial 1,2,3 (#3796)

* feat: add tests for tutorial 1,2,3

Signed-off-by: kushthedude <kushthedude@gmail.com>

* fix

Signed-off-by: kushthedude <kushthedude@gmail.com>

* fix: create csv method and add tutorial 3

Signed-off-by: kushthedude <kushthedude@gmail.com>

* fox

Signed-off-by: kushthedude <kushthedude@gmail.com>

* fix: requested changes

Signed-off-by: kushthedude <kushthedude@gmail.com>

Co-authored-by: Florian Giroud <6267288+fgiroud@users.noreply.github.com>
This commit is contained in:
Kush Trivedi 2021-05-20 18:15:39 +05:30 committed by GitHub
parent d312cd0c73
commit c162c9ca17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1128 additions and 10 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
// This spec is implementation for chapter 02 of following tutorial https://librarycarpentry.org/lc-open-refine/02-importing-data/index.html
describe(__filename, function () {
it('Create your first OpenRefine project (using provided data)', function () {
// For sake of the tutorial we have already downloaded the data into fixtures
// Step-1:Once OpenRefine is launched in your browser, click Create Project from the left hand menu and select Get data from This Computer
cy.visitOpenRefine();
cy.navigateTo('Create Project');
cy.get('#create-project-ui-source-selection-tabs > div')
.contains('This Computer')
.click();
// Step-2 Click Choose Files (or Browse, depending on your setup) and locate the file which you have downloaded called doaj-article-sample.csv
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: 'doaj-article-sample.csv',
mimeType: 'application/csv',
};
cy.get(
'.create-project-ui-source-selection-tab-body.selected input[type="file"]'
).attachFile(csvFile);
cy.get(
'.create-project-ui-source-selection-tab-body.selected button.button-primary'
)
.contains('Next »')
.click();
// then ensure we are on the preview page
cy.get('.create-project-ui-panel').contains('Configure Parsing Options');
// Step-3 Click in the Character encoding box and set it to UTF-8
cy.get('input[bind="encodingInput"]').should('have.value', 'UTF-8');
// step-4 Configure the import options
cy.get('input[bind="trimStringsCheckbox"]').check();
// create the project and ensure its successful
cy.doCreateProjectThroughUserInterface();
// ensure that the project data is loaded completely
cy.get('#summary-bar').should('to.contain', '1001 rows');
});
});

View File

@ -0,0 +1,64 @@
// librarycarpentry.org/lc-open-refine/03-working-with-data/index.html
describe(__filename, function () {
it('Working with rows and records in openrefine', function () {
/** ************
Splitting Cells
**************/
// For sake of the tutorial we will assume we have already covered the previous chapter for importing data
// cy.loadAndVisitProject('doaj-article-sample.csv');
const projectName = Date.now();
cy.loadProject('doaj-article-sample.csv', projectName).then((projectId) => {
cy.visitProject(projectId);
cy.get('#project-name-button').contains(projectName);
});
// Click the dropdown menu at the top of the Author column and Choose Edit cells->Split multi-valued cells
cy.columnActionClick('Authors', [
'Edit cells',
'Split multi-valued cells...',
]);
// In the prompt type the ( | ) symbol and click OK
cy.get('.dialog-container label').contains('by separator').click();
cy.get('.dialog-container input[bind="separatorInput"]').type('|');
cy.confirmDialogPanel();
cy.get('#summary-bar').should('to.contain', '4009 rows');
// Click the Records option to change to Records mode,
// Note how the numbering has changed - indicating that several rows are related to the same record
cy.get('span[bind="modeSelectors"]').contains('records').click();
cy.get('body[ajax_in_progress="true"]');
cy.get('body[ajax_in_progress="false"]');
cy.get('#summary-bar').should('to.contain', '1001 records');
/** ************
Joining Cells
**************/
// Click the dropdown menu at the top of the Author column, Choose Edit cells->Join multi-valued cells
// Hack to imitate the window prompt which will be shown used in the later code
// In the prompt type the ( | ) symbol
cy.window().then(($win) => {
cy.stub($win, 'prompt').returns(',');
});
cy.columnActionClick('Authors', [
'Edit cells',
'Join multi-valued cells...',
]);
cy.get('#summary-bar').should('to.contain', '1001 records');
// Click both the Rows and Records options and observe how the numbers of Rows and Records are equal
cy.get('span[bind="modeSelectors"]').contains('rows').click();
cy.get('#summary-bar').should('to.contain', '1001 rows');
});
});

View File

@ -50,17 +50,24 @@ Cypress.Commands.add('loadProject', (fixture, projectName, tagName) => {
const openRefineProjectName = projectName ? projectName : 'cypress-test';
let jsonFixture;
if (typeof fixture == 'string') {
jsonFixture = fixtures[fixture];
} else {
jsonFixture = fixture;
}
let content;
const csv = [];
jsonFixture.forEach((item) => {
csv.push('"' + item.join('","') + '"');
});
const content = csv.join('\n');
if (fixture.includes('.csv')) {
cy.fixture(fixture).then((value) => {
content = value;
});
} else {
if (typeof fixture == 'string') {
jsonFixture = fixtures[fixture];
} else {
jsonFixture = fixture;
}
jsonFixture.forEach((item) => {
csv.push('"' + item.join('","') + '"');
});
content = csv.join('\n');
}
cy.get('@token', { log: false }).then((token) => {
// cy.request(Cypress.env('OPENREFINE_URL')+'/command/core/get-csrf-token').then((response) => {