Skip to content

Commit c913316

Browse files
committed
Tests: Migrate assets/ specs to use shared page-objects
- Rewrite `tests/e2e/assets/admin/{upload,delete,drag-reorder,single-mode,validation}.ts` to consume `DitoUploadField` from `tests/utils/pages.ts` instead of raw `.dito-*` selectors. - Delete `uploadFile`/`uploadFileTo` from `tests/e2e/assets/fixtures.ts` (replaced by `DitoUploadField.upload`). - Delete duplicate `createModelHelpers` from `tests/e2e/assets/fixtures.ts`; callers import from the shared `tests/utils/fixture-app.ts`.
1 parent 6c3bada commit c913316

6 files changed

Lines changed: 109 additions & 340 deletions

File tree

tests/e2e/assets/admin/delete.ts

Lines changed: 31 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import path from 'path'
22
import {
3-
test, expect, createModelHelpers,
4-
uploadFile, fixturesDir
3+
test, expect, fixturesDir
54
} from '../fixtures.js'
5+
import { createModelHelpers } from '../../../utils/fixture-app.js'
6+
import { DitoUploadField } from '../../../utils/pages.js'
67
import { AssetWidget } from '../models/AssetWidget.js'
78

89
const { seed, saveAndFetch } = createModelHelpers(
@@ -17,30 +18,21 @@ test.describe('delete', () => {
1718
await page.goto(
1819
`${url}/admin/assets/${widgetId}`
1920
)
20-
const upload = page.locator(
21-
'.dito-upload:has(input#files)'
22-
)
23-
await expect(upload).toBeVisible(
24-
{ timeout: 15_000 }
25-
)
21+
const upload = new DitoUploadField(page, 'files')
22+
await upload.waitUntilVisible({ timeout: 15_000 })
2623

27-
await uploadFile(
28-
page,
24+
await upload.upload(
2925
path.resolve(fixturesDir, 'tiny.png')
3026
)
31-
await expect(
32-
upload.locator('tbody tr')
33-
).toHaveCount(1)
27+
await expect(upload.rows).toHaveCount(1)
3428

3529
// Accept the confirm dialog
3630
page.on('dialog', dialog => dialog.accept())
37-
await upload.locator(
31+
await upload.container.locator(
3832
'.dito-button--delete'
3933
).first().click()
4034

41-
await expect(
42-
upload.locator('tbody tr')
43-
).toHaveCount(0)
35+
await expect(upload.rows).toHaveCount(0)
4436
}
4537
)
4638

@@ -51,30 +43,23 @@ test.describe('delete', () => {
5143
await page.goto(
5244
`${url}/admin/assets/${widgetId}`
5345
)
54-
const upload = page.locator(
55-
'.dito-upload:has(input#files)'
56-
)
57-
await expect(upload).toBeVisible(
58-
{ timeout: 15_000 }
59-
)
46+
const upload = new DitoUploadField(page, 'files')
47+
await upload.waitUntilVisible({ timeout: 15_000 })
6048

61-
await uploadFile(
62-
page,
49+
await upload.upload(
6350
path.resolve(fixturesDir, 'tiny.png')
6451
)
6552

6653
// Dismiss the confirm dialog
6754
page.once('dialog', dialog =>
6855
dialog.dismiss()
6956
)
70-
await upload.locator(
57+
await upload.container.locator(
7158
'.dito-button--delete'
7259
).first().click()
7360

7461
// File should still be there
75-
await expect(
76-
upload.locator('tbody tr')
77-
).toHaveCount(1)
62+
await expect(upload.rows).toHaveCount(1)
7863
}
7964
)
8065

@@ -85,16 +70,11 @@ test.describe('delete', () => {
8570
await page.goto(
8671
`${url}/admin/assets/${widgetId}`
8772
)
88-
const upload = page.locator(
89-
'.dito-upload:has(input#files)'
90-
)
91-
await expect(upload).toBeVisible(
92-
{ timeout: 15_000 }
93-
)
73+
const upload = new DitoUploadField(page, 'files')
74+
await upload.waitUntilVisible({ timeout: 15_000 })
9475

9576
// Upload and save first
96-
await uploadFile(
97-
page,
77+
await upload.upload(
9878
path.resolve(fixturesDir, 'tiny.png')
9979
)
10080
await saveAndFetch(page, widgetId)
@@ -103,18 +83,14 @@ test.describe('delete', () => {
10383
await page.goto(
10484
`${url}/admin/assets/${widgetId}`
10585
)
106-
await expect(
107-
upload.locator('tbody tr')
108-
).toHaveCount(1)
86+
await expect(upload.rows).toHaveCount(1)
10987

11088
page.on('dialog', dialog => dialog.accept())
111-
await upload.locator(
89+
await upload.container.locator(
11290
'.dito-button--delete'
11391
).first().click()
11492

115-
await expect(
116-
upload.locator('tbody tr')
117-
).toHaveCount(0)
93+
await expect(upload.rows).toHaveCount(0)
11894

11995
const widget = await saveAndFetch(
12096
page, widgetId
@@ -131,20 +107,15 @@ test.describe('delete', () => {
131107
await page.goto(
132108
`${url}/admin/assets/${widgetId}`
133109
)
134-
const upload = page.locator(
135-
'.dito-upload:has(input#files)'
136-
)
137-
await expect(upload).toBeVisible(
138-
{ timeout: 15_000 }
139-
)
110+
const upload = new DitoUploadField(page, 'files')
111+
await upload.waitUntilVisible({ timeout: 15_000 })
140112

141-
await uploadFile(
142-
page,
113+
await upload.upload(
143114
path.resolve(fixturesDir, 'tiny.png')
144115
)
145116

146117
page.on('dialog', dialog => dialog.accept())
147-
await upload.locator(
118+
await upload.container.locator(
148119
'.dito-button--delete'
149120
).first().click()
150121

@@ -168,16 +139,11 @@ test.describe('delete', () => {
168139
await page.goto(
169140
`${url}/admin/assets/${widgetId}`
170141
)
171-
const upload = page.locator(
172-
'.dito-upload:has(input#files)'
173-
)
174-
await expect(upload).toBeVisible(
175-
{ timeout: 15_000 }
176-
)
142+
const upload = new DitoUploadField(page, 'files')
143+
await upload.waitUntilVisible({ timeout: 15_000 })
177144

178145
// Upload first file and save
179-
await uploadFile(
180-
page,
146+
await upload.upload(
181147
path.resolve(fixturesDir, 'tiny.png')
182148
)
183149
const widget1 = await saveAndFetch(
@@ -189,21 +155,16 @@ test.describe('delete', () => {
189155
await page.goto(
190156
`${url}/admin/assets/${widgetId}`
191157
)
192-
await expect(
193-
upload.locator('tbody tr')
194-
).toHaveCount(1)
158+
await expect(upload.rows).toHaveCount(1)
195159

196160
page.on('dialog', dialog => dialog.accept())
197-
await upload.locator(
161+
await upload.container.locator(
198162
'.dito-button--delete'
199163
).first().click()
200164

201-
await expect(
202-
upload.locator('tbody tr')
203-
).toHaveCount(0)
165+
await expect(upload.rows).toHaveCount(0)
204166

205-
await uploadFile(
206-
page,
167+
await upload.upload(
207168
path.resolve(fixturesDir, 'small.png')
208169
)
209170

tests/e2e/assets/admin/drag-reorder.ts

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import path from 'path'
22
import {
3-
test, expect, createModelHelpers,
4-
uploadFile, fixturesDir
3+
test, expect, fixturesDir
54
} from '../fixtures.js'
5+
import { createModelHelpers } from '../../../utils/fixture-app.js'
6+
import { DitoUploadField } from '../../../utils/pages.js'
67
import { AssetWidget } from '../models/AssetWidget.js'
78

89
const { seed, saveAndFetch } = createModelHelpers(
@@ -17,29 +18,23 @@ test.describe('drag reorder', () => {
1718
await page.goto(
1819
`${url}/admin/assets/${widgetId}`
1920
)
20-
const upload = page.locator(
21-
'.dito-upload:has(input#files)'
22-
)
23-
await expect(upload).toBeVisible(
24-
{ timeout: 15_000 }
25-
)
21+
const upload = new DitoUploadField(page, 'files')
22+
await upload.waitUntilVisible({ timeout: 15_000 })
2623

2724
// Upload one file — no drag handle
28-
await uploadFile(
29-
page,
25+
await upload.upload(
3026
path.resolve(fixturesDir, 'tiny.png')
3127
)
3228
await expect(
33-
upload.locator('.dito-button--drag')
29+
upload.container.locator('.dito-button--drag')
3430
).toHaveCount(0)
3531

3632
// Upload second file — drag handles appear
37-
await uploadFile(
38-
page,
33+
await upload.upload(
3934
path.resolve(fixturesDir, 'tiny.jpg')
4035
)
4136
await expect(
42-
upload.locator('.dito-button--drag')
37+
upload.container.locator('.dito-button--drag')
4338
).toHaveCount(2)
4439
}
4540
)
@@ -51,28 +46,21 @@ test.describe('drag reorder', () => {
5146
await page.goto(
5247
`${url}/admin/assets/${widgetId}`
5348
)
54-
const upload = page.locator(
55-
'.dito-upload:has(input#files)'
56-
)
57-
await expect(upload).toBeVisible(
58-
{ timeout: 15_000 }
59-
)
49+
const upload = new DitoUploadField(page, 'files')
50+
await upload.waitUntilVisible({ timeout: 15_000 })
6051

61-
await uploadFile(
62-
page,
52+
await upload.upload(
6353
path.resolve(fixturesDir, 'tiny.png')
6454
)
65-
await uploadFile(
66-
page,
55+
await upload.upload(
6756
path.resolve(fixturesDir, 'tiny.jpg')
6857
)
6958

7059
// Verify initial order
71-
const rows = upload.locator('tbody tr')
72-
await expect(rows.nth(0)).toContainText(
60+
await expect(upload.getRow(0)).toContainText(
7361
'tiny.png'
7462
)
75-
await expect(rows.nth(1)).toContainText(
63+
await expect(upload.getRow(1)).toContainText(
7664
'tiny.jpg'
7765
)
7866

@@ -113,10 +101,10 @@ test.describe('drag reorder', () => {
113101
})
114102

115103
// Verify new order in DOM
116-
await expect(rows.nth(0)).toContainText(
104+
await expect(upload.getRow(0)).toContainText(
117105
'tiny.jpg'
118106
)
119-
await expect(rows.nth(1)).toContainText(
107+
await expect(upload.getRow(1)).toContainText(
120108
'tiny.png'
121109
)
122110

0 commit comments

Comments
 (0)