Skip to content

Commit

Permalink
Reduce mock file size in image upload tests (#2443)
Browse files Browse the repository at this point in the history
* try smaller fake file

* more tweaks
  • Loading branch information
david-crespo authored Sep 13, 2024
1 parent be84c19 commit f9f0d15
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/forms/image-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ function Step({ children, state, label, className }: StepProps) {
return (
// data-status used only for e2e testing
<div
className={cn('items-top flex gap-2 px-4 py-3', className)}
data-testid="upload-step"
className={cn('upload-step items-top flex gap-2 px-4 py-3', className)}
data-testid={`upload-step: ${label}`}
data-status={status}
>
{/* padding on icon to align it with text since everything is aligned to top */}
Expand Down
3 changes: 2 additions & 1 deletion mock-api/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,11 @@ export const handlers = makeHandlers({
disk.state = { state: 'import_ready' }
return 204
},
diskBulkWriteImport: ({ path, query, body }) => {
async diskBulkWriteImport({ path, query, body }) {
const disk = lookup.disk({ ...path, ...query })
const diskImport = db.diskBulkImportState.get(disk.id)
if (!diskImport) throw notFoundErr(`disk import for disk '${disk.id}'`)
await delay(1000) // slow it down for the tests
// if (Math.random() < 0.01) throw 400
diskImport.blocks[body.offset] = true
return 204
Expand Down
21 changes: 6 additions & 15 deletions test/e2e/image-upload.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function expectUploadProcess(page: Page) {
const progressModal = page.getByRole('dialog', { name: 'Image upload progress' })
await expect(progressModal).toBeVisible()

const steps = page.getByTestId('upload-step')
const steps = page.locator('css=.upload-step')
await expect(steps).toHaveCount(8)

const done = progressModal.getByRole('button', { name: 'Done' })
Expand Down Expand Up @@ -114,10 +114,7 @@ test.describe('Image upload', () => {
await expectVisible(page, [fileRequired])
})

test('cancel', async ({ page, browserName }) => {
// eslint-disable-next-line playwright/no-skipped-test
test.skip(browserName === 'webkit', 'safari. stop this')

test('cancel', async ({ page }) => {
await fillForm(page, 'new-image')

await page.click('role=button[name="Upload image"]')
Expand All @@ -126,10 +123,7 @@ test.describe('Image upload', () => {
await expect(progressModal).toBeVisible()

// wait to be in the middle of upload
const uploadStep = page
.getByTestId('upload-step')
.filter({ hasText: 'Upload image file' })
.first()
const uploadStep = page.getByTestId('upload-step: Upload image file')
await expect(uploadStep).toHaveAttribute('data-status', 'running')

// form is disabled and semi-hidden
Expand Down Expand Up @@ -196,10 +190,7 @@ test.describe('Image upload', () => {
await page.click('role=button[name="Upload image"]')

// wait to be in the middle of upload
const uploadStep = page
.locator('div[data-status]')
.filter({ hasText: 'Upload image file' })
.first()
const uploadStep = page.getByTestId('upload-step: Upload image file')
await expect(uploadStep).toHaveAttribute('data-status', 'running')

// form is disabled and semi-hidden
Expand Down Expand Up @@ -227,7 +218,7 @@ test.describe('Image upload', () => {
{ imageName: 'disk-create-500', stepText: 'Create temporary disk' },
{ imageName: 'import-start-500', stepText: 'Put disk in import mode' },
{ imageName: 'import-stop-500', stepText: 'Get disk out of import mode' },
{ imageName: 'disk-finalize-500', stepText: 'Finalize disk' },
{ imageName: 'disk-finalize-500', stepText: 'Finalize disk and create snapshot' },
]

for (const { imageName, stepText } of failureCases) {
Expand All @@ -236,7 +227,7 @@ test.describe('Image upload', () => {

await page.click('role=button[name="Upload image"]')

const step = page.locator('[data-status]').filter({ hasText: stepText }).first()
const step = page.getByTestId(`upload-step: ${stepText}`)
await expect(step).toHaveAttribute('data-status', 'error', { timeout: 15000 })
await expectVisible(page, [
'text="Something went wrong. Please try again."',
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export async function expectObscured(locator: Locator) {

export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

export async function chooseFile(page: Page, inputLocator: Locator, size = 15 * MiB) {
export async function chooseFile(page: Page, inputLocator: Locator, size = 3 * MiB) {
const fileChooserPromise = page.waitForEvent('filechooser')
await inputLocator.click()
const fileChooser = await fileChooserPromise
Expand Down

0 comments on commit f9f0d15

Please sign in to comment.