2022-06-12 17:34:33 +02:00
|
|
|
import test, { expect } from '@playwright/test'
|
|
|
|
import cuid from 'cuid'
|
|
|
|
import path from 'path'
|
2022-06-16 11:12:51 +02:00
|
|
|
import { parse } from 'papaparse'
|
2022-06-12 17:34:33 +02:00
|
|
|
import { typebotViewer } from '../services/selectorUtils'
|
2022-09-17 16:37:33 +02:00
|
|
|
import { createResults, importTypebotInDatabase } from '../services/database'
|
2022-06-16 11:12:51 +02:00
|
|
|
import { readFileSync } from 'fs'
|
2022-06-26 18:17:50 +02:00
|
|
|
import { isDefined } from 'utils'
|
2022-08-21 22:33:09 +02:00
|
|
|
|
2022-09-17 16:37:33 +02:00
|
|
|
const THREE_GIGABYTES = 3 * 1024 * 1024 * 1024
|
2022-06-12 17:34:33 +02:00
|
|
|
|
2022-06-26 18:17:50 +02:00
|
|
|
test('should work as expected', async ({ page, browser }) => {
|
2022-06-12 17:34:33 +02:00
|
|
|
const typebotId = cuid()
|
|
|
|
await importTypebotInDatabase(
|
|
|
|
path.join(__dirname, '../fixtures/typebots/fileUpload.json'),
|
|
|
|
{ id: typebotId, publicId: `${typebotId}-public` }
|
|
|
|
)
|
|
|
|
await page.goto(`/${typebotId}-public`)
|
|
|
|
await typebotViewer(page)
|
|
|
|
.locator(`input[type="file"]`)
|
|
|
|
.setInputFiles([
|
|
|
|
path.join(__dirname, '../fixtures/typebots/api.json'),
|
|
|
|
path.join(__dirname, '../fixtures/typebots/fileUpload.json'),
|
|
|
|
path.join(__dirname, '../fixtures/typebots/hugeGroup.json'),
|
|
|
|
])
|
|
|
|
await expect(typebotViewer(page).locator(`text="3"`)).toBeVisible()
|
|
|
|
await typebotViewer(page).locator('text="Upload 3 files"').click()
|
|
|
|
await expect(
|
|
|
|
typebotViewer(page).locator(`text="3 files uploaded"`)
|
|
|
|
).toBeVisible()
|
2022-08-21 22:33:09 +02:00
|
|
|
await page.goto(`${process.env.BUILDER_URL}/typebots/${typebotId}/results`)
|
2022-06-12 17:34:33 +02:00
|
|
|
await expect(page.locator('text="api.json"')).toHaveAttribute(
|
|
|
|
'href',
|
|
|
|
/.+\/api\.json/
|
|
|
|
)
|
|
|
|
await expect(page.locator('text="fileUpload.json"')).toHaveAttribute(
|
|
|
|
'href',
|
|
|
|
/.+\/fileUpload\.json/
|
|
|
|
)
|
2022-06-24 14:06:06 +02:00
|
|
|
await expect(page.locator('text="hugeGroup.json"')).toHaveAttribute(
|
2022-06-12 17:34:33 +02:00
|
|
|
'href',
|
2022-06-24 14:06:06 +02:00
|
|
|
/.+\/hugeGroup\.json/
|
2022-06-12 17:34:33 +02:00
|
|
|
)
|
2022-06-16 11:12:51 +02:00
|
|
|
|
|
|
|
await page.click('[data-testid="checkbox"] >> nth=0')
|
|
|
|
const [download] = await Promise.all([
|
|
|
|
page.waitForEvent('download'),
|
2022-07-01 17:08:35 +02:00
|
|
|
page.locator('text="Export"').click(),
|
2022-06-16 11:12:51 +02:00
|
|
|
])
|
|
|
|
const downloadPath = await download.path()
|
2022-09-24 08:58:23 +02:00
|
|
|
expect(downloadPath).toBeDefined()
|
2022-06-16 11:12:51 +02:00
|
|
|
const file = readFileSync(downloadPath as string).toString()
|
|
|
|
const { data } = parse(file)
|
|
|
|
expect(data).toHaveLength(2)
|
|
|
|
expect((data[1] as unknown[])[1]).toContain('http://localhost:9000')
|
2022-06-24 14:06:06 +02:00
|
|
|
|
2022-06-26 18:17:50 +02:00
|
|
|
const urls = (
|
|
|
|
await Promise.all(
|
|
|
|
[
|
|
|
|
page.locator('text="api.json"'),
|
|
|
|
page.locator('text="fileUpload.json"'),
|
|
|
|
page.locator('text="hugeGroup.json"'),
|
|
|
|
].map((elem) => elem.getAttribute('href'))
|
|
|
|
)
|
|
|
|
).filter(isDefined)
|
2022-06-24 14:06:06 +02:00
|
|
|
|
2022-06-26 18:17:50 +02:00
|
|
|
const page2 = await browser.newPage()
|
|
|
|
await page2.goto(urls[0])
|
|
|
|
await expect(page2.locator('pre')).toBeVisible()
|
2022-06-24 14:06:06 +02:00
|
|
|
|
2022-06-26 18:17:50 +02:00
|
|
|
await page.locator('button >> text="Delete"').click()
|
|
|
|
await page.locator('button >> text="Delete" >> nth=1').click()
|
|
|
|
await expect(page.locator('text="api.json"')).toBeHidden()
|
|
|
|
await page2.goto(urls[0])
|
|
|
|
await expect(
|
|
|
|
page2.locator('span:has-text("The specified key does not exist.")')
|
|
|
|
).toBeVisible()
|
|
|
|
await page2.goto(urls[1])
|
|
|
|
await expect(
|
|
|
|
page2.locator('span:has-text("The specified key does not exist.")')
|
|
|
|
).toBeVisible()
|
|
|
|
await page2.goto(urls[2])
|
|
|
|
await expect(
|
|
|
|
page2.locator('span:has-text("The specified key does not exist.")')
|
|
|
|
).toBeVisible()
|
2022-06-12 17:34:33 +02:00
|
|
|
})
|
2022-09-17 16:37:33 +02:00
|
|
|
|
2022-09-24 08:58:23 +02:00
|
|
|
test.describe('Storage limit is reached', () => {
|
2022-09-17 16:37:33 +02:00
|
|
|
const typebotId = cuid()
|
|
|
|
|
|
|
|
test.beforeAll(async () => {
|
|
|
|
await importTypebotInDatabase(
|
|
|
|
path.join(__dirname, '../fixtures/typebots/fileUpload.json'),
|
|
|
|
{
|
|
|
|
id: typebotId,
|
|
|
|
publicId: `${typebotId}-public`,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
await createResults({
|
|
|
|
typebotId,
|
|
|
|
count: 20,
|
|
|
|
fakeStorage: THREE_GIGABYTES,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test("shouldn't upload anything if limit has been reached", async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
await page.goto(`/${typebotId}-public`)
|
|
|
|
await typebotViewer(page)
|
|
|
|
.locator(`input[type="file"]`)
|
|
|
|
.setInputFiles([
|
|
|
|
path.join(__dirname, '../fixtures/typebots/api.json'),
|
|
|
|
path.join(__dirname, '../fixtures/typebots/fileUpload.json'),
|
|
|
|
path.join(__dirname, '../fixtures/typebots/hugeGroup.json'),
|
|
|
|
])
|
|
|
|
await expect(typebotViewer(page).locator(`text="3"`)).toBeVisible()
|
|
|
|
await typebotViewer(page).locator('text="Upload 3 files"').click()
|
|
|
|
await expect(
|
|
|
|
typebotViewer(page).locator(`text="3 files uploaded"`)
|
|
|
|
).toBeVisible()
|
|
|
|
await page.evaluate(() =>
|
|
|
|
window.localStorage.setItem('workspaceId', 'starterWorkspace')
|
|
|
|
)
|
|
|
|
await page.goto(`${process.env.BUILDER_URL}/typebots/${typebotId}/results`)
|
|
|
|
await expect(page.locator('text="150%"')).toBeVisible()
|
|
|
|
await expect(page.locator('text="api.json"')).toBeHidden()
|
|
|
|
})
|
|
|
|
})
|