Skip to content

Commit de2fbb2

Browse files
chore: return post id in end2end test because publishing flow changed
1 parent 6244f1c commit de2fbb2

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

test/integration/conversion.spec.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,18 @@ test.describe('conversion', () => {
4949

5050
test('will display the optimized image on a page', async () => {
5151
const media = await uploadMedia(page, 'input-example.jpg');
52-
const postURL = await newPost(page, {
53-
title: 'test',
54-
content: `<figure class="wp-block-image size-large" id="tinytest"><img src="${media}" alt="" class="wp-image-209"/></figure>`,
55-
}, WPVersion);
56-
57-
await page.goto(postURL);
58-
59-
const picture = await page.locator('picture:has(source[srcset*="input-example.avif"][type="image/avif"])');
52+
const postID = await newPost(
53+
page,
54+
{
55+
title: 'test',
56+
content: `<figure class="wp-block-image size-large" id="tinytest"><img src="${media}" alt="" class="wp-image-209"/></figure>`,
57+
},
58+
WPVersion
59+
);
60+
61+
await page.goto(`/?p=${postID}`);
62+
63+
const picture = await page.locator('picture:has(source[srcset*="input-example.avif"][type="image/avif"])');
6064
await expect(picture).toBeVisible();
6165
});
6266
});

test/integration/utils.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ export async function uploadMedia(page: Page, file: string): Promise<string> {
99
await page.getByLabel('Upload').click();
1010
const fileChooser = await fileChooserPromise;
1111
await fileChooser.setFiles(path.join(__dirname, `../fixtures/${file}`));
12-
await Promise.all([
13-
page.waitForURL('**/wp-admin/upload.php**', { waitUntil: 'load' }),
14-
page.locator('#html-upload').click(),
15-
]);
16-
12+
await Promise.all([page.waitForURL('**/wp-admin/upload.php**', { waitUntil: 'load' }), page.locator('#html-upload').click()]);
13+
1714
await page.goto('/wp-admin/upload.php?mode=list');
1815

1916
const row = await page.locator('table.wp-list-table tbody > tr').first();
@@ -23,10 +20,7 @@ export async function uploadMedia(page: Page, file: string): Promise<string> {
2320

2421
const rowID = await row.getAttribute('id');
2522
const attachmentID = rowID?.split('-')[1];
26-
await Promise.all([
27-
page.waitForURL(new RegExp(`/wp-admin/post\\.php\\?post=${attachmentID}&action=edit$`), { waitUntil: 'load' }),
28-
page.goto(`/wp-admin/post.php?post=${attachmentID}&action=edit`),
29-
]);
23+
await Promise.all([page.waitForURL(new RegExp(`/wp-admin/post\\.php\\?post=${attachmentID}&action=edit$`), { waitUntil: 'load' }), page.goto(`/wp-admin/post.php?post=${attachmentID}&action=edit`)]);
3024

3125
return page.locator('input[name="attachment_url"]').inputValue();
3226
}
@@ -260,13 +254,16 @@ export async function newPost(page: Page, options: NewPostOptions, WPVersion: nu
260254
}, content);
261255
await page.getByRole('button', { name: 'Publish', exact: true }).click();
262256
await page.getByLabel('Editor publish').getByRole('button', { name: 'Publish', exact: true }).click();
263-
await page.getByLabel('Editor publish').getByRole('link', { name: 'View Post' }).click();
264257
} else {
265258
await page.locator('#content-html').click();
266259
await page.locator('#content').fill(content);
267260
await page.locator('#publish').click();
268-
await page.getByRole('link', { name: 'View Post' }).first().click();
269261
}
270-
271-
return page.url();
262+
await page.waitForURL('**/wp-admin/post.php**');
263+
const url = new URL(page.url());
264+
const postID = url.searchParams.get('post');
265+
if (!postID) {
266+
throw new Error('unable to get post id from url');
267+
}
268+
return postID;
272269
}

0 commit comments

Comments
 (0)