Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/helpers/test-methods.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export function IShouldNotBeLoggedIn(page): Promise<void>;

export function ILogInAs([page, username]): Promise<void>;

export function ILogOut([page, base_url]): Promise<void>;

export function theCacheHitExists([page, response]): Promise<void>;

export function theHeaderContains([response, headerValue, shouldContain, ...headers]): Promise<void>;
Expand Down
19 changes: 16 additions & 3 deletions tests/helpers/test-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@ 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly related to the Drupal Logout, but this seemed a good time to do some refactoring of ILogInAs.

The extra expect() doesn't really add anything, because if we are already logged in, the fill() would also fail.
It's just that the expect() likely generates a better error message.
(Also, I felt I needed to do something, while removing the first line from all the following constructions in the tests:

    await helpers.IShouldNotBeLoggedIn(page);
    await helpers.ILogInAs([page, 'dru_editor']);

)

// Then make sure login worked.
await expect(page.locator('body.user-logged-in').first()).toHaveCount(1);
},
ILogOut: async ([page, base_url]) => {
// 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' ||
await response.headerValue('X-Drupal-Dynamic-Cache') == 'HIT' ||
Expand Down