test: Improved the way we handle fixtures, #3505 (#3506)

* test: Improved the way we handle fixtures, #3505

* Added a fix for an invalid call to loadAndVisitProject, added cypress download path to gitignore
This commit is contained in:
Florian Giroud 2021-01-25 21:05:03 +01:00 committed by GitHub
parent 61fe0ed458
commit a421447a8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 10743 additions and 106 deletions

View File

@ -3,5 +3,6 @@ node_modules
.env.local
cypress/videos
cypress/screenshots
cypress/downloads
npm-debug.log
cypress.env.json

View File

@ -0,0 +1,9 @@
const foodMini = require('./food.mini.js')
const foodSmall = require('./food.small.js')
const fixtures = {
'food.mini': foodMini,
'food.small': foodSmall,
}
export default fixtures

View File

@ -1,3 +1,3 @@
NDB_No,Shrt_Desc,Water,Energ_Kcal
01001,"BUTTER,WITH SALT",15.87,717
01002,"BUTTER,WHIPPED,WITH SALT",15.87,717
"NDB_No","Shrt_Desc","Water","Energ_Kcal"
"01001","BUTTER,WITH SALT","15.87","717"
"01002","BUTTER,WHIPPED,WITH SALT","15.87","717"
1 NDB_No Shrt_Desc Water Energ_Kcal
2 01001 BUTTER,WITH SALT 15.87 717
3 01002 BUTTER,WHIPPED,WITH SALT 15.87 717

View File

@ -0,0 +1,7 @@
const fixture = [
['NDB_No', 'Shrt_Desc', 'Water', 'Energ_Kcal'],
['01001', 'BUTTER,WITH SALT', '15.87', '717'],
['01002', 'BUTTER,WHIPPED,WITH SALT', '15.87', '717'],
]
export default fixture

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
describe(__filename, function () {
it('List an existing project, ensure a newly created project is displayed', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName)
cy.loadProject('food.mini', projectName)
cy.visitOpenRefine()
cy.navigateTo('Open Project')
cy.get('#projects-list table').contains(projectName)
@ -9,7 +9,7 @@ describe(__filename, function () {
it('Visit a project from the Open project page, ensure link is working', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName)
cy.loadProject('food.mini', projectName)
cy.visitOpenRefine()
cy.navigateTo('Open Project')
cy.get('#projects-list table').contains(projectName).click()

View File

@ -1,9 +1,9 @@
describe(__filename, function () {
it('Open an existing project by visiting the URL directly', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName).then((projectId) => {
cy.visitProject(projectId)
cy.get('#project-name-button').contains(projectName)
})
})
it('Open an existing project by visiting the URL directly', function () {
const projectName = Date.now()
cy.loadProject('food.mini', projectName).then((projectId) => {
cy.visitProject(projectId)
cy.get('#project-name-button').contains(projectName)
})
})
})

View File

@ -1,6 +1,6 @@
describe(__filename, function () {
it('A numeric facet must be casted first', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Numeric facet'])
cy.get('#refine-tabs-facets .facets-container li:first-child').contains(
'No numeric value present.'
@ -8,7 +8,7 @@ describe(__filename, function () {
})
it('Changing the type of the column for numeric', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Numeric facet'])
cy.get('#refine-tabs-facets .facets-container li:first-child').contains(
'No numeric value present.'

View File

@ -1,6 +1,6 @@
describe(__filename, function () {
it('Test the facets text (no facets yet)', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets')
.should('exist')
@ -8,7 +8,7 @@ describe(__filename, function () {
})
it('Create a simple text facet', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets').should('exist')
@ -28,7 +28,7 @@ describe(__filename, function () {
})
it('Create a facet, Sort by count', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets').should('exist')
@ -46,7 +46,7 @@ describe(__filename, function () {
})
it('Create a facet, Sort by count, then by name', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('Water', ['Facet', 'Text facet'])
cy.get('#refine-tabs-facets').should('exist')
@ -70,7 +70,7 @@ describe(__filename, function () {
})
it('Test the display of multiple facets', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
cy.columnActionClick('Shrt_Desc', ['Facet', 'Text facet'])
cy.columnActionClick('Water', ['Facet', 'Text facet'])
@ -89,7 +89,7 @@ describe(__filename, function () {
// it('Test collapsing facet panels', function () {
// The following test does not work
// Because the facet panels uses soem weird CSS with overflow:hidden, Cypress can not detect it
// //// # cy.loadAndVisitProject('food.small.csv');
// //// # cy.loadAndVisitProject('food.small');
// //// # cy.columnActionClick('NDB_No', ['Facet', 'Text facet']);
// //// # ensure facet inner panel is visible
// //// # cy.get('#refine-tabs-facets .facets-container li:nth-child(1) .facet-body-inner').should('be.visible');
@ -99,7 +99,7 @@ describe(__filename, function () {
// });
it('Test editing a facet', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
cy.get(
'#refine-tabs-facets .facets-container li:nth-child(1) a[bind="changeButton"]'
@ -113,7 +113,7 @@ describe(__filename, function () {
})
it('Test editing a facet / Preview', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
cy.get(
'#refine-tabs-facets .facets-container li:nth-child(1) a[bind="changeButton"]'
@ -129,7 +129,7 @@ describe(__filename, function () {
})
it('Test editing a facet / History', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
cy.get(
'#refine-tabs-facets .facets-container li:nth-child(1) a[bind="changeButton"]'
@ -147,7 +147,7 @@ describe(__filename, function () {
})
it('Test editing a facet / Starred', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
cy.get(
'#refine-tabs-facets .facets-container li:nth-child(1) a[bind="changeButton"]'
@ -165,7 +165,7 @@ describe(__filename, function () {
})
it('Test editing a facet / Help', function () {
cy.loadAndVisitProject('food.small.csv')
cy.loadAndVisitProject('food.small')
cy.columnActionClick('NDB_No', ['Facet', 'Text facet'])
cy.get(
'#refine-tabs-facets .facets-container li:nth-child(1) a[bind="changeButton"]'

View File

@ -1,6 +1,6 @@
describe(__filename, function () {
it('Perform a basic sort', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
// sort and confirm
cy.columnActionClick('Shrt_Desc', ['Sort'])
@ -16,7 +16,7 @@ describe(__filename, function () {
})
it('Perform a basic sort + Reverse', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
// sort and confirm
cy.columnActionClick('Shrt_Desc', ['Sort'])
@ -42,7 +42,7 @@ describe(__filename, function () {
})
it('Perform a basic sort + Remove Sort', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
// sort and confirm
cy.columnActionClick('Shrt_Desc', ['Sort'])

View File

@ -1,6 +1,6 @@
describe(__filename, function () {
it('Ensure the Edit button is visible on mouse over a cell', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.getCell(1, 'Water').trigger('mouseover')
cy.getCell(1, 'Water')
@ -9,7 +9,7 @@ describe(__filename, function () {
})
it('Ensure the Edit button opens a popup', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.getCell(1, 'Shrt_Desc')
.trigger('mouseover')
.find('a.data-table-cell-edit')
@ -22,7 +22,7 @@ describe(__filename, function () {
})
it('Test a simple edit', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.getCell(1, 'Shrt_Desc')
.trigger('mouseover')
.find('a.data-table-cell-edit')
@ -38,7 +38,7 @@ describe(__filename, function () {
})
it('Test a simple edit, using keyboard shortcut', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.getCell(1, 'Shrt_Desc')
.trigger('mouseover')
.find('a.data-table-cell-edit')
@ -53,7 +53,7 @@ describe(__filename, function () {
})
it('Test the cancel button', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.getCell(1, 'Shrt_Desc')
.trigger('mouseover')
.find('a.data-table-cell-edit')
@ -69,7 +69,7 @@ describe(__filename, function () {
})
it('Test the cancel button, using keyboard shortcut', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.getCell(1, 'Shrt_Desc')
.trigger('mouseover')
.find('a.data-table-cell-edit')
@ -85,7 +85,7 @@ describe(__filename, function () {
})
it('Test edit all identical cells', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.getCell(1, 'Water')
.trigger('mouseover')
.find('a.data-table-cell-edit')
@ -104,7 +104,7 @@ describe(__filename, function () {
})
it('Test edit all identical cells, using the shortcut', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.getCell(1, 'Water')
.trigger('mouseover')
.find('a.data-table-cell-edit')

View File

@ -1,10 +1,10 @@
describe(__filename, function () {
it('Export a project', function () {
const testProjectName = Date.now()
cy.loadAndVisitProject('food.mini.csv', testProjectName)
cy.get('#export-button').click()
cy.get('.menu-container a')
.contains('OpenRefine project archive to file')
.click()
})
it('Export a project', function () {
const testProjectName = Date.now()
cy.loadAndVisitProject('food.mini', testProjectName)
cy.get('#export-button').click()
cy.get('.menu-container a')
.contains('OpenRefine project archive to file')
.click()
})
})

View File

@ -1,6 +1,6 @@
describe(__filename, function () {
it('Apply a JSON', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.get('#or-proj-undoRedo').click()
cy.get('#refine-tabs-history .history-panel-controls')

View File

@ -1,6 +1,6 @@
describe(__filename, function () {
it('Test select/unselect all', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.deleteColumn('NDB_No')
cy.deleteColumn('Shrt_Desc')
@ -50,7 +50,7 @@ describe(__filename, function () {
})
it('Test select/unselect individual entries', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.deleteColumn('NDB_No')
cy.deleteColumn('Shrt_Desc')
cy.get('#or-proj-undoRedo').click()
@ -119,7 +119,7 @@ describe(__filename, function () {
})
it('Test the close button', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.deleteColumn('NDB_No')
cy.get('#or-proj-undoRedo').click()
cy.get('#refine-tabs-history .history-panel-controls')
@ -132,7 +132,7 @@ describe(__filename, function () {
})
it('Ensure action are recorded in the extract panel', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.deleteColumn('NDB_No')
cy.deleteColumn('Shrt_Desc')

View File

@ -1,6 +1,6 @@
describe(__filename, function () {
it('Ensure the Undo button is visible after deleting a column', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.deleteColumn('NDB_No')
cy.get('#notification-container')
@ -12,7 +12,7 @@ describe(__filename, function () {
})
it('Ensure the Undo button is effectively working', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
cy.deleteColumn('NDB_No')
// ensure that the column is back in the grid
@ -24,7 +24,7 @@ describe(__filename, function () {
})
it('Delete 3 columns, then successively undo and redo the modifications using the Undo/Redo panel', function () {
cy.loadAndVisitProject('food.mini.csv')
cy.loadAndVisitProject('food.mini')
// delete NDB_No
cy.deleteColumn('NDB_No')
@ -106,7 +106,7 @@ describe(__filename, function () {
// Very long test to run
// it('Ensure the Undo button dissapear after timeout after deleting a column', function () {
// const ORNotificationTimeout = 15000;
// cy.loadAndVisitProject('food.mini.csv');
// cy.loadAndVisitProject('food.mini');
// cy.columnActionClick('NDB_No', ['Edit column', 'Remove this column']);
// cy.get('#notification-container', { timeout: ORNotificationTimeout }).should('not.be.visible');
// });

View File

@ -1,7 +1,7 @@
describe(__filename, function () {
it('Ensures project-metadata dialogue loads', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName)
cy.loadProject('food.mini', projectName)
cy.visitOpenRefine()
cy.navigateTo('Open Project')
cy.contains('td', projectName).siblings().contains('a', 'About').click()
@ -13,7 +13,7 @@ describe(__filename, function () {
})
it('Ensures project-metadata has correct details', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName)
cy.loadProject('food.mini', projectName)
cy.visitOpenRefine()
cy.navigateTo('Open Project')
cy.contains('td', projectName).siblings().contains('a', 'About').click()
@ -22,7 +22,7 @@ describe(__filename, function () {
})
it('Ensures project-metadata can be edit project name', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName)
cy.loadProject('food.mini', projectName)
cy.visit(Cypress.env('OPENREFINE_URL'), {
onBeforeLoad(win) {
cy.stub(win, 'prompt').returns('testProject')
@ -39,7 +39,7 @@ describe(__filename, function () {
})
it('Ensures project-metadata can be edit tags', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName)
cy.loadProject('food.mini', projectName)
cy.visit(Cypress.env('OPENREFINE_URL'), {
onBeforeLoad(win) {
cy.stub(win, 'prompt').returns('tagTest')
@ -53,7 +53,7 @@ describe(__filename, function () {
})
it('Ensures project-metadata can be edit creator', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName)
cy.loadProject('food.mini', projectName)
cy.visit(Cypress.env('OPENREFINE_URL'), {
onBeforeLoad(win) {
cy.stub(win, 'prompt').returns('testCreator')
@ -70,7 +70,7 @@ describe(__filename, function () {
})
it('Ensures project-metadata can be edit contributors', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName)
cy.loadProject('food.mini', projectName)
cy.visit(Cypress.env('OPENREFINE_URL'), {
onBeforeLoad(win) {
cy.stub(win, 'prompt').returns('testcontributor')
@ -87,7 +87,7 @@ describe(__filename, function () {
})
it('Ensures project-metadata can be edit subject', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName)
cy.loadProject('food.mini', projectName)
cy.visit(Cypress.env('OPENREFINE_URL'), {
onBeforeLoad(win) {
cy.stub(win, 'prompt').returns('testSubject')
@ -104,7 +104,7 @@ describe(__filename, function () {
})
it('Ensures project-metadata can be edit license', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName)
cy.loadProject('food.mini', projectName)
cy.visit(Cypress.env('OPENREFINE_URL'), {
onBeforeLoad(win) {
cy.stub(win, 'prompt').returns('GPL-3')
@ -121,7 +121,7 @@ describe(__filename, function () {
})
it('Ensures project-metadata can be edit homepage', function () {
const projectName = Date.now()
cy.loadProject('food.mini.csv', projectName)
cy.loadProject('food.mini', projectName)
cy.visit(Cypress.env('OPENREFINE_URL'), {
onBeforeLoad(win) {
cy.stub(win, 'prompt').returns('openrefine.org')

View File

@ -1,3 +1,5 @@
const fixtures = require('../fixtures/fixtures.js')
Cypress.Commands.add('setPreference', (preferenceName, preferenceValue) => {
const openRefineUrl = Cypress.env('OPENREFINE_URL')
cy.request(openRefineUrl + '/command/core/get-csrf-token').then(
@ -45,53 +47,67 @@ Cypress.Commands.add('cleanupProjects', () => {
Cypress.Commands.add('loadProject', (fixture, projectName) => {
const openRefineUrl = Cypress.env('OPENREFINE_URL')
const openRefineProjectName = projectName ? projectName : fixture
cy.fixture(fixture).then((content) => {
cy.get('@token', { log: false }).then((token) => {
// cy.request(Cypress.env('OPENREFINE_URL')+'/command/core/get-csrf-token').then((response) => {
const openRefineFormat = 'text/line-based/*sv'
// const options = { projectTags: ['OpenRefineTesting'] };
// '\r\n------BOUNDARY\r\nContent-Disposition: form-data; name="options"\r\n\r\n' +
// JSON.stringify(options) +
const openRefineProjectName = projectName ? projectName : 'cypress-test'
var postData =
'------BOUNDARY\r\nContent-Disposition: form-data; name="project-file"; filename="' +
fixture +
'"\r\nContent-Type: "text/csv"\r\n\r\n' +
content +
'\r\n------BOUNDARY\r\nContent-Disposition: form-data; name="project-name"\r\n\r\n' +
openRefineProjectName +
'\r\n------BOUNDARY\r\nContent-Disposition: form-data; name="format"\r\n\r\n' +
openRefineFormat +
'\r\n------BOUNDARY--'
let jsonFixture
if (typeof fixture == 'string') {
jsonFixture = fixtures[fixture]
} else {
jsonFixture = fixture
}
cy.request({
method: 'POST',
url:
`${openRefineUrl}/command/core/create-project-from-upload?csrf_token=` +
token,
body: postData,
headers: {
'content-type':
'multipart/form-data; boundary=----BOUNDARY',
},
}).then((resp) => {
const location =
resp.allRequestResponses[0]['Response Headers'].location
const projectId = location.split('=').slice(-1)[0]
cy.log('Created OR project', projectId)
const csv = []
jsonFixture.forEach((item) => {
csv.push('"' + item.join('","') + '"')
})
const content = csv.join('\n')
cy.get('@loadedProjectIds', { log: false }).then(
(loadedProjectIds) => {
loadedProjectIds.push(projectId)
cy.wrap(loadedProjectIds, { log: false })
.as('loadedProjectIds')
.then(() => {
return projectId
})
}
)
})
cy.get('@token', { log: false }).then((token) => {
// cy.request(Cypress.env('OPENREFINE_URL')+'/command/core/get-csrf-token').then((response) => {
const openRefineFormat = 'text/line-based/*sv'
// the following code can be used to inject tags in created projects
// It's conflicting though, breaking up the CSV files
// const options = { projectTags: ['OpenRefineTesting'] };
// '\r\n------BOUNDARY\r\nContent-Disposition: form-data; name="options"\r\n\r\n' +
// JSON.stringify(options) +
var postData =
'------BOUNDARY\r\nContent-Disposition: form-data; name="project-file"; filename="' +
fixture +
'"\r\nContent-Type: "text/csv"\r\n\r\n' +
content +
'\r\n------BOUNDARY\r\nContent-Disposition: form-data; name="project-name"\r\n\r\n' +
openRefineProjectName +
'\r\n------BOUNDARY\r\nContent-Disposition: form-data; name="format"\r\n\r\n' +
openRefineFormat +
'\r\n------BOUNDARY--'
cy.request({
method: 'POST',
url:
`${openRefineUrl}/command/core/create-project-from-upload?csrf_token=` +
token,
body: postData,
headers: {
'content-type': 'multipart/form-data; boundary=----BOUNDARY',
},
}).then((resp) => {
const location =
resp.allRequestResponses[0]['Response Headers'].location
const projectId = location.split('=').slice(-1)[0]
cy.log('Created OR project', projectId)
cy.get('@loadedProjectIds', { log: false }).then(
(loadedProjectIds) => {
loadedProjectIds.push(projectId)
cy.wrap(loadedProjectIds, { log: false })
.as('loadedProjectIds')
.then(() => {
return projectId
})
}
)
})
})
})