Skip to content

Commit 56b0e71

Browse files
authoredMar 18, 2025··
fix(test): updates flaky imageArrayDraft pte test (#8975)
1 parent 3bf6557 commit 56b0e71

File tree

1 file changed

+59
-34
lines changed

1 file changed

+59
-34
lines changed
 
+59-34
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,72 @@
1+
import {createReadStream} from 'node:fs'
2+
import path from 'node:path'
3+
14
import {expect} from '@playwright/test'
5+
import {type SanityImageAssetDocument} from '@sanity/client'
26
import {test} from '@sanity/test'
37

4-
test('Portable Text Input - Array Input of images dragging an image will not trigger range out of bounds (toast)', async ({
5-
page,
6-
createDraftDocument,
7-
}) => {
8-
await createDraftDocument('/test/content/input-standard;portable-text;pt_allTheBellsAndWhistles')
9-
10-
// set up the portable text editor
11-
await page.getByTestId('field-body').focus()
12-
await page.getByTestId('field-body').click()
8+
test.describe('Portable Text Input - ImageArrayDraft', () => {
9+
let uploadedAsset: SanityImageAssetDocument
10+
test.beforeAll(async ({sanityClient}) => {
11+
const asset = await sanityClient.assets.upload(
12+
'image',
13+
createReadStream(path.join(__dirname, '..', '..', 'resources', 'capybara.jpg')),
14+
{
15+
filename: 'image-array-drag.jpg',
16+
title: 'image-array-drag',
17+
},
18+
)
19+
uploadedAsset = asset
20+
})
1321

14-
page.on('dialog', async () => {
15-
await expect(page.getByTestId('insert-menu-auto-collapse-menu')).toBeVisible()
22+
test.afterAll(async ({sanityClient}) => {
23+
await sanityClient.delete(uploadedAsset._id)
1624
})
1725

18-
// open the insert menu
19-
await page
20-
.getByTestId('insert-menu-auto-collapse-menu')
21-
.getByRole('button', {name: 'Insert Image slideshow (block)'})
22-
.click()
26+
test('Portable Text Input - Array Input of images dragging an image will not trigger range out of bounds (toast)', async ({
27+
page,
28+
createDraftDocument,
29+
}) => {
30+
await createDraftDocument(
31+
'/test/content/input-standard;portable-text;pt_allTheBellsAndWhistles',
32+
)
33+
34+
// set up the portable text editor
35+
await page.getByTestId('field-body').focus()
36+
await page.getByTestId('field-body').click()
2337

24-
// set up for the PTE block
25-
await page.getByRole('button', {name: 'Add item'}).click()
26-
await page.getByTestId('file-input-multi-browse-button').click()
27-
await page.getByTestId('file-input-browse-button-sanity-default').click()
38+
page.on('dialog', async () => {
39+
await expect(page.getByTestId('insert-menu-auto-collapse-menu')).toBeVisible()
40+
})
2841

29-
// grab an image
30-
await page.getByRole('button', {name: 'capybara.jpg'}).click()
31-
await page.getByLabel('Edit Image With Caption').getByLabel('Close dialog').click()
42+
// open the insert menu
43+
await page
44+
.getByTestId('insert-menu-auto-collapse-menu')
45+
.getByRole('button', {name: 'Insert Image slideshow (block)'})
46+
.click()
3247

33-
// grab drag element in array element
34-
await page.locator("[data-sanity-icon='drag-handle']").hover()
48+
// set up for the PTE block
49+
await page.getByRole('button', {name: 'Add item'}).click()
50+
await page.getByTestId('file-input-multi-browse-button').click()
51+
await page.getByTestId('file-input-browse-button-sanity-default').click()
3552

36-
// drag and drop element
37-
await page.mouse.down()
38-
await page.getByRole('button', {name: 'Add item'}).hover()
39-
await page.mouse.up()
53+
// grab an image
54+
await page.getByRole('button', {name: uploadedAsset.originalFilename}).click()
55+
await page.getByLabel('Edit Image With Caption').getByLabel('Close dialog').click()
4056

41-
await page.locator(
42-
`:has-text("Failed to execute 'getRangeAt' on 'Selection': 0 is not a valid index.']`,
43-
)
57+
// grab drag element in array element
58+
await page.locator("[data-sanity-icon='drag-handle']").hover()
4459

45-
// check that the alert is not visible
46-
await expect(await page.getByRole('alert').locator('div').nth(1)).not.toBeVisible()
60+
// drag and drop element
61+
await page.mouse.down()
62+
await page.getByRole('button', {name: 'Add item'}).hover()
63+
await page.mouse.up()
64+
65+
await page.locator(
66+
`:has-text("Failed to execute 'getRangeAt' on 'Selection': 0 is not a valid index.']`,
67+
)
68+
69+
// check that the alert is not visible
70+
await expect(await page.getByRole('alert').locator('div').nth(1)).not.toBeVisible()
71+
})
4772
})

0 commit comments

Comments
 (0)
Please sign in to comment.