Skip to content

Commit f9f0d15

Browse files
authored
Reduce mock file size in image upload tests (#2443)
* try smaller fake file * more tweaks
1 parent be84c19 commit f9f0d15

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

app/forms/image-upload.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ function Step({ children, state, label, className }: StepProps) {
103103
return (
104104
// data-status used only for e2e testing
105105
<div
106-
className={cn('items-top flex gap-2 px-4 py-3', className)}
107-
data-testid="upload-step"
106+
className={cn('upload-step items-top flex gap-2 px-4 py-3', className)}
107+
data-testid={`upload-step: ${label}`}
108108
data-status={status}
109109
>
110110
{/* padding on icon to align it with text since everything is aligned to top */}

mock-api/msw/handlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,11 @@ export const handlers = makeHandlers({
206206
disk.state = { state: 'import_ready' }
207207
return 204
208208
},
209-
diskBulkWriteImport: ({ path, query, body }) => {
209+
async diskBulkWriteImport({ path, query, body }) {
210210
const disk = lookup.disk({ ...path, ...query })
211211
const diskImport = db.diskBulkImportState.get(disk.id)
212212
if (!diskImport) throw notFoundErr(`disk import for disk '${disk.id}'`)
213+
await delay(1000) // slow it down for the tests
213214
// if (Math.random() < 0.01) throw 400
214215
diskImport.blocks[body.offset] = true
215216
return 204

test/e2e/image-upload.e2e.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function expectUploadProcess(page: Page) {
2424
const progressModal = page.getByRole('dialog', { name: 'Image upload progress' })
2525
await expect(progressModal).toBeVisible()
2626

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

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

117-
test('cancel', async ({ page, browserName }) => {
118-
// eslint-disable-next-line playwright/no-skipped-test
119-
test.skip(browserName === 'webkit', 'safari. stop this')
120-
117+
test('cancel', async ({ page }) => {
121118
await fillForm(page, 'new-image')
122119

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

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

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

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

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

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

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

239-
const step = page.locator('[data-status]').filter({ hasText: stepText }).first()
230+
const step = page.getByTestId(`upload-step: ${stepText}`)
240231
await expect(step).toHaveAttribute('data-status', 'error', { timeout: 15000 })
241232
await expectVisible(page, [
242233
'text="Something went wrong. Please try again."',

test/e2e/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export async function expectObscured(locator: Locator) {
195195

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

198-
export async function chooseFile(page: Page, inputLocator: Locator, size = 15 * MiB) {
198+
export async function chooseFile(page: Page, inputLocator: Locator, size = 3 * MiB) {
199199
const fileChooserPromise = page.waitForEvent('filechooser')
200200
await inputLocator.click()
201201
const fileChooser = await fileChooserPromise

0 commit comments

Comments
 (0)