2022-01-28 09:42:31 +01:00
|
|
|
import test, { expect, Page } from '@playwright/test'
|
2022-03-18 12:30:42 +01:00
|
|
|
import cuid from 'cuid'
|
2022-01-28 09:42:31 +01:00
|
|
|
import { readFileSync } from 'fs'
|
2022-06-11 07:27:38 +02:00
|
|
|
import { defaultTextInputOptions, InputBlockType } from 'models'
|
2022-01-28 09:42:31 +01:00
|
|
|
import { parse } from 'papaparse'
|
2022-02-12 12:54:16 +01:00
|
|
|
import path from 'path'
|
2022-01-28 09:42:31 +01:00
|
|
|
import {
|
|
|
|
createResults,
|
|
|
|
createTypebots,
|
2022-02-17 10:46:04 +01:00
|
|
|
importTypebotInDatabase,
|
2022-06-11 07:27:38 +02:00
|
|
|
parseDefaultGroupWithBlock,
|
2022-01-28 09:42:31 +01:00
|
|
|
} from '../services/database'
|
|
|
|
import { deleteButtonInConfirmDialog } from '../services/selectorUtils'
|
|
|
|
|
2022-03-18 12:30:42 +01:00
|
|
|
const typebotId = cuid()
|
2022-01-28 09:42:31 +01:00
|
|
|
|
2022-07-01 17:08:35 +02:00
|
|
|
test('Submission table header should be parsed correctly', async ({ page }) => {
|
|
|
|
const typebotId = cuid()
|
|
|
|
await importTypebotInDatabase(
|
|
|
|
path.join(__dirname, '../fixtures/typebots/results/submissionHeader.json'),
|
|
|
|
{
|
|
|
|
id: typebotId,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
await page.goto(`/typebots/${typebotId}/results`)
|
|
|
|
await expect(page.locator('text=Submitted at')).toBeVisible()
|
|
|
|
await expect(page.locator('text=Welcome')).toBeVisible()
|
|
|
|
await expect(page.locator('text=Email')).toBeVisible()
|
|
|
|
await expect(page.locator('text=Name')).toBeVisible()
|
|
|
|
await expect(page.locator('text=Services')).toBeVisible()
|
|
|
|
await expect(page.locator('text=Additional information')).toBeVisible()
|
|
|
|
await expect(page.locator('text=utm_source')).toBeVisible()
|
|
|
|
await expect(page.locator('text=utm_userid')).toBeVisible()
|
|
|
|
})
|
2022-02-17 10:46:04 +01:00
|
|
|
|
2022-07-01 17:08:35 +02:00
|
|
|
test('results should be deletable', async ({ page }) => {
|
|
|
|
await createTypebots([
|
|
|
|
{
|
|
|
|
id: typebotId,
|
|
|
|
...parseDefaultGroupWithBlock({
|
|
|
|
type: InputBlockType.TEXT,
|
|
|
|
options: defaultTextInputOptions,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
])
|
2022-09-24 08:58:23 +02:00
|
|
|
await createResults({ typebotId, count: 200, isChronological: true })
|
2022-07-01 17:08:35 +02:00
|
|
|
await page.goto(`/typebots/${typebotId}/results`)
|
2022-10-02 10:34:13 +02:00
|
|
|
await expect(page.locator('text=content199')).toBeVisible()
|
|
|
|
await page.click('[data-testid="checkbox"] >> nth=1')
|
|
|
|
await page.click('[data-testid="checkbox"] >> nth=2')
|
2022-07-01 17:08:35 +02:00
|
|
|
await page.click('text="Delete"')
|
|
|
|
await deleteButtonInConfirmDialog(page).click()
|
|
|
|
await expect(page.locator('text=content199')).toBeHidden()
|
|
|
|
await expect(page.locator('text=content198')).toBeHidden()
|
|
|
|
await page.waitForTimeout(1000)
|
|
|
|
await page.click('[data-testid="checkbox"] >> nth=0')
|
|
|
|
await page.click('text="Delete"')
|
|
|
|
await deleteButtonInConfirmDialog(page).click()
|
|
|
|
await page.waitForTimeout(1000)
|
|
|
|
expect(await page.locator('tr').count()).toBe(1)
|
|
|
|
await expect(page.locator('text="Delete"')).toBeHidden()
|
|
|
|
})
|
2022-01-28 09:42:31 +01:00
|
|
|
|
2022-07-01 17:08:35 +02:00
|
|
|
test('submissions table should have infinite scroll', async ({ page }) => {
|
|
|
|
const scrollToBottom = () =>
|
|
|
|
page.evaluate(() => {
|
|
|
|
const tableWrapper = document.querySelector('.table-wrapper')
|
|
|
|
if (!tableWrapper) return
|
|
|
|
tableWrapper.scrollTo(0, tableWrapper.scrollHeight)
|
|
|
|
})
|
2022-01-28 09:42:31 +01:00
|
|
|
|
2022-09-24 08:58:23 +02:00
|
|
|
await createResults({ typebotId, count: 200, isChronological: true })
|
2022-07-01 17:08:35 +02:00
|
|
|
await page.goto(`/typebots/${typebotId}/results`)
|
|
|
|
await expect(page.locator('text=content199')).toBeVisible()
|
2022-01-28 09:42:31 +01:00
|
|
|
|
2022-07-01 17:08:35 +02:00
|
|
|
await expect(page.locator('text=content149')).toBeHidden()
|
|
|
|
await scrollToBottom()
|
|
|
|
await expect(page.locator('text=content149')).toBeVisible()
|
2022-01-28 09:42:31 +01:00
|
|
|
|
2022-07-01 17:08:35 +02:00
|
|
|
await expect(page.locator('text=content99')).toBeHidden()
|
|
|
|
await scrollToBottom()
|
|
|
|
await expect(page.locator('text=content99')).toBeVisible()
|
2022-01-28 09:42:31 +01:00
|
|
|
|
2022-07-01 17:08:35 +02:00
|
|
|
await expect(page.locator('text=content49')).toBeHidden()
|
|
|
|
await scrollToBottom()
|
|
|
|
await expect(page.locator('text=content49')).toBeVisible()
|
|
|
|
await expect(page.locator('text=content0')).toBeVisible()
|
|
|
|
})
|
2022-01-28 09:42:31 +01:00
|
|
|
|
2022-07-01 17:08:35 +02:00
|
|
|
test('should correctly export selection in CSV', async ({ page }) => {
|
|
|
|
await page.goto(`/typebots/${typebotId}/results`)
|
2022-10-02 10:34:13 +02:00
|
|
|
await expect(page.locator('text=content199')).toBeVisible()
|
|
|
|
await page.click('[data-testid="checkbox"] >> nth=1')
|
|
|
|
await page.click('[data-testid="checkbox"] >> nth=2')
|
2022-07-01 17:08:35 +02:00
|
|
|
const [download] = await Promise.all([
|
|
|
|
page.waitForEvent('download'),
|
|
|
|
page.locator('text="Export"').click(),
|
|
|
|
])
|
|
|
|
const path = await download.path()
|
|
|
|
expect(path).toBeDefined()
|
|
|
|
const file = readFileSync(path as string).toString()
|
|
|
|
const { data } = parse(file)
|
|
|
|
validateExportSelection(data)
|
2022-02-12 12:54:16 +01:00
|
|
|
|
2022-07-01 17:08:35 +02:00
|
|
|
await page.click('[data-testid="checkbox"] >> nth=0')
|
|
|
|
const [downloadAll] = await Promise.all([
|
|
|
|
page.waitForEvent('download'),
|
|
|
|
page.locator('text="Export"').click(),
|
|
|
|
])
|
|
|
|
const pathAll = await downloadAll.path()
|
|
|
|
expect(pathAll).toBeDefined()
|
|
|
|
const fileAll = readFileSync(pathAll as string).toString()
|
|
|
|
const { data: dataAll } = parse(fileAll)
|
|
|
|
validateExportAll(dataAll)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Can resize, hide and reorder columns', async ({ page }) => {
|
|
|
|
const typebotId = cuid()
|
|
|
|
await importTypebotInDatabase(
|
|
|
|
path.join(__dirname, '../fixtures/typebots/results/submissionHeader.json'),
|
|
|
|
{
|
|
|
|
id: typebotId,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
await page.goto(`/typebots/${typebotId}/results`)
|
|
|
|
|
|
|
|
// Resize
|
|
|
|
expect((await page.locator('th >> nth=4').boundingBox())?.width).toBe(200)
|
|
|
|
await page.waitForTimeout(500)
|
|
|
|
await page.dragAndDrop(
|
|
|
|
'[data-testid="resize-handle"] >> nth=3',
|
|
|
|
'[data-testid="resize-handle"] >> nth=3',
|
|
|
|
{ targetPosition: { x: 150, y: 0 }, force: true }
|
|
|
|
)
|
|
|
|
await page.waitForTimeout(500)
|
|
|
|
expect((await page.locator('th >> nth=4').boundingBox())?.width).toBe(345)
|
|
|
|
|
|
|
|
// Hide
|
|
|
|
await expect(
|
|
|
|
page.locator('[data-testid="Submitted at header"]')
|
|
|
|
).toBeVisible()
|
|
|
|
await expect(page.locator('[data-testid="Email header"]')).toBeVisible()
|
|
|
|
await page.click('button >> text="Columns"')
|
|
|
|
await page.click('[aria-label="Hide column"] >> nth=0')
|
|
|
|
await page.click('[aria-label="Hide column"] >> nth=1')
|
|
|
|
await expect(page.locator('[data-testid="Submitted at header"]')).toBeHidden()
|
|
|
|
await expect(page.locator('[data-testid="Email header"]')).toBeHidden()
|
|
|
|
|
|
|
|
// Reorder
|
|
|
|
await expect(page.locator('th >> nth=1')).toHaveText('Welcome')
|
|
|
|
await expect(page.locator('th >> nth=2')).toHaveText('Name')
|
|
|
|
await page.dragAndDrop(
|
|
|
|
'[aria-label="Drag"] >> nth=0',
|
|
|
|
'[aria-label="Drag"] >> nth=0',
|
|
|
|
{ targetPosition: { x: 0, y: 80 }, force: true }
|
|
|
|
)
|
|
|
|
await expect(page.locator('th >> nth=1')).toHaveText('Name')
|
|
|
|
await expect(page.locator('th >> nth=2')).toHaveText('Welcome')
|
|
|
|
|
|
|
|
// Preferences should be persisted
|
|
|
|
const saveAndReload = async (page: Page) => {
|
|
|
|
await page.click('text="Theme"')
|
|
|
|
await page.waitForTimeout(2000)
|
|
|
|
await page.goto(`/typebots/${typebotId}/results`)
|
|
|
|
}
|
|
|
|
await saveAndReload(page)
|
|
|
|
expect((await page.locator('th >> nth=1').boundingBox())?.width).toBe(345)
|
|
|
|
await expect(page.locator('[data-testid="Submitted at header"]')).toBeHidden()
|
|
|
|
await expect(page.locator('[data-testid="Email header"]')).toBeHidden()
|
|
|
|
await expect(page.locator('th >> nth=1')).toHaveText('Name')
|
|
|
|
await expect(page.locator('th >> nth=2')).toHaveText('Welcome')
|
|
|
|
})
|
|
|
|
|
2022-01-28 09:42:31 +01:00
|
|
|
const validateExportSelection = (data: unknown[]) => {
|
|
|
|
expect(data).toHaveLength(3)
|
|
|
|
expect((data[1] as unknown[])[1]).toBe('content199')
|
|
|
|
expect((data[2] as unknown[])[1]).toBe('content198')
|
|
|
|
}
|
|
|
|
|
|
|
|
const validateExportAll = (data: unknown[]) => {
|
|
|
|
expect(data).toHaveLength(201)
|
|
|
|
expect((data[1] as unknown[])[1]).toBe('content199')
|
|
|
|
expect((data[200] as unknown[])[1]).toBe('content0')
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectFirstResults = async (page: Page) => {
|
2022-02-12 10:12:43 +01:00
|
|
|
await page.click('[data-testid="checkbox"] >> nth=1')
|
2022-10-02 10:34:13 +02:00
|
|
|
await page.click('[data-testid="checkbox"] >> nth=2')
|
2022-01-28 09:42:31 +01:00
|
|
|
}
|