2
0

⚗️ Add export results

This commit is contained in:
Baptiste Arnaud
2022-01-04 15:50:56 +01:00
parent 72454c0f68
commit 6c1e0fd345
11 changed files with 235 additions and 103 deletions

View File

@ -1,3 +1,6 @@
import path from 'path'
import { parse } from 'papaparse'
describe('ResultsPage', () => {
before(() => {
cy.intercept({ url: '/api/typebots/typebot2/results*', method: 'GET' }).as(
@ -44,4 +47,48 @@ describe('ResultsPage', () => {
cy.findByText('content50').should('exist')
cy.findByText('content0').should('exist')
})
it.only('should correctly export selection in CSV', () => {
const downloadsFolder = Cypress.config('downloadsFolder')
cy.signIn('test2@gmail.com')
cy.visit('/typebots/typebot2/results')
cy.wait('@getResults')
cy.findByRole('button', { name: 'Export' }).should('not.exist')
cy.findByText('content199').should('exist')
cy.findAllByRole('checkbox').eq(2).check({ force: true })
cy.findAllByRole('checkbox').eq(3).check({ force: true })
cy.findByRole('button', { name: 'Export 2' }).click({ force: true })
const filename = path.join(
downloadsFolder,
`typebot-export_${new Date()
.toLocaleDateString()
.replaceAll('/', '-')}.csv`
)
cy.readFile(filename, { timeout: 15000 })
.then(parse)
.then(validateExportSelection as any)
cy.findAllByRole('checkbox').first().check({ force: true })
cy.findByRole('button', { name: 'Export 200' }).click({ force: true })
const filenameAll = path.join(
downloadsFolder,
`typebot-export_${new Date()
.toLocaleDateString()
.replaceAll('/', '-')}_all.csv`
)
cy.readFile(filenameAll, { timeout: 15000 })
.then(parse)
.then(validateExportAll as any)
})
})
const validateExportSelection = (list: { data: unknown[][] }) => {
expect(list.data, 'number of records').to.have.length(3)
expect(list.data[1][1], 'first record').to.equal('content198')
expect(list.data[2][1], 'second record').to.equal('content197')
}
const validateExportAll = (list: { data: unknown[][] }) => {
expect(list.data, 'number of records').to.have.length(201)
expect(list.data[1][1], 'first record').to.equal('content199')
expect(list.data[200][1], 'second record').to.equal('content0')
}

View File

@ -4,7 +4,7 @@
"exclude": [],
"compilerOptions": {
"types": ["cypress", "@testing-library/cypress", "cypress-file-upload"],
"lib": ["es2015", "dom"],
"lib": ["es2015", "dom", "ES2021.String"],
"target": "es5",
"isolatedModules": false,
"allowJs": true,