From 38c1eaa628f71e1fb5d17ef20f249fb8cfebdda6 Mon Sep 17 00:00:00 2001 From: balintjunkuncz Date: Wed, 3 Jul 2024 12:36:23 +0200 Subject: [PATCH 1/4] feat: LDP-2540: Adds helper for Drupal logout --- tests/helpers/drupal-commands.d.ts | 8 ++++++++ tests/helpers/drupal-commands.js | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/helpers/drupal-commands.d.ts b/tests/helpers/drupal-commands.d.ts index d14eebc..2af163b 100644 --- a/tests/helpers/drupal-commands.d.ts +++ b/tests/helpers/drupal-commands.d.ts @@ -72,3 +72,11 @@ export async function cloneNodeByTitle([page, node_type, node_title, new_node_ti * @returns {Promise} The json result. */ export async function checkWatchdogErrors(timestamp, fail_on_notice = false, verbose = false): Promise; + +/** + * Logs out the current user. + * @param page Page object. + * @param base_url Base url. + * @return {Response} The response. + */ +export function logout(page, base_url): Promise; diff --git a/tests/helpers/drupal-commands.js b/tests/helpers/drupal-commands.js index 82f9d1e..d3fd122 100644 --- a/tests/helpers/drupal-commands.js +++ b/tests/helpers/drupal-commands.js @@ -19,6 +19,18 @@ module.exports = { return await page.goto(`${lang_prefix}/node/${nid}/edit?destination=admin/content`); }, + /** + * Logs out the current user. + * @param page Page object. + * @param base_url Base URL. + * @return {Response} The response. + */ + logout: async (page, base_url) => { + await page.goto(`${base_url}/user/logout`); + // Logout has a confirmation page since Drupal 10.3. + await page.locator('input[value="Log out"]').click(); + }, + /** * Finds node ID via drush and visits node layout page. * @param {Array<{page: Page, node_title: String}>} array Page object and From 2481b5cba9372fa1cd2da5e335e45008c3816496 Mon Sep 17 00:00:00 2001 From: balintjunkuncz Date: Wed, 3 Jul 2024 12:40:21 +0200 Subject: [PATCH 2/4] refact: LDP-2540: Rename method --- tests/helpers/drupal-commands.d.ts | 2 +- tests/helpers/drupal-commands.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/helpers/drupal-commands.d.ts b/tests/helpers/drupal-commands.d.ts index 2af163b..cd8d594 100644 --- a/tests/helpers/drupal-commands.d.ts +++ b/tests/helpers/drupal-commands.d.ts @@ -79,4 +79,4 @@ export async function checkWatchdogErrors(timestamp, fail_on_notice = false, ver * @param base_url Base url. * @return {Response} The response. */ -export function logout(page, base_url): Promise; +export function userLogout(page, base_url): Promise; diff --git a/tests/helpers/drupal-commands.js b/tests/helpers/drupal-commands.js index d3fd122..bdc2162 100644 --- a/tests/helpers/drupal-commands.js +++ b/tests/helpers/drupal-commands.js @@ -25,7 +25,7 @@ module.exports = { * @param base_url Base URL. * @return {Response} The response. */ - logout: async (page, base_url) => { + userLogout: async (page, base_url) => { await page.goto(`${base_url}/user/logout`); // Logout has a confirmation page since Drupal 10.3. await page.locator('input[value="Log out"]').click(); From 78d3d482cd3c5303f00667817c74367079a6fff1 Mon Sep 17 00:00:00 2001 From: balintjunkuncz Date: Tue, 23 Jul 2024 10:34:01 +0200 Subject: [PATCH 3/4] refact: LDP-2540: Change/move logout helper --- tests/helpers/drupal-commands.d.ts | 8 -------- tests/helpers/drupal-commands.js | 12 ------------ tests/helpers/test-methods.d.ts | 2 ++ tests/helpers/test-methods.js | 5 +++++ 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/tests/helpers/drupal-commands.d.ts b/tests/helpers/drupal-commands.d.ts index cd8d594..d14eebc 100644 --- a/tests/helpers/drupal-commands.d.ts +++ b/tests/helpers/drupal-commands.d.ts @@ -72,11 +72,3 @@ export async function cloneNodeByTitle([page, node_type, node_title, new_node_ti * @returns {Promise} The json result. */ export async function checkWatchdogErrors(timestamp, fail_on_notice = false, verbose = false): Promise; - -/** - * Logs out the current user. - * @param page Page object. - * @param base_url Base url. - * @return {Response} The response. - */ -export function userLogout(page, base_url): Promise; diff --git a/tests/helpers/drupal-commands.js b/tests/helpers/drupal-commands.js index bdc2162..82f9d1e 100644 --- a/tests/helpers/drupal-commands.js +++ b/tests/helpers/drupal-commands.js @@ -19,18 +19,6 @@ module.exports = { return await page.goto(`${lang_prefix}/node/${nid}/edit?destination=admin/content`); }, - /** - * Logs out the current user. - * @param page Page object. - * @param base_url Base URL. - * @return {Response} The response. - */ - userLogout: async (page, base_url) => { - await page.goto(`${base_url}/user/logout`); - // Logout has a confirmation page since Drupal 10.3. - await page.locator('input[value="Log out"]').click(); - }, - /** * Finds node ID via drush and visits node layout page. * @param {Array<{page: Page, node_title: String}>} array Page object and diff --git a/tests/helpers/test-methods.d.ts b/tests/helpers/test-methods.d.ts index 1a43b6e..cd73bc0 100644 --- a/tests/helpers/test-methods.d.ts +++ b/tests/helpers/test-methods.d.ts @@ -2,6 +2,8 @@ export function IShouldNotBeLoggedIn(page): Promise; export function ILogInAs([page, username]): Promise; +export function ILogOut([page, base_url]): Promise; + export function theCacheHitExists([page, response]): Promise; export function theHeaderContains([response, headerValue, shouldContain, ...headers]): Promise; diff --git a/tests/helpers/test-methods.js b/tests/helpers/test-methods.js index 2760911..18525cb 100644 --- a/tests/helpers/test-methods.js +++ b/tests/helpers/test-methods.js @@ -14,6 +14,11 @@ module.exports = { // Then make sure login worked. await expect(page.locator('body.user-logged-in').first()).toHaveCount(1); }, + ILogOut: async ([page, base_url]) => { + await page.goto(`${base_url}/user/logout`); + // Logout has a confirmation page since Drupal 10.3. + await page.locator('input[value="Log out"]').click(); + }, theCacheHitExists: async ([page, response]) => { expect(await response.headerValue('X-Drupal-Cache') == 'HIT' || await response.headerValue('X-Drupal-Dynamic-Cache') == 'HIT' || From 821a7a923af05b37d225684c0de5cbe5b4e34e6c Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Wed, 24 Jul 2024 08:20:39 +0200 Subject: [PATCH 4/4] feat: LDP-2540: Add check that we are logged out, directly in ILogOut(). --- tests/helpers/test-methods.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/helpers/test-methods.js b/tests/helpers/test-methods.js index 18525cb..0d02d12 100644 --- a/tests/helpers/test-methods.js +++ b/tests/helpers/test-methods.js @@ -8,16 +8,24 @@ module.exports = { }, ILogInAs: async ([page, username]) => { await page.goto('/user/login'); - await page.fill('input[name="name"]', username); - await page.fill('input[name="pass"]', process.env.APP_SECRET); - await page.click('input[value="Log in"]', process.env.APP_SECRET); + await expect(page.locator('form.user-login-form')).toBeVisible; + await page.locator('input[name="name"]').fill(username); + await page.locator('input[name="pass"]').fill(process.env.APP_SECRET); + await page.locator('input[value="Log in"]').click(); // Then make sure login worked. await expect(page.locator('body.user-logged-in').first()).toHaveCount(1); }, ILogOut: async ([page, base_url]) => { - await page.goto(`${base_url}/user/logout`); - // Logout has a confirmation page since Drupal 10.3. + // Go to the confirm form URL directly, instead of /user/logout: it saves a + // redirect and supports the destination parameter. + // Possible optimization: get the URL including token from the "logout" + // menu item; visiting that URL is faster because it doesn't need the extra + // "Log out" click. + await page.goto(`${base_url}/user/logout/confirm?destination=/user/login`); await page.locator('input[value="Log out"]').click(); + // Verify logout worked, on the immediate destination page. (The default + // home page does not have an indicator? So use the login page for that.) + await expect(page.locator('form.user-login-form')).toBeVisible; }, theCacheHitExists: async ([page, response]) => { expect(await response.headerValue('X-Drupal-Cache') == 'HIT' ||