-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72454c0
commit 6c1e0fd
Showing
11 changed files
with
235 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
cypress/videos | ||
cypress/screenshots | ||
cypress/screenshots | ||
cypress/downloads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { | ||
HStack, | ||
Button, | ||
Fade, | ||
Tag, | ||
Text, | ||
useDisclosure, | ||
} from '@chakra-ui/react' | ||
import { DownloadIcon, TrashIcon } from 'assets/icons' | ||
import { ConfirmModal } from 'components/modals/ConfirmModal' | ||
import React from 'react' | ||
|
||
type ResultsActionButtonsProps = { | ||
totalSelected: number | ||
isDeleteLoading: boolean | ||
isExportLoading: boolean | ||
onDeleteClick: () => Promise<void> | ||
onExportClick: () => void | ||
} | ||
|
||
export const ResultsActionButtons = ({ | ||
totalSelected, | ||
isDeleteLoading, | ||
isExportLoading, | ||
onDeleteClick, | ||
onExportClick, | ||
}: ResultsActionButtonsProps) => { | ||
const { isOpen, onOpen, onClose } = useDisclosure() | ||
return ( | ||
<HStack> | ||
<Fade in={totalSelected > 0} unmountOnExit> | ||
<HStack | ||
as={Button} | ||
colorScheme="blue" | ||
onClick={onExportClick} | ||
isLoading={isExportLoading} | ||
> | ||
<DownloadIcon /> | ||
<Text>Export</Text> | ||
|
||
<Tag colorScheme="blue" variant="subtle" size="sm"> | ||
{totalSelected} | ||
</Tag> | ||
</HStack> | ||
</Fade> | ||
|
||
<Fade in={totalSelected > 0} unmountOnExit> | ||
<HStack | ||
as={Button} | ||
colorScheme="red" | ||
onClick={onOpen} | ||
isLoading={isDeleteLoading} | ||
> | ||
<TrashIcon /> | ||
<Text>Delete</Text> | ||
{totalSelected > 0 && ( | ||
<Tag colorScheme="red" variant="subtle" size="sm"> | ||
{totalSelected} | ||
</Tag> | ||
)} | ||
</HStack> | ||
<ConfirmModal | ||
isOpen={isOpen} | ||
onConfirm={onDeleteClick} | ||
onClose={onClose} | ||
message={ | ||
<Text> | ||
You are about to delete{' '} | ||
<strong> | ||
{totalSelected} submission | ||
{totalSelected > 1 ? 's' : ''} | ||
</strong> | ||
. Are you sure you wish to continue? | ||
</Text> | ||
} | ||
confirmButtonLabel={'Delete'} | ||
/> | ||
</Fade> | ||
</HStack> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('[email protected]') | ||
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') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.