11import path from 'path'
22import {
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'
67import { AssetWidget } from '../models/AssetWidget.js'
78
89const { 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
0 commit comments