From a1b40e2aa3fd080debc20835003d20930c4568eb Mon Sep 17 00:00:00 2001 From: ilyaukin <67313-ilyaukin@users.noreply.drupalcode.org> Date: Sun, 29 Sep 2024 22:16:30 +0000 Subject: [PATCH] Resolve #3477410 "Patch tests" --- playwright/e2e/atk_entity/atk_media.spec.js | 13 ++++---- playwright/e2e/atk_entity/atk_node.spec.js | 33 +++++-------------- .../e2e/atk_entity/atk_taxonomy.spec.js | 3 +- playwright/support/atk_commands.js | 11 +++++++ 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/playwright/e2e/atk_entity/atk_media.spec.js b/playwright/e2e/atk_entity/atk_media.spec.js index d4c9da5..22c1c8b 100644 --- a/playwright/e2e/atk_entity/atk_media.spec.js +++ b/playwright/e2e/atk_entity/atk_media.spec.js @@ -71,15 +71,15 @@ test.describe('Media tests.', () => { // and NaturalHeight properties. let isImageDownloaded = await imageLocator.evaluate((img) => img.naturalWidth > 0 && img.naturalHeight > 0); - // Extract the media id that was added by - // automated_testing_kit_preprocess_image(). - const mid = await imageLocator.getAttribute('data-media-id'); + // Extract the edit and delete hrefs. + const rowLocator = page.locator('tr', { has: imageLocator }); + const mediaEditUrl = await rowLocator.locator('a[href*="edit"]').first().getAttribute('href'); + const mediaDeleteUrl = await rowLocator.locator('a[href*="delete"]').getAttribute('href'); // // Update the media. // - const mediaEditUrl = atkConfig.mediaEditUrl.replace('{mid}', mid); - await page.goto(baseUrl + mediaEditUrl); + await page.goto(mediaEditUrl); await page.getByRole('button', { name: 'Remove' }).click(); await page.setInputFiles('input[name="files[field_media_image_0]"]', image2Filepath); await altField.fill(`${testId}: ${uniqueToken2}`); @@ -101,8 +101,7 @@ test.describe('Media tests.', () => { // // Delete the media entity. // - const mediaDeleteUrl = atkConfig.mediaDeleteUrl.replace('{mid}', mid); - await page.goto(baseUrl + mediaDeleteUrl); + await page.goto(mediaDeleteUrl); await page.getByRole('button', { name: 'Delete' }).click(); }); }); diff --git a/playwright/e2e/atk_entity/atk_node.spec.js b/playwright/e2e/atk_entity/atk_node.spec.js index 95a691b..a2a499f 100644 --- a/playwright/e2e/atk_entity/atk_node.spec.js +++ b/playwright/e2e/atk_entity/atk_node.spec.js @@ -54,27 +54,15 @@ test.describe('Node tests.', () => { // // Confirm content appears. // - let divContainer = await page.textContent('.text-content'); + let divContainer = await page.textContent('.node__content'); await expect(divContainer).toContain(bodyText); - // Extract the nid placed in the body class by this hook: - // automated_testing_kit.module:automated_testing_kit_preprocess_html(). - // Wait for the page to load - await page.waitForLoadState('domcontentloaded'); - const bodyClass = await page.evaluate(() => document.body.className); - const match = bodyClass.match(/node-nid-(\d+)/); - - // Get the nid. - const nid = parseInt(match[1], 10); - // // Update the node. // - const nodeEditUrl = atkConfig.nodeEditUrl.replace('{nid}', nid); - bodyText = 'Ut eget ex vitae nibh dapibus vulputate ut id lacus.'; - await page.goto(baseUrl + nodeEditUrl); + await page.getByRole('link', { name: 'Edit' }).click(); ckEditor = await page.locator('[aria-label="Editor editing area: main"]'); await ckEditor.fill(bodyText); // Timeouts necessary when running at full speed. @@ -85,14 +73,14 @@ test.describe('Node tests.', () => { // // Confirm content has changed. // - divContainer = await page.locator('.text-content'); + divContainer = await page.locator('.node__content'); const text = await divContainer.textContent(); await expect(text).toContain(bodyText); // // Delete the node. // - await atkCommands.deleteNodeViaUiWithNid(page, context, nid); + await atkCommands.deleteCurrentNodeViaUi(page); }); // @@ -131,7 +119,7 @@ test.describe('Node tests.', () => { // // Confirm content appears. // - let divContainer = await page.textContent('.text-content'); + let divContainer = await page.textContent('.node__content'); await expect(divContainer).toContain(bodyText); // Extract the nid placed in the body class by this hook: @@ -141,17 +129,12 @@ test.describe('Node tests.', () => { const bodyClass = await page.evaluate(() => document.body.className); const match = bodyClass.match(/node-nid-(\d+)/); - // Get the nid. - const nid = parseInt(match[1], 10); - // // Update the node. // - const nodeEditUrl = atkConfig.nodeEditUrl.replace('{nid}', nid); - bodyText = 'Ut eget ex vitae nibh dapibus vulputate ut id lacus.'; - await page.goto(baseUrl + nodeEditUrl); + await page.getByRole('link', { name: 'Edit' }).click(); ckEditor = await page.locator('[aria-label="Editor editing area: main"]'); await ckEditor.fill(bodyText); // Timeouts necessary when running at full speed. @@ -162,13 +145,13 @@ test.describe('Node tests.', () => { // // Confirm content has changed. // - divContainer = await page.locator('.text-content'); + divContainer = await page.locator('.node__content'); const text = await divContainer.textContent(); await expect(text).toContain(bodyText); // // Delete the node. // - await atkCommands.deleteNodeViaUiWithNid(page, context, nid); + await atkCommands.deleteCurrentNodeViaUi(page); }); }); diff --git a/playwright/e2e/atk_entity/atk_taxonomy.spec.js b/playwright/e2e/atk_entity/atk_taxonomy.spec.js index 9828e51..f498e02 100644 --- a/playwright/e2e/atk_entity/atk_taxonomy.spec.js +++ b/playwright/e2e/atk_entity/atk_taxonomy.spec.js @@ -59,8 +59,7 @@ test.describe('Entity tests.', () => { // Fetch tag id from the list. The new term should be at // or near the top. // - await page.goto(`${baseUrl}admin/structure/taxonomy/manage/tags/overview`); - const termLocator = await page.getByText(termName); // eslint-disable-line no-unused-vars + await page.goto(`admin/structure/taxonomy/manage/tags/overview`); // Get the tid from the edit button. const link = await page.locator("//a[contains(text(),'Edit') and starts-with(@href, '/taxonomy/term')]").first(); diff --git a/playwright/support/atk_commands.js b/playwright/support/atk_commands.js index 523696f..4c10ee0 100644 --- a/playwright/support/atk_commands.js +++ b/playwright/support/atk_commands.js @@ -11,6 +11,7 @@ module.exports = { createUserWithUserObject, + deleteCurrentNodeViaUi, deleteNodeViaUiWithNid, deleteUserWithEmail, deleteUserWithUid, @@ -91,6 +92,16 @@ function createUserWithUserObject (user, roles = [], args = [], options = []) { }) } +/** + * Delete currently opened node. + * @param page {object} Page object. + * @returns {Promise<void>} + */ +async function deleteCurrentNodeViaUi(page) { + await page.getByRole('link', { name: 'Delete' }).click(); + await page.getByRole('button', { name: 'Delete' }).click(); +} + /** * Delete node via UI given a nid. * -- GitLab